openrsgis / pytdml

Python library for TrainingDML-AI encode/decode
MIT License
16 stars 7 forks source link

How to fix - ValueError: The given json_dict is not a valid PixelLabel #6

Open omshinde opened 1 year ago

omshinde commented 1 year ago

I am trying to run an example for generating TDML for a semantic segmentation task. I am able to generate the json file successfully but when trying to load it again, it gives the following error-

File "/opt/homebrew/anaconda3/lib/python3.10/site-packages/pytdml/io/tdml_readers.py", line 47, in read_from_json
    return EOTrainingDataset.from_dict(json_dict)
  File "/opt/homebrew/anaconda3/lib/python3.10/site-packages/pytdml/type/extended_types.py", line 358, in from_dict
    td.data = [EOTrainingData.from_dict(data) for data in json_dict["data"]]
  File "/opt/homebrew/anaconda3/lib/python3.10/site-packages/pytdml/type/extended_types.py", line 358, in <listcomp>
    td.data = [EOTrainingData.from_dict(data) for data in json_dict["data"]]
  File "/opt/homebrew/anaconda3/lib/python3.10/site-packages/pytdml/type/extended_types.py", line 265, in from_dict
    training_data.labels = [PixelLabel.from_dict(label) for label in json_dict["labels"]]
  File "/opt/homebrew/anaconda3/lib/python3.10/site-packages/pytdml/type/extended_types.py", line 265, in <listcomp>
    training_data.labels = [PixelLabel.from_dict(label) for label in json_dict["labels"]]
  File "/opt/homebrew/anaconda3/lib/python3.10/site-packages/pytdml/type/extended_types.py", line 141, in from_dict
    raise ValueError("The given json_dict is not a valid PixelLabel")
ValueError: The given json_dict is not a valid PixelLabel

Code to read the json file -

import pytdml

training_dataset = pytdml.io.read_from_json("flair.json")  # read from TDML json file
print("Load training dataset: " + training_dataset.name)
print("Number of training samples: " + str(training_dataset.amount_of_training_data))
print("Number of classes: " + str(training_dataset.number_of_classes))

Please let me know if I am missing something here. Thank you. PS: The images and labels are .tiff file and stored in the directory data/train and data/label respectively.

boyi-shangguan commented 1 year ago

There are 2 required properties for PixelLabel: imageURL and imageFormat, you may have missed the imageFormat property.