27
27
)
28
28
from densepose .vis .extractor import CompoundExtractor , create_extractor
29
29
30
- LOGGER_NAME = "apply_net"
31
- logger = logging .getLogger (LOGGER_NAME )
30
+
31
+ opts = []
32
+ config_fpath = '/workspace/detectron2_repo/configs/densepose_rcnn_R_50_FPN_s1x_legacy.yaml'
33
+ model_fpath = '/workspace/detectron2_repo/densepose_rcnn_R_50_FPN_s1x.pkl'
34
+
35
+ def setup_config ():
36
+ cfg = get_cfg ()
37
+ add_densepose_config (cfg )
38
+ cfg .merge_from_file (config_fpath )
39
+ if opts :
40
+ cfg .merge_from_list (opts )
41
+ cfg .MODEL .WEIGHTS = model_fpath
42
+ cfg .MODEL .DEVICE = 'cuda'
43
+ cfg .freeze ()
44
+ return cfg
45
+
46
+ cfg = setup_config ()
32
47
33
48
class Action (object ):
34
49
pass
35
50
36
51
class InferenceAction (Action ):
37
52
@classmethod
38
53
def execute (cls : type , args : argparse .Namespace ):
39
- logger .info (f"Loading config from { args .cfg } " )
40
- opts = []
41
- cfg = cls .setup_config (args .cfg , args .model , args , opts )
42
- logger .info (f"Loading model from { args .model } " )
43
54
predictor = DefaultPredictor (cfg )
44
- logger .info (f"Loading data from { args .input } " )
45
- # file_list = cls._get_input_file_list(args.input)
46
- # if len(file_list) == 0:
47
- # logger.warning(f"No input images for {args.input}")
48
- # return
49
55
file_list = [args .input ]
50
56
context = cls .create_context (args )
51
57
for file_name in file_list :
@@ -57,20 +63,6 @@ def execute(cls: type, args: argparse.Namespace):
57
63
cls .postexecute (context )
58
64
return out_binary
59
65
60
- @classmethod
61
- def setup_config (
62
- cls : type , config_fpath : str , model_fpath : str , args : argparse .Namespace , opts : List [str ]
63
- ):
64
- cfg = get_cfg ()
65
- add_densepose_config (cfg )
66
- cfg .merge_from_file (config_fpath )
67
- if opts :
68
- cfg .merge_from_list (opts )
69
- cfg .MODEL .WEIGHTS = model_fpath
70
- cfg .MODEL .DEVICE = 'cuda'
71
- cfg .freeze ()
72
- return cfg
73
-
74
66
class ShowAction (InferenceAction ):
75
67
"""
76
68
Show action that visualizes selected entries on an image
@@ -85,18 +77,6 @@ class ShowAction(InferenceAction):
85
77
"bbox" : ScoredBoundingBoxVisualizer ,
86
78
}
87
79
88
- @classmethod
89
- def setup_config (
90
- cls : type , config_fpath : str , model_fpath : str , args : argparse .Namespace , opts : List [str ]
91
- ):
92
- opts .append ("MODEL.ROI_HEADS.SCORE_THRESH_TEST" )
93
- opts .append (str (args .min_score ))
94
- if args .nms_thresh is not None :
95
- opts .append ("MODEL.ROI_HEADS.NMS_THRESH_TEST" )
96
- opts .append (str (args .nms_thresh ))
97
- cfg = super (ShowAction , cls ).setup_config (config_fpath , model_fpath , args , opts )
98
- return cfg
99
-
100
80
@classmethod
101
81
def execute_on_outputs (
102
82
cls : type , context : Dict [str , Any ], entry : Dict [str , Any ], outputs : Instances
@@ -106,7 +86,6 @@ def execute_on_outputs(
106
86
visualizer = context ["visualizer" ]
107
87
extractor = context ["extractor" ]
108
88
image_fpath = entry ["file_name" ]
109
- logger .info (f"Processing { image_fpath } " )
110
89
image = cv2 .cvtColor (entry ["image" ], cv2 .COLOR_BGR2GRAY )
111
90
image = np .tile (image [:, :, np .newaxis ], [1 , 1 , 3 ])
112
91
data = extractor (outputs )
@@ -117,7 +96,6 @@ def execute_on_outputs(
117
96
# if len(out_dir) > 0 and not os.path.exists(out_dir):
118
97
# os.makedirs(out_dir)
119
98
# cv2.imwrite(out_fname, image_vis)
120
- logger .info (f"Output saved to { out_fname } " )
121
99
context ["entry_idx" ] += 1
122
100
return cv2 .imencode ('.jpg' , image_vis )[1 ]
123
101
@classmethod
@@ -151,18 +129,13 @@ def create_context(cls: type, args: argparse.Namespace) -> Dict[str, Any]:
151
129
152
130
def main (file_in_memory ):
153
131
args = argparse .Namespace ()
154
- args .cfg = '/workspace/detectron2_repo/configs/densepose_rcnn_R_50_FPN_s1x_legacy.yaml'
155
132
args .func = ShowAction .execute
156
133
args .input = file_in_memory
157
134
args .min_score = 0.8
158
- args .model = '/workspace/detectron2_repo/densepose_rcnn_R_50_FPN_s1x.pkl'
159
135
args .nms_thresh = None
160
136
args .output = 'outputres2.png'
161
137
args .verbosity = None
162
138
args .visualizations = 'dp_contour,bbox'
163
139
verbosity = args .verbosity if hasattr (args , "verbosity" ) else None
164
- global logger
165
- logger = setup_logger (name = LOGGER_NAME )
166
- logger .setLevel (verbosity_to_level (verbosity ))
167
140
out_binary_buffer = args .func (args )
168
141
return out_binary_buffer
0 commit comments