1.程序报错:feed的值不能是一个tensor,只能是标量、字符串、列表、数组等,所以不能用tf.reshape, 应该使用np.reshape。
with tf.Session() as sess:
tf.global_variables_initializer().run()
v_x = tf.reshape(mnist.validation.images, [mnist.validation.num_examples, 28, 28, 1])
t_x = tf.reshape(mnist.test.images, [mnist.test.num_examples, 28, 28, 1])
validate_feed = {x: v_x, y: mnist.validation.labels}
test_feed = {x: t_x, y: mnist.test.labels}
TypeError: The value of a feed cannot be a tf.Tensor object.
Acceptable feed values include Python scalars, strings, lists, numpy ndarrays, or TensorHandles.
2.pool_shape的第一维是None,这是为了便于调整batch大小,但是这样的话tf.reshape无法将输出的矩阵转换为向量。可以直接使用slim.flatten()函数进行转换,不需要读取shape的大小。
# 将输出矩阵拉伸成一个向量
pool_shape = pool2.get_shape().as_list() # 只有tensor能用get_shape,as_list将元组转换为列表
nodes = pool_shape[1]*pool_shape[2]*pool_shape[3]
reshaped = tf.reshape(pool2, [pool_shape[0], nodes])
TypeError: Failed to convert object of type <class 'list'> to Tensor.
pool_shape = pool2.get_shape().as_list()
nodes = pool_shape[1]*pool_shape[2]*pool_shape[3]
reshaped = tf.contrib.slim.flatten(pool2)