-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_datasets.py
More file actions
78 lines (40 loc) · 1.45 KB
/
get_datasets.py
File metadata and controls
78 lines (40 loc) · 1.45 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import csv
from shutil import copyfile
from pycocotools.coco import COCO
from tqdm import tqdm
# In[ ]:
#make directory and get annotations for training and testing
get_ipython().system('mkdir data')
get_ipython().system('wget http://msvocds.blob.core.windows.net/annotations-1-0-3/captions_train-val2014.zip -P ./data/')
get_ipython().system('unzip ./data/captions_train-val2014.zip -d ./data/')
get_ipython().system('rm ./data/captions_train-val2014.zip')
# In[ ]:
get_ipython().system('mkdir data/images')
get_ipython().system('mkdir data/images/train')
get_ipython().system('mkdir data/images/test')
# In[ ]:
coco = COCO('./data/annotations/captions_train2014.json')
# In[ ]:
#get ids of training images
with open('TrainImageIds.csv', 'r') as f:
reader = csv.reader(f)
trainIds = list(reader)
trainIds = [int(i) for i in trainIds[0]]
# In[ ]:
for img_id in trainIds:
path = coco.loadImgs(img_id)[0]['file_name']
copyfile('/datasets/COCO-2015/train2014/'+path, './data/images/train/'+path)
# In[ ]:
cocoTest = COCO('./data/annotations/captions_val2014.json')
# In[ ]:
with open('TestImageIds.csv', 'r') as f:
reader = csv.reader(f)
testIds = list(reader)
testIds = [int(i) for i in testIds[0]]
# In[ ]:
for img_id in testIds:
path = cocoValTest.loadImgs(img_id)[0]['file_name']
copyfile('/datasets/COCO-2015/val2014/'+path, './data/images/test/'+path)