-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetchImages.py
46 lines (38 loc) · 1.47 KB
/
fetchImages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import sys
import fetchCOCO as COCO
import fetchOpenImages as OpenImages
import fetchPersonal as Personal
import fetchVisualGenome as VisualGenome
import getopt
usage = ("fetch.py destination categories...\n" +
" Places images for all categories, resized and cropped, to destination. Each category will be under a folder of the same name.\n")
if __name__ == '__main__':
args = sys.argv[1:]
try:
opts, args = getopt.getopt(args, 'r:', ['resolution='])
except getopt.GetoptError as err:
print(err)
print(usage)
sys.exit(2)
if (len(args) < 2):
print(usage)
sys.exit()
targetDims = (336, 280)
try:
for opt, val in opts:
if opt in ['-r', '--resolution']:
targetDims = val.split('x', 1)
targetDims = (int(targetDims[0]), int(targetDims[1]))
except Exception as err:
print(err)
print(usage)
sys.exit(2)
destination = args[0].rstrip("/")
categories = args[1:]
for category in categories:
COCO.fetchCategory(category, targetDims, f"{destination}/{category}")
OpenImages.fetchCategory(category, targetDims, f"{destination}/{category}")
Personal.fetchCategory(category, targetDims, f"{destination}/{category}")
VisualGenome.fetchCategory(category, targetDims, f"{destination}/{category}")
print("\n")
print(f"DONE! All images of {', '.join(categories)} in all databases saved to {destination}")