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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章