我m new to tensorflow and python and I created a feed forward neural network with tensorflow that will help me to classify two groups of images. One group represents images of myself and another group represents images of a different person (I know convolutional network is better for this kind of problem but for the sake of learning I approached the FF network). All my images are stored in two separate directories. I
尝试加载图像进行训练并将其输入NN。我的图像是272x272px RGB,所以输入层应该有73984个神经元。我无法加载图像并通过网络提供它们。
我尝试使用这种方法:
filename_queue = tf.train.string_input_producer(tf.train.match_filenames_once("images/train/resized/*.jpg"))
reader = tf.WholeFileReader()
filename, content = reader.read(filename_queue)
image = tf.image.decode_jpeg(content, channels=3)
image = tf.cast(image, tf.float32)
resized_image = tf.image.resize_images(image, [272, 272])
然后,当我跑:
sess.run([optimizer], feed_dict={x: resized_image, y: 1})
I gen“Feed的值不能是tf.Tensor对象”错误
有更好的方法可以做到这一点,或者我在这里缺少什么? 谢谢!
答案 0 :(得分:1)
您的resized_image
变量是一个张量,因为您已将其初始化为tf.image.resize_images(image, [272, 272])
...您的Feed必须是一个numpy数组,其形状必须与您拥有的张量x
相匹配在代码中定义
例如,如果在你的情况下x = tf.placeholder(tf.float32, (None, 272, 272, 3))
然后你必须给它形状必须是形状的bacth(bacth_number,272,272,3)
我建议您使用以下代码来阅读图片...以此代码为例
import matplotlib.image as mpimg
image = mpimg.imread(path_to_the_image)
x = tf.placeholder(tf.float32, (None, 272, 272, 3))
并在会话中运行时:
sess.run([optimizer], feed_dict={x: image.reshape((1, image.shape[0], image.shape[1], image.shape[2])), y: 1})