HRNet / Lite-HRNet

This is an official pytorch implementation of Lite-HRNet: A Lightweight High-Resolution Network.
Apache License 2.0
819 stars 126 forks source link

I adapted this simple snippet from `tools/test.py` and mmpose api for inference. #56

Open wangm-word opened 3 years ago

wangm-word commented 3 years ago

first,thank you for your Answer,could you give some examples about the 'img_data_with_bbox'?is this a detector model about person?

import matplotlib.pyplot as plt
from mmpose.apis.inference import init_pose_model, inference_top_down_pose_model

model = init_pose_model(config_path, ckpt_path, device=device)

results, heatmaps= inference_top_down_pose_model(model, inputs['image'], img_data_with_bbox, return_heatmap=True, format='xyxy', dataset='TopDownCocoDataset')

## Visualize Results
hms =heatmaps[0]['heatmap']

result = results[0]
keypoints = ([np.array([v[0],v[1]]) for v in result['keypoints']])

#Plot image and keypoints
plt.figure()
plt.scatter(*zip(*keypoints))
plt.imshow(result['image'])
plt.show()

#Plot heatmaps in a grid
n_hms = np.shape(hms)[1]
f, axarr = plt.subplots(3, 4, figsize=(15,15))
this_col=0
for idx in range(n_hms):
    this_hm = hms[0,idx,:,:]
    row = idx % 4
    this_ax = axarr[this_col, row]
    this_ax.set_title(f'{idx}')
    hm_display = this_ax.imshow(this_hm, cmap='jet', vmin=0, vmax=1)
    if row == 3:
        this_col += 1

cb=f.colorbar(hm_display, ax=axarr)

Note that img_data_with_bbox is a list of dicts, where dicts should contain 'bbox' key. For more info checkout the mmpose documentation

If you care about inference speed, you can fuse conv and batch norm layers in the model. See tools/test.py for the code

Originally posted by @kuldeepbrd1 in https://github.com/HRNet/Lite-HRNet/issues/23#issuecomment-841660213