- Mastering TensorFlow 1.x
- Armando Fandango
- 419字
- 2021-06-25 22:50:59
TF Slim
TF Slim is a lightweight library built on top of TensorFlow core for defining and training models. TF Slim can be used in conjunction with other TensorFlow low level and high-level libraries such as TF Learn. The TF Slim comes as part of the TensorFlow installation in the package: tf.contrib.slim. Run the following command to check if your TF Slim installation is working:
python3 -c 'import tensorflow.contrib.slim as slim; eval = slim.evaluation.evaluate_once'
TF Slim provides several modules that can be picked and applied independently and mixed with other TensorFlow packages. For example, at the time of writing of this book TF Slim had following major modules:

The simple workflow in TF Slim is as follows:
- Create the model using slim layers.
- Provide the input to the layers to instantiate the model.
- Use the logits and labels to define the loss.
- Get the total loss using convenience function get_total_loss().
- Create an optimizer.
- Create a training function using convenience function slim.learning.create_train_op(), total_loss and optimizer.
- Run the training using the convenience function slim.learning.train() and training function defined in the previous step.
The complete code for the MNIST classification example is provided in the notebook ch-02_TF_High_Level_Libraries. The output from the TF Slim MNIST example is as follows:
INFO:tensorflow:Starting Session. INFO:tensorflow:Saving checkpoint to path ./slim_logs/model.ckpt INFO:tensorflow:global_step/sec: 0 INFO:tensorflow:Starting Queues. INFO:tensorflow:global step 100: loss = 2.2669 (0.010 sec/step) INFO:tensorflow:global step 200: loss = 2.2025 (0.010 sec/step) INFO:tensorflow:global step 300: loss = 2.1257 (0.010 sec/step) INFO:tensorflow:global step 400: loss = 2.0419 (0.009 sec/step) INFO:tensorflow:global step 500: loss = 1.9532 (0.009 sec/step) INFO:tensorflow:global step 600: loss = 1.8733 (0.010 sec/step) INFO:tensorflow:global step 700: loss = 1.8002 (0.010 sec/step) INFO:tensorflow:global step 800: loss = 1.7273 (0.010 sec/step) INFO:tensorflow:global step 900: loss = 1.6688 (0.010 sec/step) INFO:tensorflow:global step 1000: loss = 1.6132 (0.010 sec/step) INFO:tensorflow:Stopping Training. INFO:tensorflow:Finished training! Saving model to disk. final loss=1.6131552457809448
As we see from the output, the convenience function slim.learning.train() saves the output of the training in checkpoint files in the specified log directory. If you restart the training, it will first check if the checkpoint exists and will resume the training from the checkpoint by default.
The documentation page for the TF Slim was found empty at the time of this writing at the following link: https://www.tensorflow.org/api_docs/python/tf/contrib/slim. However, some of the documentation can be found in the source code at the following link: https://github.com/tensorflow/tensorflow/tree/r1.4/tensorflow/contrib/slim.
We shall use TF Slim for learning how to use pre-trained models such as VGG16 and Inception V3 in later chapters.
- Istio入門與實戰(zhàn)
- Camtasia Studio 8:Advanced Editing and Publishing Techniques
- Learning Game Physics with Bullet Physics and OpenGL
- Large Scale Machine Learning with Python
- 計算機組裝與維護(第3版)
- CC2530單片機技術(shù)與應(yīng)用
- 基于Proteus仿真的51單片機應(yīng)用
- BeagleBone Robotic Projects
- VMware Workstation:No Experience Necessary
- 單片微機原理及應(yīng)用
- The Artificial Intelligence Infrastructure Workshop
- Istio實戰(zhàn)指南
- 微控制器的應(yīng)用
- Angular 6 by Example
- Building Machine Learning Systems with Python