Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can tf.image.decode_jpeg decode a png?

Today I was testing some tensorflow (python) codes. It's a neural network on the famous MNIST set.

Everything worked well, so I just read through the codes and studied the structure of that network.

When it came to the image input, I found the following code:

image_string = tf.read_file(filename)

image_decoded = tf.image.decode_jpeg(image_string, channels=3)

The code is using "decode_jpeg" instead of "decode_png". And I didn't see any error.

However, I am 100% sure that the images are in PNG format.

I have used

od -c -b 1.png

to look into those images and they are PNGs.

So, why could "decode_jpeg" work on PNGs ? And is there any potential issue that might be caused by this?

like image 680
user10253771 Avatar asked Aug 30 '18 08:08

user10253771


1 Answers

The documentation for tensorflow states:

This op also supports decoding PNGs and non-animated GIFs since the interface is the same, though it is cleaner to use tf.image.decode_image.

So essentially it was a design decision that because the interface is the same to just handle it, rather than throw an error that forces user to use the correct API call.

like image 55
James Kent Avatar answered Oct 22 '22 09:10

James Kent