繁体   English   中英

Conv3d:InvalidArgumentError(请参阅上面的回溯):重塑的输入是张量

[英]Conv3d: InvalidArgumentError (see above for traceback): Input to reshape is a tensor

 inp = tf.expand_dims(inp, -1)
    conv = tf.layers.conv3d(inputs=inp, filters=64, kernel_size=[5, 5, 5], padding='same', activation=tf.nn.relu)
    print 'conv size', conv.get_shape().as_list()
    pool = tf.layers.max_pooling3d(inputs=conv, pool_size=[2, 2, 2], strides=2)
    print 'pool size', pool.get_shape().as_list()
    conv2 = tf.layers.conv3d(inputs=pool, filters=32, kernel_size=[5, 5, 5], padding='same', activation=tf.nn.relu)
    print 'conv size', conv2.get_shape().as_list()
    pool2 = tf.layers.max_pooling3d(inputs=conv2, pool_size=[2, 2, 2], strides=5)
    print 'pool size', pool2.get_shape().as_list()
    flattened = tf.reshape(pool2, [-1, 10, 1 * 30 * 32])
    print 'flattened size', flattened.get_shape().as_list()

版画

conv size [None, 10, 10, 300, 64]
pool size [None, 5, 5, 150, 64]
conv size [None, 5, 5, 150, 32]
pool size [None, 1, 1, 30, 32]
flattened size [None, 10, 960]

但是我得到了错误

  ARGS.func(ARGS)
  File "cnn_rnn.py", line 274, in train
model.fit(session, saver, train, test)
  File "/Users//Desktop/Coterm/Winter2018/Psych209/Final/neural-transposition-corrector/CNN/rnn_model.py", line 110, in fit
score = self.run_epoch(sess, train, dev)
  File "/Users//Desktop/Coterm/Winter2018/Psych209/Final/neural-transposition-corrector/CNN/rnn_model.py", line 69, in run_epoch
loss = self.train_on_batch(sess, *batch)
  File "cnn_rnn.py", line 211, in train_on_batch
_, loss = sess.run([self.train_op, self.loss], feed_dict=feed)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 889, in run
run_metadata_ptr)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1120, in _run
feed_dict_tensor, options, run_metadata)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1317, in _do_run
options, run_metadata)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1336, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 30720 values, but the requested shape requires a multiple of 9600
     [[Node: Reshape_1 = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"](max_pooling3d_2/MaxPool3D, Reshape_1/shape)]]

Caused by op u'Reshape_1', defined at:
  File "cnn_rnn.py", line 335, in <module>
ARGS.func(ARGS)
  File "cnn_rnn.py", line 266, in train
model = CNN_RNN(config, embeddings)
  File "cnn_rnn.py", line 225, in __init__
self.build()
  File "/Users//Desktop/Coterm/Winter2018/Psych209/Final/neural-transposition-corrector/CNN/model.py", line 81, in build
  File "cnn_rnn.py", line 109, in add_prediction_op
x = self.convolve(x)
  File "cnn_rnn.py", line 96, in convolve
flattened = tf.reshape(pool2, [-1, 10, 1 * 30 * 32])
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 3938, in reshape
"Reshape", tensor=tensor, shape=shape, name=name)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2956, in create_op
op_def=op_def)
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1470, in __init__
self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 30720 values, but the requested shape requires a multiple of 9600
     [[Node: Reshape_1 = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"](max_pooling3d_2/MaxPool3D, Reshape_1/shape)]]

我知道重塑的尺寸存在问题,但是通过打印上述步骤的尺寸,看起来应该没问题。 这是我第一次使用conv3d,所以很可能我犯了一个愚蠢的错误。

有谁知道维数应该是多少?

谢谢!

我解决了! 问题在于,重整调用应该被平整= tf.reshape(pool2,[-1,1,1 * 30 * 32])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM