I am trying to read and decode an image file using Tensorflow. I have the following code:
dir_path = os.path.dirname(os.path.realpath(__file__))
filename = dir_path + '/images/cat/cat1.jpg'
image_file = tf.read_file(filename)
image_decoded = tf.image.decode_jpeg(image_file, channels=3)
print(image_file)
print(image_decoded)
This results in the following output:
Tensor("ReadFile:0", shape=(), dtype=string)
Tensor("DecodeJpeg:0", shape=(?, ?, 3), dtype=uint8)
It appears as if the file is not read at all by Tensorflow. However I could not find any error messages indicating that something went wrong. I don't know how I can resolve this, any help would be greatly appreciated!
Tensorflow creates a computation graph which should then be evaluated. What you see over there in the result is the op that is created. You need to define a Session object to get the results of your operations.
dir_path = os.path.dirname(os.path.realpath(__file__))
filename = dir_path + '/images/cat/cat1.jpg'
image_file = tf.read_file(filename)
image_decoded = tf.image.decode_jpeg(image_file, channels=3)
with tf.Session() as sess:
f, img = sess.run([image_file, image_decoded])
print(f)
print(img)
Check out this tensorflow resource to help you further understand!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With