Reputation: 1856
Currently I'm feeding the test for Inception v3 with:
image_data = tf.gfile.FastGFile(image_path, 'rb').read()
softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
predictions = sess.run(softmax_tensor, \
{'DecodeJpeg/contents:0': image_data})
But instead I need to crop the image before feeding it to the CNN, so I'm using imread and cropping the matrix. But if I do it I can't use it as image_data since it is expecting a jpeg binary.
Upvotes: 2
Views: 752
Reputation: 190
predictions = sess.run(softmax_tensor, {'DecodeJpeg/contents:0': cv2.imencode('.jpg', image_data)[1].tostring()})
Upvotes: 2
Reputation: 1856
Solved by using PIL instead of OpenCV. It is possible to feed it directly and also the drawing function seems better than the one I was using for OpenCV.
img = Image.open(tstImg)
image = img.resize((1936, 1296), Image.ANTIALIAS)
crop_img = image.crop((x, y, x+x_adds, y+y_adds))
predictions = sess.run(softmax_tensor, {'DecodeJpeg:0': crop_img})
Upvotes: 0