当前位置: 代码迷 >> 综合 >> TensorFlow 报错:InvalidArgumentError (see above for traceback): tags and values not the same shape: []
  详细解决方案

TensorFlow 报错:InvalidArgumentError (see above for traceback): tags and values not the same shape: []

热度:56   发布时间:2024-01-14 07:03:01.0

报错信息:
TypeError: Failed to convert object of type <class 'list'> to Tensor. Contents: [None, 3136]. Consider casting elements to a supported type.

 

报错源码:

>>> layer_pool2_shapes = layer_pool2.get_shape()
>>> layer_pool2_shapes_list = layer_pool2_shapes.as_list()
>>> batch_size = layer_pool2_shapes_list[0]
>>> input_num = layer_pool2_shapes_list[1]*layer_pool2_shapes_list[2]*layer_pool2_shapes_list[3]
>>> print(input_num)
>>> layer_pool2_flat = tf.reshape(tensor=layer_pool2, shape=[batch_size, input_num])

问题出在最后一句 tf.reshape 处,其中参数 shape 中的 batch_size 的问题

 

解决方法:shape 中的 batch_size 改为 -1

tf.reshape(tensor=layer_pool2, shape=[-1, input_num])

  相关解决方案