简体   繁体   English

InvalidArgumentError(回溯,请参见上面的内容):张量必须为4-D,且最后为1、3或4,而不是[5,100,100,120]

[英]InvalidArgumentError (see above for traceback): Tensor must be 4-D with last dim 1, 3, or 4, not [5,100,100,120]

In tf.summary.image , max_outputs=3. tf.summary.image中 ,max_outputs = 3。 I want to visualize the output of a convolution layer where max_output is 100. In this case tf.summary.image is not working. 我想可视化max_output为100的卷积层的输出。在这种情况下,tf.summary.image无法正常工作。 Please suggest how can I visualize all feature maps(=100)? 请建议如何可视化所有要素地图(= 100)?

Code snippet 程式码片段

conv2 CONV2

with tf.variable_scope('conv2') as scope:
    kernel2 = _variable_with_weight_decay('weights', shape=[5, 5, 100, 120], stddev=1e-4, wd=0.0)
    conv2 = tf.nn.conv2d(norm1, kernel2, [1, 1, 1, 1], padding='SAME')
    biases2 = _variable_on_cpu('biases', [120], tf.constant_initializer(0.1))
    bias2 = tf.nn.bias_add(conv2, biases2)
    conv2 = tf.nn.relu(bias2, name=scope.name)
    print(tf.abs(conv2))
    _activation_summary(conv2)
    tf.summary.image('conv2', conv2, max_outputs=3)

Traceback 追溯

tf.summary.image('conv2', conv2, max_outputs=3)
  File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/tensorflow/python/summary/summary.py", line 146, in image
    tag=tag, tensor=tensor, max_images=max_outputs, name=scope)
  File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/tensorflow/python/ops/gen_logging_ops.py", line 388, in image_summary
    bad_color=bad_color, name=name)
  File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 454, in new_func
    return func(*args, **kwargs)
  File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3155, in create_op
    op_def=op_def)
  File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1717, in __init__
    self._traceback = tf_stack.extract_stack()

InvalidArgumentError (see above for traceback): Tensor must be 4-D with last dim 1, 3, or 4, not [5,100,100,120]
     [[Node: tower_3/conv2/conv2_1 = ImageSummary[T=DT_FLOAT, bad_color=Tensor<type: uint8 shape: [4] values: 255 0 0...>, max_images=3, _device="/job:localhost/replica:0/task:0/device:CPU:0"](tower_3/conv2/conv2_1/tag, tower_3/conv2/conv2-0-1-TransposeNCHWToNHWC-LayoutOptimizer/_1787)]]
     [[Node: tower_1/gradients/tower_1/deconv8/deconv8/BiasAdd_grad/BiasAddGrad/_2204 = _Send[T=DT_FLOAT, client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:1", send_device_incarnation=1, tensor_name="edge_2343_tower_1/gradients/tower_1/deconv8/deconv8/BiasAdd_grad/BiasAddGrad", _device="/job:localhost/replica:0/task:0/device:GPU:1"](tower_1/gradients/tower_1/deconv8/deconv8/BiasAdd_grad/BiasAddGrad)]]

Any type of help will be highly appreciated. 任何类型的帮助将不胜感激。

Below is the solution to the above problem. 以下是上述问题的解决方案。 The answer is taken from the Reference 答案来自参考

Here, channels = 120; 此处,渠道= 120; img_size = 100 img_size = 100

with tf.variable_scope('conv2'):
    V = tf.slice(conv2, (0, 0, 0, 0), (1, -1, -1, -1), name='slice_first_input')
    V = tf.reshape(V, (100, 100, 120))

  # Reorder so the channels are in the first dimension, x and y follow.
    V = tf.transpose(V, (2, 0, 1))
  # Bring into shape expected by image_summary
    V = tf.reshape(V, (-1, 100, 100, 1))

    tf.summary.image("first_conv", V)

暂无
暂无

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

相关问题 InvalidArgumentError(请参阅上面的回溯):重整形的输入是具有35000个值的张量,但请求的形状需要7500的倍数 - InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 35000 values, but the requested shape requires a multiple of 7500 InvalidArgumentError(参见上面的回溯):indices [1] = 10不在[0,10]中 - InvalidArgumentError (see above for traceback): indices[1] = 10 is not in [0, 10) CIFAR-10 TensorFlow:InvalidArgumentError(请参阅上面的回溯):logits和标签必须是可广播的 - CIFAR-10 TensorFlow: InvalidArgumentError (see above for traceback): logits and labels must be broadcastable Tensorflow InvalidArgumentError(请参阅上面的回溯):平面索引不会索引到参数中 - Tensorflow InvalidArgumentError (see above for traceback): flat indices does not index into param 在tensorflow中提供占位符回溯:&#39;tensorflow.python.framework.errors_impl.InvalidArgumentError:您必须提供占位符张量的值 - feed placeholder traceback in tensorflow: 'tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 重复错误:形状 (1,3) 和 (100,) 未对齐:3 (dim 1) != 100 (dim 0) - Repetitive Error: shapes (1,3) and (100,) not aligned: 3 (dim 1) != 100 (dim 0) 3D SparseTensor 矩阵乘以 2D 张量:InvalidArgumentError:张量“a_shape”必须有 2 个元素 [Op:SparseTensorDenseMatMul] - 3D SparseTensor matrix multiplication with 2D Tensor :InvalidArgumentError: Tensor 'a_shape' must have 2 elements [Op:SparseTensorDenseMatMul] 如何将张量从完全连接到4-D成形 - how to shape tensor from fully connected to to 4-D 在最后一个暗淡处填充多个火炬张量 - Pad multiple torch tensor over the last dim InvalidArgumentError:您必须使用dtype float输入占位符张量&#39;Placeholder&#39;的值 - InvalidArgumentError : You must feed a value for placeholder tensor 'Placeholder' with dtype float
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM