问题说明:
对于image_batch进行feed_dict,结果一直报错:
TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, numpy ndarrays, or TensorHandles.For reference, the tensor object was Tensor("shuffle_batch_1:1", shape=(3, 5), dtype=int32) which was passed to the feed with key Tensor("y-input_1:0", shape=(?, 5), dtype=float32).
问题分析:
feed_dict不能喂入tf张量,可以喂入数组,字符串,列表等
而喂入的image_batch经过了tf.reshape,变成了tf张量。
解决方法:
将tf.Tensor变成数组即可。
数组与张量的互相转换:
import tensorflow as tf
sess=tf.Session()
sess.run(tf.global_variables_initializer())
#转化为numpy数组
img_numpy=img.eval(session=sess)
print("out2=",type(img_numpy))
#转化为tensor
img_tensor= tf.convert_to_tensor(img_numpy)
print("out2=",type(img_tensor))