1

I have a issue with converting tfrecords back to images:

def _parse_test_image_function(img):
    image_feature_description = {
        'image/file_name': tf.io.FixedLenFeature([], tf.string),
        'image/encoded_image': tf.io.FixedLenFeature([], tf.string),
    }
    return tf.io.parse_single_example(img, image_feature_description)

test_dataset = tf.data.TFRecordDataset(temp_path)
test_dataset = test_dataset.map(_parse_test_image_function)

print(tf.__version__)
images = test_dataset.take(1)
print(images)

2.5.0
<TakeDataset shapes: {image/encoded_image: (), image/file_name: ()}, types: {image/encoded_image: tf.string, image/file_name: tf.string}>

Fields in image_feature_description are correct

also I saw this Converting TFRecords back into JPEG Images But this is not very helpful for me because some of functions which is used in answers outdated.

t123
  • 11
  • 5

1 Answers1

0

You can get the image as numpy array by using the below code.

import numpy as np
import PIL.Image as Image
gold_fish=Image.open('/content/gold.jpeg')
gold_fish=np.array(gold_fish)

Thank You.

  • Thank you for your answer, but I meant something like that https://www.tensorflow.org/api_docs/python/tf/io/parse_single_example – t123 Nov 14 '22 at 12:04