It might be something to do with the line of code
img = tf.transpose(img, perm=[1, 0, 2])
in encode_single_sample function.
I ran the code and checked the output by using matplotlib's matshow() function and it seemed the image was the same but was rotated by 90 degrees. Check the order of the matrix that you want for your input node and transpose the image matrix accordingly.