forked from open-mmlab/mmpose
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support bottom-up demo (open-mmlab#72)
Co-authored-by: jinsheng <jinsheng@sensetime.com>
- Loading branch information
Showing
11 changed files
with
458 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import os | ||
from argparse import ArgumentParser | ||
|
||
from mmpose.apis import (inference_bottom_up_pose_model, init_pose_model, | ||
vis_pose_result) | ||
|
||
|
||
def main(): | ||
"""Visualize the demo images.""" | ||
parser = ArgumentParser() | ||
parser.add_argument('pose_config', help='Config file for detection') | ||
parser.add_argument('pose_checkpoint', help='Checkpoint file') | ||
parser.add_argument('--img-root', type=str, default='', help='Image root') | ||
parser.add_argument( | ||
'--json-file', | ||
type=str, | ||
default='', | ||
help='Json file containing image info.') | ||
parser.add_argument( | ||
'--show', | ||
action='store_true', | ||
default=False, | ||
help='whether to show img') | ||
parser.add_argument( | ||
'--out-img-root', | ||
type=str, | ||
default='', | ||
help='Root of the output img file. ' | ||
'Default not saving the visualization images.') | ||
parser.add_argument( | ||
'--device', default='cuda:0', help='Device used for inference') | ||
parser.add_argument( | ||
'--kpt-thr', type=float, default=0.3, help='Keypoint score threshold') | ||
|
||
args = parser.parse_args() | ||
|
||
assert args.show or (args.out_img_root != '') | ||
|
||
skeleton = [[16, 14], [14, 12], [17, 15], [15, 13], [12, 13], [6, 12], | ||
[7, 13], [6, 7], [6, 8], [7, 9], [8, 10], [9, 11], [2, 3], | ||
[1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7]] | ||
|
||
from pycocotools.coco import COCO | ||
coco = COCO(args.json_file) | ||
# build the pose model from a config file and a checkpoint file | ||
pose_model = init_pose_model( | ||
args.pose_config, args.pose_checkpoint, device=args.device) | ||
|
||
img_keys = list(coco.imgs.keys()) | ||
|
||
# process each image | ||
for i in range(len(img_keys)): | ||
image_id = img_keys[i] | ||
image = coco.loadImgs(image_id)[0] | ||
image_name = os.path.join(args.img_root, image['file_name']) | ||
|
||
# test a single image, with a list of bboxes. | ||
pose_results = inference_bottom_up_pose_model(pose_model, image_name) | ||
|
||
if args.out_img_root == '': | ||
out_file = None | ||
else: | ||
os.makedirs(args.out_img_root, exist_ok=True) | ||
out_file = os.path.join(args.out_img_root, f'vis_{i}.jpg') | ||
|
||
# show the results | ||
vis_pose_result( | ||
pose_model, | ||
image_name, | ||
pose_results, | ||
skeleton=skeleton, | ||
kpt_score_thr=args.kpt_thr, | ||
show=args.show, | ||
out_file=out_file) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import os | ||
from argparse import ArgumentParser | ||
|
||
import cv2 | ||
|
||
from mmpose.apis import (inference_bottom_up_pose_model, init_pose_model, | ||
vis_pose_result) | ||
|
||
|
||
def main(): | ||
"""Visualize the demo images.""" | ||
parser = ArgumentParser() | ||
parser.add_argument('pose_config', help='Config file for pose') | ||
parser.add_argument('pose_checkpoint', help='Checkpoint file for pose') | ||
parser.add_argument('--video-path', type=str, help='Video path') | ||
parser.add_argument( | ||
'--show', | ||
action='store_true', | ||
default=False, | ||
help='whether to show visualizations.') | ||
parser.add_argument( | ||
'--out-video-root', | ||
default='', | ||
help='Root of the output video file. ' | ||
'Default not saving the visualization video.') | ||
parser.add_argument( | ||
'--device', default='cuda:0', help='Device used for inference') | ||
parser.add_argument( | ||
'--kpt-thr', type=float, default=0.3, help='Keypoint score threshold') | ||
|
||
args = parser.parse_args() | ||
|
||
skeleton = [[16, 14], [14, 12], [17, 15], [15, 13], [12, 13], [6, 12], | ||
[7, 13], [6, 7], [6, 8], [7, 9], [8, 10], [9, 11], [2, 3], | ||
[1, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7]] | ||
|
||
assert args.show or (args.out_video_root != '') | ||
|
||
# build the pose model from a config file and a checkpoint file | ||
pose_model = init_pose_model( | ||
args.pose_config, args.pose_checkpoint, device=args.device) | ||
|
||
cap = cv2.VideoCapture(args.video_path) | ||
|
||
if args.out_video_root == '': | ||
save_out_video = False | ||
else: | ||
os.makedirs(args.out_video_root, exist_ok=True) | ||
save_out_video = True | ||
|
||
if save_out_video: | ||
fps = cap.get(cv2.CAP_PROP_FPS) | ||
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), | ||
int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))) | ||
fourcc = cv2.VideoWriter_fourcc(*'mp4v') | ||
videoWriter = cv2.VideoWriter( | ||
os.path.join(args.out_video_root, | ||
f'vis_{os.path.basename(args.video_path)}'), fourcc, | ||
fps, size) | ||
|
||
while (cap.isOpened()): | ||
flag, img = cap.read() | ||
if not flag: | ||
break | ||
|
||
pose_results = inference_bottom_up_pose_model(pose_model, img) | ||
|
||
# show the results | ||
vis_img = vis_pose_result( | ||
pose_model, | ||
img, | ||
pose_results, | ||
skeleton=skeleton, | ||
kpt_score_thr=args.kpt_thr, | ||
show=False) | ||
|
||
if args.show: | ||
cv2.imshow('Image', vis_img) | ||
|
||
if save_out_video: | ||
videoWriter.write(vis_img) | ||
|
||
if cv2.waitKey(1) & 0xFF == ord('q'): | ||
break | ||
|
||
cap.release() | ||
if save_out_video: | ||
videoWriter.release() | ||
cv2.destroyAllWindows() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
from .inference import inference_pose_model, init_pose_model, vis_pose_result | ||
from .inference import (inference_bottom_up_pose_model, | ||
inference_top_down_pose_model, init_pose_model, | ||
vis_pose_result) | ||
from .test import multi_gpu_test, single_gpu_test | ||
from .train import train_model | ||
|
||
__all__ = [ | ||
'train_model', 'init_pose_model', 'inference_pose_model', 'multi_gpu_test', | ||
'single_gpu_test', 'vis_pose_result' | ||
'train_model', 'init_pose_model', 'inference_top_down_pose_model', | ||
'inference_bottom_up_pose_model', 'multi_gpu_test', 'single_gpu_test', | ||
'vis_pose_result' | ||
] |
Oops, something went wrong.