BernardoGO BernardoGO -4 years ago 231
Python Question

Feed Inception with OpenCV image

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.

Answer Source

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})
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download