Datasets:
Update CC6204-Hackaton-Cub-Dataset.py
Browse files
CC6204-Hackaton-Cub-Dataset.py
CHANGED
@@ -29,7 +29,7 @@ _URLS = {
|
|
29 |
"mini_images_urls": f"{_REPO}/dummy/mini_images.zip"
|
30 |
}
|
31 |
|
32 |
-
# Create
|
33 |
classes = get(_URLS["classes"]).iter_lines()
|
34 |
_ID2LABEL = {}
|
35 |
for row in classes:
|
@@ -41,6 +41,15 @@ for row in classes:
|
|
41 |
|
42 |
_NAMES = list(_ID2LABEL.values())
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
# build from images.txt: a mapping from image_file_name -> id
|
46 |
imgpath_to_ids = get(_URLS["images"]).iter_lines()
|
@@ -138,6 +147,6 @@ class CubDataset(datasets.GeneratorBasedBuilder):
|
|
138 |
if file_name.endswith(".jpg"):
|
139 |
yield i, {
|
140 |
"image": path,
|
141 |
-
"labels": _ID2LABEL[
|
142 |
}
|
143 |
|
|
|
29 |
"mini_images_urls": f"{_REPO}/dummy/mini_images.zip"
|
30 |
}
|
31 |
|
32 |
+
# Create ClassId-to-label dictionary using the classes file
|
33 |
classes = get(_URLS["classes"]).iter_lines()
|
34 |
_ID2LABEL = {}
|
35 |
for row in classes:
|
|
|
41 |
|
42 |
_NAMES = list(_ID2LABEL.values())
|
43 |
|
44 |
+
# Create imageId-to-ClassID dictionary using the image_class_labels
|
45 |
+
img_idx_2_class_idx = get(_URLS["image_class_labels"]).iter_lines()
|
46 |
+
_IMGID2CLASSID = {}
|
47 |
+
for row in img_idx_2_class_idx:
|
48 |
+
row = row.decode("UTF8")
|
49 |
+
if row != "":
|
50 |
+
idx, class_id = row.split(" ")
|
51 |
+
_IMGID2CLASSID[idx] = int(class_id)
|
52 |
+
|
53 |
|
54 |
# build from images.txt: a mapping from image_file_name -> id
|
55 |
imgpath_to_ids = get(_URLS["images"]).iter_lines()
|
|
|
147 |
if file_name.endswith(".jpg"):
|
148 |
yield i, {
|
149 |
"image": path,
|
150 |
+
"labels": _ID2LABEL[_IMGID2CLASSID[image_idx[i]]],
|
151 |
}
|
152 |
|