Skip to content

Commit 2df07a8

Browse files
committed
fix omport file name
1 parent e333ac4 commit 2df07a8

File tree

4 files changed

+39
-89
lines changed

4 files changed

+39
-89
lines changed

apply_net-gpu.py

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,31 @@
2727
)
2828
from densepose.vis.extractor import CompoundExtractor, create_extractor
2929

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()
3247

3348
class Action(object):
3449
pass
3550

3651
class InferenceAction(Action):
3752
@classmethod
3853
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}")
4354
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
4955
file_list = [args.input]
5056
context = cls.create_context(args)
5157
for file_name in file_list:
@@ -57,20 +63,6 @@ def execute(cls: type, args: argparse.Namespace):
5763
cls.postexecute(context)
5864
return out_binary
5965

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-
7466
class ShowAction(InferenceAction):
7567
"""
7668
Show action that visualizes selected entries on an image
@@ -85,18 +77,6 @@ class ShowAction(InferenceAction):
8577
"bbox": ScoredBoundingBoxVisualizer,
8678
}
8779

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-
10080
@classmethod
10181
def execute_on_outputs(
10282
cls: type, context: Dict[str, Any], entry: Dict[str, Any], outputs: Instances
@@ -106,7 +86,6 @@ def execute_on_outputs(
10686
visualizer = context["visualizer"]
10787
extractor = context["extractor"]
10888
image_fpath = entry["file_name"]
109-
logger.info(f"Processing {image_fpath}")
11089
image = cv2.cvtColor(entry["image"], cv2.COLOR_BGR2GRAY)
11190
image = np.tile(image[:, :, np.newaxis], [1, 1, 3])
11291
data = extractor(outputs)
@@ -117,7 +96,6 @@ def execute_on_outputs(
11796
# if len(out_dir) > 0 and not os.path.exists(out_dir):
11897
# os.makedirs(out_dir)
11998
# cv2.imwrite(out_fname, image_vis)
120-
logger.info(f"Output saved to {out_fname}")
12199
context["entry_idx"] += 1
122100
return cv2.imencode('.jpg', image_vis)[1]
123101
@classmethod
@@ -151,18 +129,13 @@ def create_context(cls: type, args: argparse.Namespace) -> Dict[str, Any]:
151129

152130
def main(file_in_memory):
153131
args = argparse.Namespace()
154-
args.cfg='/workspace/detectron2_repo/configs/densepose_rcnn_R_50_FPN_s1x_legacy.yaml'
155132
args.func=ShowAction.execute
156133
args.input=file_in_memory
157134
args.min_score=0.8
158-
args.model='/workspace/detectron2_repo/densepose_rcnn_R_50_FPN_s1x.pkl'
159135
args.nms_thresh=None
160136
args.output='outputres2.png'
161137
args.verbosity=None
162138
args.visualizations='dp_contour,bbox'
163139
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))
167140
out_binary_buffer = args.func(args)
168141
return out_binary_buffer

apply_net.py

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,31 @@
2727
)
2828
from densepose.vis.extractor import CompoundExtractor, create_extractor
2929

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 = 'cpu'
43+
cfg.freeze()
44+
return cfg
45+
46+
cfg = setup_config()
3247

3348
class Action(object):
3449
pass
3550

3651
class InferenceAction(Action):
3752
@classmethod
3853
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}")
4354
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
4955
file_list = [args.input]
5056
context = cls.create_context(args)
5157
for file_name in file_list:
@@ -57,20 +63,6 @@ def execute(cls: type, args: argparse.Namespace):
5763
cls.postexecute(context)
5864
return out_binary
5965

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 = 'cpu'
71-
cfg.freeze()
72-
return cfg
73-
7466
class ShowAction(InferenceAction):
7567
"""
7668
Show action that visualizes selected entries on an image
@@ -85,18 +77,6 @@ class ShowAction(InferenceAction):
8577
"bbox": ScoredBoundingBoxVisualizer,
8678
}
8779

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-
10080
@classmethod
10181
def execute_on_outputs(
10282
cls: type, context: Dict[str, Any], entry: Dict[str, Any], outputs: Instances
@@ -106,7 +86,6 @@ def execute_on_outputs(
10686
visualizer = context["visualizer"]
10787
extractor = context["extractor"]
10888
image_fpath = entry["file_name"]
109-
logger.info(f"Processing {image_fpath}")
11089
image = cv2.cvtColor(entry["image"], cv2.COLOR_BGR2GRAY)
11190
image = np.tile(image[:, :, np.newaxis], [1, 1, 3])
11291
data = extractor(outputs)
@@ -117,7 +96,6 @@ def execute_on_outputs(
11796
# if len(out_dir) > 0 and not os.path.exists(out_dir):
11897
# os.makedirs(out_dir)
11998
# cv2.imwrite(out_fname, image_vis)
120-
logger.info(f"Output saved to {out_fname}")
12199
context["entry_idx"] += 1
122100
return cv2.imencode('.jpg', image_vis)[1]
123101
@classmethod
@@ -151,18 +129,13 @@ def create_context(cls: type, args: argparse.Namespace) -> Dict[str, Any]:
151129

152130
def main(file_in_memory):
153131
args = argparse.Namespace()
154-
args.cfg='/workspace/detectron2_repo/configs/densepose_rcnn_R_50_FPN_s1x_legacy.yaml'
155132
args.func=ShowAction.execute
156133
args.input=file_in_memory
157134
args.min_score=0.8
158-
args.model='/workspace/detectron2_repo/densepose_rcnn_R_50_FPN_s1x.pkl'
159135
args.nms_thresh=None
160136
args.output='outputres2.png'
161137
args.verbosity=None
162138
args.visualizations='dp_contour,bbox'
163139
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))
167140
out_binary_buffer = args.func(args)
168141
return out_binary_buffer

server-gpu.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import io
88

99
import subprocess
10-
from apply_net-gpu import main as apply_net_main
10+
from apply_net import main as apply_net_main
1111

1212
app = Flask(__name__)
1313

@@ -17,6 +17,7 @@ def setup_cfg(config_file, confidence_threshold = 0.5, is_gpu = False):
1717
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = confidence_threshold
1818
cfg.MODEL.PANOPTIC_FPN.COMBINE.INSTANCES_CONFIDENCE_THRESH = confidence_threshold
1919
cfg.MODEL.DEVICE = 'cpu' if is_gpu == False else 'cuda'
20+
print(cfg.MODEL.DEVICE)
2021
cfg.freeze()
2122
return cfg
2223

server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def setup_cfg(config_file, confidence_threshold = 0.5, is_gpu = False):
1717
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = confidence_threshold
1818
cfg.MODEL.PANOPTIC_FPN.COMBINE.INSTANCES_CONFIDENCE_THRESH = confidence_threshold
1919
cfg.MODEL.DEVICE = 'cpu' if is_gpu == False else 'cuda'
20+
print(cfg.MODEL.DEVICE)
2021
cfg.freeze()
2122
return cfg
2223

@@ -32,6 +33,8 @@ def run_python(method):
3233

3334
if input_file_in_memory is None :
3435
return jsonify({'message': 'invalid file'}), 400
36+
37+
print(input_file_in_memory.shape)
3538
if input_file_in_memory.shape[2] == 4 :
3639
input_file_in_memory = input_file_in_memory[:,:,0:-1]
3740

0 commit comments

Comments
 (0)