注意模块中的ValueError

  

ValueError:无法压缩dim [1],预期尺寸为1,输入形状为[16,14,512]的'tower_0 / joint_embedding / Squeeze'(op:'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",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,512].
maochanggeng 回答:注意模块中的ValueError

您遇到的错误是错误地为张量指定挤压尺寸。 请参见下面的示例:

logincomponent

在上面的示例中,x = tf.get_variable('x',[2,3,4]) x = tf.squeeze(x) 将具有与开头相同的形状。压缩不执行任何操作,因为张量在任何轴上都不包含形状1。

让我们看看第二个例子:

x

现在tensorflow引发异常,因为您试图挤压形状与x = tf.get_variable('x',4]) x = tf.squeeze(x,axis=1) 不同的尺寸

  

1

因此,您应该检查张量在给定轴上是否具有形状Can not squeeze dim[1],expected a dimension of 1,got 2,或者是否要压缩形状为1的所有轴,那么请不要在1中指定轴功能

本文链接:https://www.f2er.com/3147527.html

大家都在问