1
1
import os
2
+ import numpy as np
3
+ import cv2
4
+ from deepvac import LOG
2
5
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 ()
14
36
15
37
if __name__ == "__main__" :
16
38
from config import config as deepvac_config
17
39
18
- synthesis (deepvac_config )
40
+ synthesis = Synthesis (deepvac_config )
41
+ synthesis ()
0 commit comments