2017-12-26 26 views
0

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 m 이미지를로드하여 NN에 공급하려고합니다. 내 이미지는 272x272 픽셀 RGB이므로 입력 레이어에는 73984 개의 뉴런이 있어야합니다. 이미지를로드하고 네트워크를 통해 이미지를로드 할 수 없습니다. 내가 실행할 때, 다음사용자 정의 이미지를 tensorflow로로드

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 세대 오류

"피드의 값이 tf.Tensor 객체가 될 수 없다"

나는이 방법을 사용하여 시도

더 나은 방법이 있습니까? 아니면 여기에서 누락 되었습니까? 감사합니다.

답변

1

귀하의 resized_image 변수는 tf.image.resize_images(image, [272, 272])에 초기화가 같은 텐서입니다 ... 피드는 그 모양이 경우 귀하의 경우 예를 들어 코드 에 정의 된 텐서 x 일치하는 NumPy와 배열을 수있다 x = tf.placeholder(tf.float32, (None, 272, 272, 3)) 다음 그것을 모양이어야 이미지 (bacth_number, 272, 272, 3)

난 당신이 이미지를 읽는 코드를 다음과 같은 제안은 ... 예를 들어

으로이 코드를 취할의 bacth을 제공해야
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}) 
+0

감사합니다. 그러나 코드를 실행할 때 정의 된 뉴런 수가 실제 입력 데이터와 일치하지 않기 때문에 네트워크 구조에서 첫 번째 레이어의 합계를 계산할 수 없습니다. 그러면 입력 뉴런의 수는 얼마입니까? –

+0

입력 텐서를'x = tf.placeholder (tf.float32, (272, 272))'로 만들고 PIL을 사용하여 그레이 스케일'gray_image = Image.open ('image.png')의 이미지를 읽습니다. LA ')'그리고 나서 텐서'x'에'gray_image'를 입력하십시오. 여러분의 입력 뉴런은 텐서'x'의 형태에 따라 달라집니다. – Jai

+0

감사합니다! –