Exporting the release file for image datasets to different formats
You can export the release file for image datasets to different formats with the Python SDK. Use the export_datasetutil function for this, setting the export_format parameter to one of the following:
Example:
# pip install segments-aifrom segments import SegmentsClient, SegmentsDatasetfrom segments.utils import export_dataset# Initialize a SegmentsDataset from the release fileclient =SegmentsClient('YOUR_API_KEY')release = client.get_release('jane/flowers', 'v1.0')# Alternatively: release = 'flowers-v1.0.json'dataset =SegmentsDataset(release, labelset='ground-truth', filter_by=['labeled', 'reviewed'])# Export to COCO panoptic formatexport_dataset(dataset, export_format='coco-panoptic')
Alternatively, you can use the initialized SegmentsDataset to loop through the samples and labels, and visualize or process them in any way you please:
import matplotlib.pyplot as pltfrom segments.utils import get_semantic_bitmapfor sample in dataset:# Print the sample name and list of labeled objectsprint(sample['name'])print(sample['annotations'])# Show the image plt.imshow(sample['image']) plt.show()# Show the instance segmentation label plt.imshow(sample['segmentation_bitmap']) plt.show()# Show the semantic segmentation label semantic_bitmap =get_semantic_bitmap(sample['segmentation_bitmap'], sample['annotations']) plt.imshow(semantic_bitmap) plt.show()