Repository navigation
Expand file tree
/
Copy pathextract_ovelap_images.py
More file actions
60 lines (38 loc) · 1.66 KB
/
Copy pathextract_ovelap_images.py
File metadata and controls
60 lines (38 loc) · 1.66 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
#!/usr/bin/python3.6
# -*- coding: utf-8 -*-
# @Time : 2020/6/24 23:25
# @Author : Yongfei Liu
# @Email : liuyf3@shanghaitech.edu.cn
import numpy as np
import os.path as osp
import os
import json
def extract_val_label():
path = './RefSegDatasets/refseg_anno'
img_list = []
# img_list = read_dataset(path, 'refcoco', 'training', img_list)
# img_list = read_dataset(path, 'refcoco', 'val', img_list)
# img_list = read_dataset(path, 'refcoco', 'testA', img_list)
# img_list = read_dataset(path, 'refcoco', 'testB', img_list)
# print('there are {} images in total'.format(len(img_list)))
#
# img_list = read_dataset(path, 'refcoco+', 'training', img_list)
# img_list = read_dataset(path, 'refcoco+', 'val', img_list)
# img_list = read_dataset(path, 'refcoco+', 'testA', img_list)
# img_list = read_dataset(path, 'refcoco+', 'testB', img_list)
# print('there are {} images in total'.format(len(img_list)))
img_list = read_dataset(path, 'refcocog', 'training', img_list)
img_list = read_dataset(path, 'refcocog', 'val', img_list)
print('there are {} images in total'.format(len(img_list)))
with open(osp.join(path, 'all_img_name_refcocog.json'), 'w') as dump_f:
json.dump(img_list, dump_f)
def read_dataset(path, split, data_name, img_list):
with open(osp.join(path, '{}/{}_list.txt'.format(split, data_name)), 'r') as read_f:
dataset = read_f.readlines()
for idx, im_name in enumerate(dataset):
im_name = im_name.strip().split(',')[0]
if im_name not in img_list:
img_list.append(im_name)
return img_list
if __name__ == '__main__':
extract_val_label()