`
def weight_variable(shape):
initial = tf.truncated_normal(shape, mean=0, stddev=0.1)
return tf.Variable(initial)
#network
x = tf.placeholder(tf.float32, [None,
FLAGS.image_height*FLAGS.image_width])
y_ = tf.placeholder(tf.float32, [None, 2])
input=tf.reshape(x,
[-1,FLAGS.image_height,FLAGS.image_width,FLAGS.input_channel])
filter = weight_variable([FLAGS.filter_size, FLAGS.filter_size,
FLAGS.input_channel, FLAGS.filter_channel])
conv_out = tf.nn.sigmoid(conv2d(input, filter))
pool_out = max_pool(conv_out)
pool_list = pool_out.get_shape().as_list()
input_dim = pool_list[1]* pool_list[2]* pool_list[3]
pool_2D = tf.reshape(pool_out, [-1, input_dim])
W_fc = weight_variable([input_dim, 2])
logits = tf.matmul(pool_2D, W_fc) #(batch_size,2)
y_conv=tf.nn.softmax(logits)
s=tf.argmax(y_conv,axis=1)
test = tf.reduce_sum(s)
cross_entropy =
tf.nn.softmax_cross_entropy_with_logits(logits=logits,labels=y_)
loss = tf.reduce_mean(cross_entropy)
optimizer = tf.train.GradientDescentOptimizer(FLAGS.rLearn).minimize(loss)
correct_prediction = tf.equal(tf.argmax(y_conv,axis=1), tf.argmax(y_,
axis=1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
#training loop
for i in range(200):`
答案 0 :(得分:1)
我不明白您初始化权重矩阵的方式。
假设您以这种方式初始化体重矩阵:
def new_weights(shape):
return tf.Variable(tf.truncated_normal(shape, stddev=0.05))
训练后,您可以通过以下方式获取权重变量的值:
# Retrieve the values of the weight-variables from TensorFlow.
# A feed-dict is not necessary because nothing is calculated.
w = session.run(weights)