I am trying to convert some tfrecord files back to jpeg images but have some errors

Viewed 40

I am trying to convert some tfrecord files back to jpeg images using the code sample section below:

for image_features in tqdm(parsed_image_dataset):
    image_raw = image_features['image'].numpy()        # accessing image array  
    # display.display(display.Image(data=image_raw))
    array = tf.io.decode_image(image_raw, dtype=tf.dtypes.uint8, expand_animations=True).numpy()
    im = Image.fromarray(array)# converting as a image
    image_path = TRAIN_IMAGES_FROM_TFRECORD_PATH +str(image_features['image_name'].numpy(),'utf8')  
    # specifying image path with image name
    im.save(image_path)
    
    # we are storing image path and target variable for later use 
    image_name_to_df.append(str(image_features['image_name'].numpy(), 'utf8'))
    target_name_to_df.append(image_features['target'].numpy())

However, I got this error message:

InvalidArgumentError Traceback (most recent call last)
<ipython-input-5-b5db5aa683ca> in <module>()
      for image_features in tqdm(parsed_image_dataset):
          image_raw = image_features['image'].numpy()        # accessing image array
          display.display(display.Image(data=image_raw))
          array = tf.io.decode_image(imag`enter code here`e_raw, dtype=tf.dtypes.uint8, expand_animations=True).numpy() # Decoding image
          im = Image.fromarray(array)# converting as a image


/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/ops.py in raise_from_not_ok_status(e, name)
   7184 def raise_from_not_ok_status(e, name):
   7185   e.message += (" name: " + name if name is not None else "")
   7186   raise core._status_to_exception(e) from None  # pylint: disable=protected-access
   7187 
   7188 

InvalidArgumentError: Feature: image (data type: string) is required but could not be found.
     [[{{node ParseSingleExample/ParseExample/ParseExampleV2}}]] [Op:IteratorGetNext]

Can someone please help me to rectify this issue. Thanks.

0 Answers
Related