TensorFlow学习日记31

1.fit_generator
解析:fit_generator(self, generator, steps_per_epoch, epochs=1, verbose=1, callbacks=None, validation_data=None, validation_steps=None, class_weight=None, max_q_size=10, workers=1, pickle_safe=False, initial_epoch=0)。其中,validation_steps表示当validation_data为生成器时,本参数指定验证集的生成器返回次数。

2.deque
解析:双端队列。

3.LSTM层
解析:keras.layers.recurrent.LSTM(units, activation=’tanh’, recurrent_activation=’hard_sigmoid’, use_bias=True, kernel_initializer=’glorot_uniform’, recurrent_initializer=’orthogonal’, bias_initializer=’zeros’, unit_forget_bias=True, kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0)。如下所示:
(1)units:输出维度。
(2)dropout:0-1之间的浮点数,控制输入线性变换的神经元断开比例。
(3)input_dim:输入维度,当使用该层为模型首层时,应指定该值(或等价的指定input_shape)。
(4)return_sequences:如果return_sequences=True,返回形如(samples,timesteps,output_dim)的3D张量,否则返回形如(samples,output_dim)的2D张量。

4.Dropout层
解析:keras.layers.core.Dropout(rate, noise_shape=None, seed=None)。为输入数据施加Dropout。Dropout将在训练过程中每次更新参数时按一定概率(rate)随机断开输入神经元,Dropout层用于防止过拟合。如下所示:
(1)rate:0-1的浮点数,控制需要断开的神经元的比例。
(2)noise_shape:整数张量,为将要应用在输入上的二值Dropout mask的shape,比如输入为(batch_size, timesteps, features),并且希望在各个时间步上的Dropout mask都相同,则可传入noise_shape=(batch_size, 1, features)。
(3)seed:整数,使用的随机数种子。

5.tf.nn.max_pool
解析:max_pool(value,ksize,strides,padding,data_format=’NHWC’,name=None)

6.tf.nn.pool
解析:pool(input,window_shape,pooling_type,padding,dilation_rate=None,strides=None,name=None,data_format=None)

7.tf.trainable_variables和tf.all_variables
解析:
(1)tf.trainable_variables返回的是需要训练的变量列表。
(2)tf.all_variables返回的是所有变量的列表。

8.pickle.load
解析:

with open('file_name', 'rb') as pickle_file:
     data = pickle.load(pickle_file)


9.checkpoint
解析:
(1).meta文件保存了当前图结构。
(2).index文件保存了当前参数名。
(3).data文件保存了当前参数值。

10.tf.train.get_checkpoint_state
解析:get_checkpoint_state(checkpoint_dir,latest_filename=None),如下所示:
(1)checkpoint_dir: The directory of checkpoints.
(2)latest_filename: Optional name of the checkpoint file. Default to ‘checkpoint’.

11.tf.train.Saver
解析:
(1)save(sess,save_path,global_step=None,…,write_meta_graph=True,write_state=True)
(2)restore(sess,save_path):restores previously saved variables.

12.tf.gfile.FastGFile
解析:__init__(name,mode=’r’):File I/O wrappers without thread locking.

13.tf.train.latest_checkpoint
解析:latest_checkpoint(checkpoint_dir,latest_filename=None),如下所示:
(1)checkpoint_dir: Directory where the variables were saved.
(2)latest_filename: Optional name for the protocol buffer file that contains the list of most recent checkpoint filenames. See the corresponding argument to Saver.save().

14.graph.get_tensor_by_name(name)
解析:name表示tensor的名字。

15.tf.global_variables_initializer
解析:an Op that initializes global variables in the graph.

16.tf.name_scope与tf.variable_scope
解析:
(1)tf.name_scope主要用于管理一个图里面的各种op,返回的是一个以scope_name命名的context manager。一个graph会维护一个name_space的堆,每一个namespace下面可以定义各种op或者子namespace,实现一种层次化有条理的管理,避免各个op之间命名冲突。
(2)tf.variable_scope一般与tf.name_scope()配合使用,用于管理一个graph中变量的名字,避免变量之间的命名冲突,tf.variable_scope允许在一个variable_scope下面共享变量。
说明:tf.variable_scope用于变量,tf.name_scope用于操作。

