报错信息:
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])