Skip to content

Commit 00f10e6

Browse files
authored
Merge pull request #11 from wyh163/add_synthesis
add synthesis
2 parents 36513c4 + 8dbb44c commit 00f10e6

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

synthesis/config.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import torch
2+
from deepvac import new, AttrDict
3+
from deepvac.datasets import CocoCVContoursDataset
4+
5+
config = new(None)
6+
7+
config.datasets.CocoCVContoursDataset = AttrDict()
8+
config.datasets.CocoCVContoursDataset.auto_detect_subdir_with_basenum = 0
9+
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
15+
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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
import numpy as np
3+
import cv2
4+
from deepvac import LOG
5+
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()
36+
37+
if __name__ == "__main__":
38+
from config import config as deepvac_config
39+
40+
synthesis = Synthesis(deepvac_config)
41+
synthesis()

0 commit comments

Comments
 (0)