MMCV-Full with openmim
best practice를 따라 mim으로 mmcv-full을 설치함
MMPose with pip (for third party)
verify the installation of mmpose
download config and checkpoint
verify the inference demo
pip을 이용해 third party 용 mmpose를 설치했으므로 demo용 python script 생성
# bottom_up_img_demo.py from mmpose.apis import (init_pose_model, inference_bottom_up_pose_model, vis_pose_result) config_file = 'associative_embedding_hrnet_w32_coco_512x512.py' checkpoint_file = 'hrnet_w32_coco_512x512-bcb8c247_20200816.pth' pose_model = init_pose_model(config_file, checkpoint_file, device='cpu') # or device='cuda:0' image_name = 'demo/persons.jpg' # test a single image pose_results, _ = inference_bottom_up_pose_model(pose_model, image_name) # show the results vis_pose_result(pose_model, image_name, pose_results, out_file='demo/vis_persons.jpg')
download image for test
- 스크립트를 수정하지 않았다면
verify-mmpose/demo/
안에 사람이 포함된persons.jpg
를 추가
- 스크립트를 수정하지 않았다면
run script
결과
persons.jpg(input) | vis_persons.jpg(result) |
Issue (updated 2022.12.28)
[alias expired over ver 1.24] ‘numpy’ has no attribute ‘int’
# ERROR LOG
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/ubuntu/.local/lib/python3.8/site-packages/numpy/__init__.py", line 284, in __getattr__
raise AttributeError("module {!r} has no attribute " AttributeError: module 'numpy' has no attribute 'int'
# Environment
OS Release Ubuntu 20.04.4 LTS
mmcv-full 1.7.0
mmpose 0.29.0
numpy >=1.19.5
최신버전으로 numpy를 설치했는데 demo를 실행하는 과정에서 'numpy' has no attribute 'int'
에러가 발생했다. 공식문서에서 추가하라고 지시한 코드에는 numpy가 없었고, 로그를 살펴보니 이미지의 크기를 정하는 과정에서 int type이 필요했다. 실행한 데모는 bottom_up_transform 이었지만 np.int가 사용된 내역을 살펴보면 bottom_up 뿐 아니라 gesture에서도 사용되는 것 같았다.
# ./datasets/pipelines/gesture_transform.py
# ./datasets/pipelines/bottom_up_transform.py
input_size = np.array([input_size, input_size], dtype=np.int)
stackoverflow 에 의하면 numpy1.20 부터 np.float 또는 np.int의 alias사용이 중단 되었다. np.int_ 로 대체하거나 int로 변환하라는 권고가 나왔는데, 소스코드를 전부 수정할 수 없는 상황이므로 requirements 에 따라 1.19 로 downgrade 하면 해결된다.
NumPy requirements of mmpose:
numpy>=1.19.5
numpy 1.20 relesas note > For np.int a direct replacement with np.int_ or int is also good and will not change behavior, but the precision will continue to depend on the computer and operating system. If you want to be more explicit and review the current use, you have the following alternatives:
numpy 1.24 relesas note > The deprecation for the aliases np.object, np.bool, np.float, np.complex, np.str, and np.int is expired (introduces NumPy 1.20). Some of these will now give a FutureWarning in addition to raising an error since they will be mapped to the NumPy scalars in the future.
MMDetection
- 마찬가지로 mim을 통해 mmcv-full을 설치한다.
- pip으로 mmdet을 설치한다.
Verify installation MMdet
download config and checkpoint
verify the inference demo
pip을 이용해 third party 용 mmdet를 설치했으므로 demo용 python script 생성
# img_demo.py from mmdet.apis import init_detector, inference_detector config_file = 'yolov3_mobilenetv2_320_300e_coco.py' checkpoint_file = 'yolov3_mobilenetv2_320_300e_coco_20210719_215349-d18dff72.pth' model = init_detector(config_file, checkpoint_file, device='cpu') # or device='cuda:0'
여기까지가 공식문서의 demo script인데 이렇게 되면 inference_detector된 결과가 CLI환경에 출력되지 않는다. https://greeksharifa.github.io/references/2021/08/30/MMDetection/#high-level-apis-for-inference 위 포스트를 참고하면 결과 이미지를 확인할 수 있다.
img = 'demo/demo.jpg' inference_detector(model, img) result = inference_detector(model, img) # visualize the results in a new window model.show_result(img, result) # or save the visualization results to image files model.show_result(img, result, out_file='demo/demo_result.jpg') # test a video and show the results video = mmcv.VideoReader('demo/demo.mp4') for frame in video: result = inference_detector(model, frame) model.show_result(frame, result, wait_time=1)
prepare for demo
- mmpose와는 다르게 mmdet에는 demo용 이미지와 동영상이 있으므로 그 파일을 사용하거나 다운로드한다.
run script
bash pwd # /home/devin/env/verify-mmdet python3 demo/img_demo.py
결과
demo.jpg (input) | demo_result.jpg (result) |