Skip to content

Commit 8dbb44c

Browse files
author
wyh
committed
add show
1 parent 0dc3ca5 commit 8dbb44c

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

synthesis/config.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
config.datasets.CocoCVContoursDataset = AttrDict()
88
config.datasets.CocoCVContoursDataset.auto_detect_subdir_with_basenum = 0
99

10-
config.sample_path_prefix = 'your sample path prefix'
11-
config.target_path = 'your json file path'
12-
config.output_dir = 'your output dir'
10+
sample_path_prefix_list = ['your sample path prefix list']
11+
target_path_list = ['your json file path list']
12+
config.output_label_dir = 'your output label dir'
13+
config.output_image_dir = 'your output image dir'
14+
config.show = True
1315

14-
config.test_dataset = CocoCVContoursDataset(config, config.sample_path_prefix, config.target_path)
15-
config.test_loader = torch.utils.data.DataLoader(config.test_dataset, batch_size=1, pin_memory=False)
16+
config.test_loader_list = []
17+
for i in range(len(sample_path_prefix_list)):
18+
test_dataset = CocoCVContoursDataset(config, sample_path_prefix_list[i], target_path_list[i])
19+
config.test_loader_list.append(torch.utils.data.DataLoader(test_dataset, batch_size=1, pin_memory=False))

synthesis/synthesis.py

+35-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
11
import os
2+
import numpy as np
3+
import cv2
4+
from deepvac import LOG
25

3-
def synthesis(deepvac_config):
4-
if not os.path.exists(deepvac_config.output_dir):
5-
os.makedirs(deepvac_config.output_dir)
6-
for i, (img, bbox_info, file_path) in enumerate(deepvac_config.test_loader):
7-
file_path = file_path[0]
8-
file_name = file_path.split('/')[-1]
9-
txt_name = 'gt_{}'.format(file_name.replace('jpg', 'txt'))
10-
fw = open(os.path.join(deepvac_config.output_dir, txt_name), 'w')
11-
for s in bbox_info:
12-
fw.write('{}\n'.format(s[0]))
13-
fw.close()
6+
class Synthesis(object):
7+
def __init__(self, deepvac_config):
8+
self.config = deepvac_config
9+
self.auditConfig()
10+
11+
def auditConfig(self):
12+
if not os.path.exists(self.config.output_label_dir):
13+
os.makedirs(self.config.output_label_dir)
14+
15+
if self.config.show and not os.path.exists(self.config.output_image_dir):
16+
os.makedirs(self.config.output_image_dir)
17+
18+
def synthesis(self):
19+
for i, (img, bbox_info, file_path, show_img) in enumerate(self.test_loader):
20+
file_path = file_path[0]
21+
file_name = file_path.split('/')[-1]
22+
txt_name = 'gt_{}'.format(file_name.replace('jpg', 'txt'))
23+
fw = open(os.path.join(self.config.output_label_dir, txt_name), 'w')
24+
for s in bbox_info:
25+
fw.write('{}\n'.format(s[0]))
26+
fw.close()
27+
28+
if self.config.show:
29+
cv2.imwrite(os.path.join(self.config.output_image_dir, 'bbox_{}'.format(file_name)), show_img.numpy()[0])
30+
31+
def __call__(self):
32+
for i, test_loader in enumerate(self.config.test_loader_list):
33+
LOG.logI('Process dataset {}'.format(i+1))
34+
self.test_loader = test_loader
35+
self.synthesis()
1436

1537
if __name__ == "__main__":
1638
from config import config as deepvac_config
1739

18-
synthesis(deepvac_config)
40+
synthesis = Synthesis(deepvac_config)
41+
synthesis()

0 commit comments

Comments
 (0)