ValueError:无法挤压dim[1],尺寸应为1,对于输入形状为[16,14,14512]的"tower_0/joint_embedding/squeeze"(操作:"挤压"(得到14
Traceback (most recent call last):
File "train_image_text.py", line 244, in <module>
tf.app.run()
File "/net/per920a/export/das14a/satoh-lab/kajalk/anaconda2/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "train_image_text.py", line 240, in main
train_models.train()
File "/net/per610a/export/das18a/satoh-lab/kajalk/new_exp_cm/CMPL/train_models.py", line 240, in train
input_seqs_splits[k], input_masks_splits[k])
File "/net/per610a/export/das18a/satoh-lab/kajalk/new_exp_cm/CMPL/train_models.py", line 76, in _tower_loss
patch_embeddings = build_patch_joint_embeddings(patch_features, scope='patch_joint_embedding')
File "/net/per610a/export/das18a/satoh-lab/kajalk/new_exp_cm/CMPL/modules.py", line 228, in build_patch_joint_embeddings
joint_embeddings = tf.squeeze(joint_embeddings,[1]) # batch_size * patch_size *feature_size
File "/net/per920a/export/das14a/satoh-lab/kajalk/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 2394, in squeeze
return gen_array_ops._squeeze(input, axis, name)
File "/net/per920a/export/das14a/satoh-lab/kajalk/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 5202, in _squeeze
"Squeeze", input=input, squeeze_dims=squeeze_dims, name=name)
File "/net/per920a/export/das14a/satoh-lab/kajalk/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/net/per920a/export/das14a/satoh-lab/kajalk/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2958, in create_op
set_shapes_for_outputs(ret)
File "/net/per920a/export/das14a/satoh-lab/kajalk/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2209, in set_shapes_for_outputs
shapes = shape_func(op)
File "/net/per920a/export/das14a/satoh-lab/kajalk/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2159, in call_with_requiring
return call_cpp_shape_fn(op, require_shape_fn=True)
File "/net/per920a/export/das14a/satoh-lab/kajalk/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 627, in call_cpp_shape_fn
require_shape_fn)
File "/net/per920a/export/das14a/satoh-lab/kajalk/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 691, in _call_cpp_shape_fn_impl
raise ValueError(err.message)
ValueError: Can not squeeze dim[1], expected a dimension of 1, got 14 for 'tower_0/joint_embedding/Squeeze' (op: 'Squeeze') with input shapes: [16,14,14,512].
错误的是为张量指定挤压维度。请参阅以下示例:
x = tf.get_variable('x', [2,3,4])
x = tf.squeeze(x)
在上面的示例中,CCD_ 1将具有与开始时相同的形状。挤压不起任何作用,因为张量在任何轴上都不包含形状1。
让我们看看第二个例子:
x = tf.get_variable('x', [2,3,4])
x = tf.squeeze(x, axis=1)
现在tensorflow抛出了一个异常,因为您正试图挤压与1
不同形状的维度
Can not squeeze dim[1], expected a dimension of 1, got 2
所以你应该检查你的张量在给定的轴上是否有形状1
,或者如果你想用形状1
平方所有轴,那么请不要在tf.sqeeze
函数中指定轴