Datasets:

Modalities:
Image
Video
Formats:
parquet
Size:
< 1K
Libraries:
Datasets
pandas
License:
MohamedTEV commited on
Commit
8750664
·
verified ·
1 Parent(s): 01bcabc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +42 -1
README.md CHANGED
@@ -53,7 +53,48 @@ Note that the annotations follow the YOLO instance segmentation format.
53
  Please refer to [this page](https://docs.ultralytics.com/datasets/segment/) for more info.
54
 
55
  ## 🧪 How to use
56
- Coming soon ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
 
59
  ## 🙏 Acknowledgement
 
53
  Please refer to [this page](https://docs.ultralytics.com/datasets/segment/) for more info.
54
 
55
  ## 🧪 How to use
56
+ from datasets import load_dataset
57
+ import matplotlib.pyplot as plt
58
+ import random
59
+ import numpy as np
60
+
61
+ def show_example(dataset):
62
+ example = dataset[random.randint(0, len(dataset) - 1)]
63
+ image = example["image"].convert("RGB")
64
+ annotations = example["annotations"]
65
+ width, height = image.size
66
+
67
+ fig, ax = plt.subplots(1)
68
+ ax.imshow(image)
69
+
70
+ num_instances = len(annotations)
71
+ colors = plt.cm.get_cmap('viridis', num_instances)
72
+
73
+ if annotations:
74
+ for i, annotation in enumerate(annotations):
75
+ class_id = annotation["class_id"]
76
+ segmentation = annotation.get("segmentation")
77
+ if segmentation and len(segmentation) > 0:
78
+ polygon_norm = segmentation[0]
79
+ if polygon_norm:
80
+ polygon_abs = np.array([(p[0] * width, p[1] * height) for p in polygon_norm])
81
+ x, y = polygon_abs[:, 0], polygon_abs[:, 1]
82
+ color = colors(i)
83
+ ax.fill(x, y, color=color, alpha=0.5)
84
+
85
+ plt.title(f"Example with {len(annotations)} instances")
86
+ plt.axis('off')
87
+ plt.show()
88
+
89
+ if __name__ == "__main__":
90
+ dataset_name = "MohamedTEV/FishGrade"
91
+ try:
92
+ fish_dataset = load_dataset(dataset_name, split="train")
93
+ print(fish_dataset)
94
+ show_example(fish_dataset)
95
+ except Exception as e:
96
+ print(f"Error loading or displaying the dataset: {e}")
97
+ print(f"Make sure the dataset '{dataset_name}' exists and is public, or you are logged in if it's private.")
98
 
99
 
100
  ## 🙏 Acknowledgement