![](/img/trans.png)
[英]What's the differences between tf.contrib.slim.conv2d and tf.contrib.layers.conv2d?
[英]Tensorflow - When using tf.contrib.layers.conv2d, can I set the name of the weights and biases?
Tensorflow版本:1.10.1
我想將我的預訓練網絡中所學的權重和卷積層的偏差轉移到新網絡中。
但是,因為我使用了conv2d
api,所以檢查點文件中的權重和偏差會自動命名為Conv/weights
, Conv/biases
Conv_1/weights
, Conv_1/weights
, Conv_1/biases
Conv_2/weights
, Conv_2/weights
, Conv_2/biases
等。
但是,這些名稱與代碼中的變量名稱不一致。 例如,在我的代碼中, Conv/weights
, Conv/biases
屬於一個名為C2
的變量,因此我想將其命名為C2/weights
, C2/biases
。
我知道對於由get_variable
定義的變量,我可以通過my_varibale = tf.get_variable("whatever_name_I_want",shape,dtype,initializer)
將它們的名稱設置為所需的任何字符串,其中my_variable
命名為"whatever_name_I_want"
。
但是,當涉及到my_layer = tf.contrib.layers.conv2d(params_blabla)
(或tf.nn
或tf.layers
的等效api)時,我不知道如何命名my_layer
。
那么,有可能這樣做嗎? 如果可能的話,怎么辦?
對於tf.layers.conv2d和tf.nn.conv2d,您可以傳遞一個名為name
的附加參數。
例:
my_conv1 = tf.layers.conv2D(...., name='my_conv1')
my_conv2 = tf.layers.conv2D(...., name='my_conv2 ')
對於tf.contrib.layers.conv2d ,參數scope
用於為圖層命名空間。
例:
with tf.name_scope('my_conv1') as scope:
my_conv1 = tf.contrib.layers.conv2d(..., scope=scope)
結果:
在所有情況下,您的權重和偏差都被命名為例如my_conv1/weights
和my_conv1/bias
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.