17.f.keras.preprocessing.image.load_img
解析:
load_img(path,grayscale=False,target_size=None):loads an image into PIL format。如下所示:
(1)path: Path to image file.
(2)grayscale: Boolean, whether to load the image as grayscale.
(3)target_size: Either None (default to original size) or tuple of ints (img_height, img_width).

18.Dropout层
解析:keras.layers.core.Dropout(rate, noise_shape=None, seed=None)。为输入数据施加Dropout。Dropout将在训练过程中每次更新参数时按一定概率(rate)随机断开输入神经元,Dropout层用于防止过拟合。如下所示:
(1)rate:0-1的浮点数,控制需要断开的神经元的比例。
(2)noise_shape:整数张量,为将要应用在输入上的二值Dropout mask的shape,例如输入为(batch_size, timesteps, features),并且希望在各个时间步上的Dropout mask都相同,则可传入noise_shape=(batch_size, 1, features)。
(3)seed:整数,使用的随机数种子。

19.TimeDistributed包装器
解析:keras.layers.wrappers.TimeDistributed(layer),该包装器可以把一个层应用到输入的每一个时间步上。其中,layer表示Keras层对象。使用TimeDistributed包装Dense严格等价于layers.TimeDistribuedDense。不同的是包装器TimeDistribued还可以对别的层进行包装,比如对Convolution2D包装。

20.Bidirectional包装器
解析:keras.layers.wrappers.Bidirectional(layer, merge_mode=’concat’, weights=None),双向RNN包装器。如下所示:
(1)layer:Recurrent对象。
(2)merge_mode:前向和后向RNN输出的结合方式,为sum,mul,concat,ave和None之一,若设为None,则返回值不结合,而是以列表的形式返回。

21.set_image_dim_ordering
解析:set_image_dim_ordering(dim_ordering),sets the value of the image dimension ordering convention (‘th’ or ‘tf’)。如下所示:

>>> from keras import backend as K
>>> K.image_dim_ordering()
'th'
>>> K.set_image_dim_ordering('tf')
>>> K.image_dim_ordering()
'tf'


22.Conv2D层中的SAME和VALID
解析:
(1)SAME
out_height = ceil(float(in_height) / float(strides[1])),out_width = ceil(float(in_width) / float(strides[2]))
(2)VALID
out_height = ceil(float(in_height - filter_height + 1) / float(strides[1])),out_width = ceil(float(in_width - filter_width + 1) / float(strides[2]))

23.EarlyStopping
解析:keras.callbacks.EarlyStopping(monitor=’val_loss’, patience=0, verbose=0, mode=’auto’),当监测值不再改善时,该回调函数将中止训练。如下所示:
(1)monitor:需要监视的量。
(2)patience:当early stop被激活(比如发现loss相比上一个epoch训练没有下降),则经过patience个epoch后停止训练。
(3)verbose:信息展示模式。
(4)mode:”auto”,”min”,”max”之一,在min模式下,如果检测值停止下降则中止训练。在max模式下,当检测值不再上升则停止训练。

24.CSVLogger
解析:keras.callbacks.CSVLogger(filename, separator=’,’, append=False)。将epoch的训练结果保存在csv文件中,支持所有可被转换为string的值,包括1D的可迭代数值如np.ndarray。如下所示:
(1)fiename:保存的csv文件名,比如run/log.csv。
(2)separator:字符串,csv分隔符。
(3)append:默认为False,为True时csv文件如果存在则继续写入,为False时总是覆盖csv文件。

25.目标函数
解析:model.compile(loss=’mean_squared_error’, optimizer=’sgd’)。比如,多类对数损失categorical_crossentropy,注意使用该目标函数时,需要将标签转化为形如(nb_samples, nb_classes)的二值序列。

参考文献:
[1] Visualizing MNIST:An Exploration of Dimensionality Reduction:http://colah.github.io/posts/2014-10-Visualizing-MNIST/
[2] Keras图像深度学习实战:http://www.ituring.com.cn/book/tupubarticle/16624
[3] Tensorflow加载预训练模型和保存模型:http://blog.csdn.net/huachao1001/article/details/78501928

猜你喜欢

转载自blog.csdn.net/shengshengwang/article/details/79080393