|
1 | | -import pandas as pd |
2 | 1 | import matplotlib.pyplot as plt |
| 2 | +import pandas as pd |
3 | 3 | from tqdm import tqdm |
| 4 | + |
4 | 5 | try: |
5 | 6 | from urllib.request import urlretrieve # Python 3 |
6 | 7 | except ImportError: |
7 | 8 | from urllib import urlretrieve # Python 2 |
8 | | -classes = pd.read_csv('./classes.csv') |
9 | | -labelnames = classes['LabelName'].tolist() |
10 | | -classnames = classes['DisplayName'].tolist() |
| 9 | + |
| 10 | +classes = pd.read_csv("./classes.csv") |
| 11 | +labelnames = classes["LabelName"].tolist() |
| 12 | +classnames = classes["DisplayName"].tolist() |
11 | 13 | __imageids = [] |
12 | 14 | __imageids_and_bbox = {} |
13 | 15 | imageids = [] |
|
22 | 24 | image_id = 0 |
23 | 25 |
|
24 | 26 | imageid_and_labelname = pd.read_csv( |
25 | | - './open_images_data/oidv6-train-annotations-human-imagelabels.csv') |
26 | | -imageid_and_labelname.append(pd.read_csv( |
27 | | - './open_images_data/test-annotations-human-imagelabels-boxable.csv')) |
28 | | -imageid_and_labelname.append(pd.read_csv( |
29 | | - './open_images_data/test-annotations-machine-imagelabels.csv')) |
30 | | -imageid_and_labelname.append(pd.read_csv( |
31 | | - './open_images_data/train-annotations-human-imagelabels-boxable.csv')) |
32 | | -imageid_and_labelname.append(pd.read_csv( |
33 | | - './open_images_data/train-annotations-machine-imagelabels.csv')) |
34 | | -imageid_and_labelname.append(pd.read_csv( |
35 | | - './open_images_data/validation-annotations-human-imagelabels-boxable.csv')) |
36 | | -imageid_and_labelname.append(pd.read_csv( |
37 | | - './open_images_data/validation-annotations-machine-imagelabels.csv')) |
38 | | -tqdm_iter = tqdm(imageid_and_labelname['ImageID']) |
39 | | -for imageid, labelname in zip(tqdm_iter, imageid_and_labelname['LabelName']): |
| 27 | + "./open_images_data/oidv6-train-annotations-human-imagelabels.csv") |
| 28 | +imageid_and_labelname.append( |
| 29 | + pd.read_csv( |
| 30 | + "./open_images_data/test-annotations-human-imagelabels-boxable.csv")) |
| 31 | +imageid_and_labelname.append( |
| 32 | + pd.read_csv("./open_images_data/test-annotations-machine-imagelabels.csv")) |
| 33 | +imageid_and_labelname.append( |
| 34 | + pd.read_csv( |
| 35 | + "./open_images_data/train-annotations-human-imagelabels-boxable.csv")) |
| 36 | +imageid_and_labelname.append( |
| 37 | + pd.read_csv( |
| 38 | + "./open_images_data/train-annotations-machine-imagelabels.csv")) |
| 39 | +imageid_and_labelname.append( |
| 40 | + pd.read_csv( |
| 41 | + "./open_images_data/validation-annotations-human-imagelabels-boxable.csv" |
| 42 | + )) |
| 43 | +imageid_and_labelname.append( |
| 44 | + pd.read_csv( |
| 45 | + "./open_images_data/validation-annotations-machine-imagelabels.csv")) |
| 46 | +tqdm_iter = tqdm(imageid_and_labelname["ImageID"]) |
| 47 | +for imageid, labelname in zip(tqdm_iter, imageid_and_labelname["LabelName"]): |
40 | 48 | if labelname in labelnames: |
41 | | - tqdm_iter.set_description(f'{imageid}-{labelname}') |
| 49 | + tqdm_iter.set_description(f"{imageid}-{labelname}") |
42 | 50 | __imageids.append(imageid) |
43 | 51 |
|
44 | 52 | del imageid_and_labelname |
45 | 53 |
|
46 | | - |
47 | 54 | xmin_ymin_xmax_ymax = pd.read_csv( |
48 | | - './open_images_data/oidv6-train-annotations-bbox.csv') |
49 | | -xmin_ymin_xmax_ymax.append(pd.read_csv( |
50 | | - './open_images_data/test-annotations-bbox.csv')) |
51 | | -xmin_ymin_xmax_ymax.append(pd.read_csv( |
52 | | - './open_images_data/validation-annotations-bbox.csv')) |
| 55 | + "./open_images_data/oidv6-train-annotations-bbox.csv") |
| 56 | +xmin_ymin_xmax_ymax.append( |
| 57 | + pd.read_csv("./open_images_data/test-annotations-bbox.csv")) |
| 58 | +xmin_ymin_xmax_ymax.append( |
| 59 | + pd.read_csv("./open_images_data/validation-annotations-bbox.csv")) |
53 | 60 | for i in tqdm(range(len(xmin_ymin_xmax_ymax))): |
54 | 61 | info = xmin_ymin_xmax_ymax.iloc[i] |
55 | | - if info['ImageID'] in __imageids: |
56 | | - __imageids_and_bbox[info['ImageID']] = [ |
57 | | - info['XMin'], info['YMin'], info['XMax'], info['YMax']] |
| 62 | + if info["ImageID"] in __imageids: |
| 63 | + __imageids_and_bbox[info["ImageID"]] = [ |
| 64 | + info["XMin"], |
| 65 | + info["YMin"], |
| 66 | + info["XMax"], |
| 67 | + info["YMax"], |
| 68 | + ] |
58 | 69 | del xmin_ymin_xmax_ymax |
59 | 70 |
|
60 | 71 | urls = pd.read_csv( |
61 | | - './open_images_data/oidv6-train-images-with-labels-with-rotation.csv') |
62 | | -urls.append(pd.read_csv( |
63 | | - './open_images_data/test-images-with-rotation.csv')) |
64 | | -urls.append(pd.read_csv( |
65 | | - './open_images_data/train-images-boxable-with-rotation.csv')) |
66 | | -urls.append(pd.read_csv( |
67 | | - './open_images_data/validation-images-with-rotation.csv')) |
| 72 | + "./open_images_data/oidv6-train-images-with-labels-with-rotation.csv") |
| 73 | +urls.append(pd.read_csv("./open_images_data/test-images-with-rotation.csv")) |
| 74 | +urls.append( |
| 75 | + pd.read_csv("./open_images_data/train-images-boxable-with-rotation.csv")) |
| 76 | +urls.append( |
| 77 | + pd.read_csv("./open_images_data/validation-images-with-rotation.csv")) |
68 | 78 | for i in tqdm(range(len(urls))): |
69 | 79 | url = urls.iloc[i] |
70 | | - if url['ImageID'] in __imageids: |
71 | | - urlretrieve(url['OriginalURL'], f"./data/{image_id}.png") |
72 | | - xmin, ymin, xmax, ymax = __imageids_and_bbox[url['ImageID']] |
| 80 | + if url["ImageID"] in __imageids: |
| 81 | + urlretrieve(url["OriginalURL"], f"./data/{image_id}.png") |
| 82 | + xmin, ymin, xmax, ymax = __imageids_and_bbox[url["ImageID"]] |
73 | 83 | file_names.append(f"./data/{image_id}.png") |
74 | | - type_of_data.append(url['Subset']) |
75 | | - imageurls.append(url['OriginalURL']) |
76 | | - imageurls_original.append(url['OriginalLandingURL']) |
77 | | - imageids.append(url['ImageID']) |
| 84 | + type_of_data.append(url["Subset"]) |
| 85 | + imageurls.append(url["OriginalURL"]) |
| 86 | + imageurls_original.append(url["OriginalLandingURL"]) |
| 87 | + imageids.append(url["ImageID"]) |
78 | 88 | xmins.append(xmin) |
79 | 89 | ymins.append(ymin) |
80 | 90 | xmaxs.append(xmax) |
81 | 91 | ymaxs.append(ymax) |
82 | 92 | image_id += 1 |
83 | 93 |
|
84 | 94 | data = pd.DataFrame({ |
85 | | - 'ImageIds': imageids, |
86 | | - 'XMin': xmins, |
87 | | - 'YMin': ymins, |
88 | | - 'XMax': xmaxs, |
89 | | - 'YMax': ymaxs, |
90 | | - 'File Name': file_names, |
91 | | - 'ImageUrls': imageurls, |
92 | | - 'Og_ImageUrls': imageurls_original, |
93 | | - 'Type of Data': type_of_data, |
| 95 | + "ImageIds": imageids, |
| 96 | + "XMin": xmins, |
| 97 | + "YMin": ymins, |
| 98 | + "XMax": xmaxs, |
| 99 | + "YMax": ymaxs, |
| 100 | + "File Name": file_names, |
| 101 | + "ImageUrls": imageurls, |
| 102 | + "Og_ImageUrls": imageurls_original, |
| 103 | + "Type of Data": type_of_data, |
94 | 104 | }) |
95 | | -data.to_csv('./data.csv') |
| 105 | +data.to_csv("./data.csv") |
0 commit comments