【发布时间】:2018-06-09 05:51:47
【问题描述】:
所以我做了我能做到的最简单的模型(感知器/自动编码器),它(除了输入生成)如下:
N = 64 * 64 * 3
def main():
x = tf.placeholder(tf.float32, shape=(None, 64, 64, 3), name="x")
with tf.name_scope("perceptron"):
W = tf.Variable(tf.random_normal([N, N], stddev=1), name="W")
b = tf.Variable(tf.random_normal([], stddev=1), name="b")
y = tf.add(tf.matmul( tf.reshape(x, [-1,N]), W), b, name="y")
act = tf.nn.sigmoid(y, name="sigmoid")
yhat = tf.reshape(act, [-1, 64, 64, 3], name="yhat")
with tf.name_scope("mse"):
sq_error = tf.reduce_mean(np.square(x - yhat), axis=1)
cost = tf.reduce_mean( sq_error, name="cost" )
tf.summary.scalar("cost", cost)
with tf.name_scope("conv_opt"): #Should just be called 'opt' here
training_op = tf.train.AdamOptimizer(0.005).minimize(cost, name="train_op")
with tf.device("/gpu:0"):
config = tf.ConfigProto(allow_soft_placement=True)
config.gpu_options.allow_growth = True
sess = tf.Session(config=config)
sess.run(tf.global_variables_initializer())
logdir = "log_directory"
if os.path.exists(logdir):
shutil.rmtree(logdir)
os.makedirs(logdir)
input_gen = input.input_generator_factory(...)
input_gen.initialize((64,64,3), 512)
merged = tf.summary.merge_all()
train_writer = tf.summary.FileWriter(logdir, sess.graph)
for i in range(10):
batch = input_gen.next_train_batch()
summary,_ = sess.run([merged, training_op], feed_dict={x : batch})
train_writer.add_summary(summary, i)
print("Iteration %d completed" % (i))
if __name__ == "__main__":
main()
这会产生以下tensorboard graph。无论如何,我认为从 'perception' 到 'conv_opt' 的粗箭头(可能应该只是称为 'opt',抱歉)对应于反向传播的错误信号,(而 ?x64x64x3 箭头对应于推理)。但为什么是 12 张量?我不明白这个数字是从哪里来的。我本来预计会更少,实际上只对应于W 和b。有人可以解释一下发生了什么吗?
【问题讨论】: