TensorFlow-Slim README翻译

英文版传送门

TensorFlow-Slim

TF-Slim是为了定义、训练和评估用tensorflow构建的复杂模型而设计的一个轻量级库。tf-slim中的组件可以自由的与原生tensorflow框架相结合,和其他框架一样,例如tf.contrib.learn.

Usage:

import tensorflow.contrib.slim as slim

Why TF-Slim?

TF-Slim是一个轻量级库让构建、训练和评估神经网络变得更简单。
1、允许用户用更简洁的代码构建模型,这是通过使用argument scoping和高阶的封装layers
和variables来实现的。这些工具增加了代码的可读性和可维护性,减少了赋值-粘贴超参数和超参数微调时出现错误的可能性。
2、通过了常用的regularizers使模型变的简单。
3、一些经典模型(比如 VGG, AlexNet)已经在Slim中部署,传送门available。These can either be used as black boxes, or can be extended in various ways, e.g., by adding "multiple heads" to different internal layers.
4、Slim makes it easy to extend complex models, and to warm start training algorithms by using pieces of pre-existing model checkpoints.

What are the various components of TF-Slim?

TF-Slim是由一些相互独立设计的组件组成,主要包括以下几个点。

  • arg_scope: provides a new scope named arg_scope that allows a user to define default arguments for specific operations within that scope.
  • data: contains TF-slim's dataset definition, data providers, parallel_reader, and decoding utilities.
  • evaluation: contains routines for evaluating models.
  • layers: contains high level layers for building models using tensorflow.
  • learning: contains routines for training models.
  • losses: contains commonly used loss functions.
  • metrics: contains popular evaluation metrics.
  • nets: contains popular network definitions such as VGG and AlexNet models.
  • queues: provides a context manager for easily and safely starting and closing QueueRunners.
  • regularizers: contains weight regularizers.variables: provides convenience wrappers for variable creation and manipulation.

Defining Models

通过结合库中的variables、layers、scopes可以简洁的定义模型,详细定义如下。

Variables

在原生tensorflow中创建变量需要预定义一个值或者一个初始化器(例如,从一个高斯分布中进行随机采样)。此外,如果一个变量要在某个设备上创建,如GPU上,是需要显式设置的。为了减少创建变量的代码要求,TF-Slim提供了一系列封装函数,在variables.py中可以查看到,使调用者可以很轻易的创建变量。
比如创建一个权值变量,用truncated normal distribution初始化,用l2_loss正则化权值并且是在CPU上创建,只需要声明以下内容:

weights = slim.variable('weights',
                             shape=[10, 10, 3 , 3],
                             initializer=tf.truncated_normal_initializer(stddev=0.1),
                             regularizer=slim.l2_regularizer(0.05),
                             device='/CPU:0')

在原生tensorflow中,有两种类型的变量:常规变量和局部变量。大多数变量都是常规变量:一旦被创建,就可以保存到磁盘上用saver。而局部变量仅仅是在会话期间并且没有保存到磁盘上。
TF-Slim进一步定义了模型变量来区别不同类型的变量,模型变量就是指模型的参数。模型变量可以被训练和微调并且在评估和推断时从checkpoint文件中加载出来。

你可能感兴趣的:(TensorFlow-Slim README翻译)