我在0.6.0分支上使用了这里描述的模型.代码可以在这里找到.我对链接代码做了一些小改动.
在我的代码中,我创建了两个模型,一个用于训练,一个用于验证,与Tensorflow教程中的模型非常相似.
with tf.variable_scope("model", reuse=None, initializer=initializer):
m = PTBModel_User(is_training=True, config=config, name='Training model')
with tf.variable_scope("model", reuse=True, initializer=initializer):
mtest = PTBModel_User(is_training=False, config=config_valid, name='Validation model')
Run Code Online (Sandbox Code Playgroud)
第一个模型,一个用于训练,似乎创建得很好,但第二个用于验证,但没有.输出获得None维度!我所引用的行位于链接代码的第134行:
output = tf.reshape(tf.concat(1, outputs), [-1, size])
我在输出重新整形后立即添加了这些行:
output_shape = output.get_shape()
print("Model num_steps:", num_steps)
print("Model batch_size:", batch_size)
print("Output dims", output_shape[0], output_shape[1])
Run Code Online (Sandbox Code Playgroud)
这给了我这个:
Model num_steps: 400
Model batch_size: 1
Output dims Dimension(None) Dimension(650)
Run Code Online (Sandbox Code Playgroud)
这个问题只发生在'验证模型'上,而不是'训练模型'.对于'训练模型',我得到了预期的输出:
Model num_steps: 400
Model batch_size: 2
Output dims Dimension(800) Dimension(650)
Run Code Online (Sandbox Code Playgroud)
(注意,使用'验证模型'我使用的是batch_size=1代替batch_size=2我用于训练模型的那个)
根据我的理解,使用函数-1作为输入reshape …
tensorflow ×1