我想使用梯度下降到可变&#34最小化;损失&#34 ;,但我不'吨希望它能够更新每一个变量,只是其中的几个(有我希望在同一图表中保留一些变量。)。
因此,我在代码段的最后一行中列出了我要在var_list=[]
中更新的变量:
conv_weights = [0]*CONVOLUTION_COUNT # couldn't figure out how to initialize this better
conv_biases = [0]*CONVOLUTION_COUNT
for layer in range(0,CONVOLUTION_COUNT):
inSize = max(NUM_CHANNELS,5*layer)
outSize = 5*(layer+1)
conv_weights[layer] = tf.Variable(tf.truncated_normal([FILTER_SIZE, inSize, outSize],stddev=0.1,seed=SEED, dtype=data_type()))
conv_biases[layer] = tf.Variable(tf.constant(0.1, shape=[outSize], dtype=data_type()))
fc1_weights = tf.Variable(tf.truncated_normal([20*35, 512],stddev=0.1,seed=SEED,dtype=data_type()))
fc1_biases = tf.Variable(tf.constant(0.1, shape=[512], dtype=data_type()))
fc2_weights = tf.Variable(tf.truncated_normal([512, NUM_OUTPUTS],stddev=0.1,seed=SEED,dtype=data_type()))
fc2_biases = tf.Variable(tf.constant(0.1, shape=[NUM_OUTPUTS], dtype=data_type()))
...
optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss=loss, global_step=batch,
var_list=[conv_weights,conv_biases,fc1_weights,fc1_biases,fc2_weights,fc2_biases])
我收到错误:
if v.op.type == "ReadVariableOp":
AttributeError: 'list' object has no attribute 'op'
我有点困惑为什么列表中的元素需要进行操作,因为我只是更新神经网络的权重。这些只是变量,对吗?有人猜到我做错了什么或我采取了什么其他方法?
此外,当我没有指定var_list
时,所有这些代码都能正常工作。