Пример #1
0
input_image = ori_image.astype(np.float32) / 255.0
if (model.data_format == "channels_first"):
    input_image = np.transpose(input_image, [2, 0, 1])

img_c, img_h, img_w = input_image.shape
conf_map, paf_map = model.infer(input_image[np.newaxis, :, :, :])

#get visualize function, which is able to get visualized part and limb heatmap image from inferred heatmaps
visualize = Model.get_visualize(Config.MODEL.Openpose)
vis_parts_heatmap, vis_limbs_heatmap = visualize(input_image,
                                                 conf_map[0],
                                                 paf_map[0],
                                                 save_tofile=False)

#get postprocess function, which is able to get humans that contains assembled detected parts from inferred heatmaps
PostProcessor = Model.get_postprocessor(Config.MODEL.Openpose)
postprocessor=PostProcessor(parts=model.parts,limbs=model.limbs,hin=model.hin,\
    win=model.win,out=model.hout,wout=model.wout,colors=model.colors)
humans = postprocessor.process(conf_map[0], paf_map[0])
#draw all detected skeletons
output_img = ori_image.copy()
for human in humans:
    output_img = human.draw_human(output_img)

#if you want to visualize all the images in one plot:
#show image,part heatmap,limb heatmap and detected image
#here we use 'transpose' because our data_format is 'channels_first'
fig = plt.figure(figsize=(8, 8))
#origin image
origin_fig = fig.add_subplot(2, 2, 1)
origin_fig.set_title("origin image")
Пример #2
0
Config.set_model_type(Config.MODEL[args.model_type])
Config.set_dataset_type(Config.DATA[args.dataset_type])
Config.set_model_backbone(Config.BACKBONE[args.model_backbone])
config = Config.get_config()
output_dir = os.path.join(args.output_dir, args.model_name)
os.makedirs(output_dir, exist_ok=True)

# contruct model and processors
model = Model.get_model(config)
# visualizer
VisualizerClass = Model.get_visualizer(config)
visualizer = VisualizerClass(save_dir=output_dir,
                             parts=model.parts,
                             limbs=model.limbs)
# post processor
PostProcessorClass = Model.get_postprocessor(config)
post_processor = PostProcessorClass(parts=model.parts,
                                    limbs=model.limbs,
                                    hin=model.hin,
                                    win=model.win,
                                    hout=model.hout,
                                    wout=model.wout,
                                    colors=model.colors)
# image processor
ImageProcessorClass = Model.get_imageprocessor()
image_processor = ImageProcessorClass(input_h=model.hin, input_w=model.win)

# load weights
model_weight_path = f"./save_dir/{args.model_name}/model_dir/newest_model.npz"
model.load_weights(model_weight_path, format="npz_dict")
model.eval()