pip install decorator sympy
安装openmmlab算法库mmcls
pip install mmcls
使用mim 下载mmcls中的resnet50的模型和ckpt
mim download mmcls --config resnet50_8xb32_in1k --dest .
运行结果
Successfully downloaded resnet50_8xb32_in1k_20210831-ea4938fc.pth to /home/HwHiA
Successfully dumped resnet50_8xb32_in1k.py to /home/HwHiAiUser/tools/mmdeploy
模型转换
python tools/deploy.py configs/mmcls/classification_ascend_static-224x224.py resnet50_8xb32_in1k.py resnet50_8xb32_in1k_20210831-ea4938fc.pth tests/data/tiger.jpeg --work-dir mmdeploy_models/mmcls/resnet50/cann --device cpu --dump-info
import cv2
from mmdeploy_python import Classifier
# create a classifer
classifier = Classifier(model_path="mmdeploy_models/mmcls/resnet50/cann",device_name='cpu',device_id=0)
#read an image
img = cv2.imread("tests/data/tiger.jpeg')
#person inference
result = classifier(img)
#show result
for label_id, score in result:
print(label_id,score)
运行结果:
292 0.91845703125
282 0.07904052734375
281 0.00037169456481933594
290 0.00032806396484375
243 0.0001347064971923828
安装openmmlab 算法库mmdet
pip install mmdet
使用mim下载mmdet中的RetinaNet模型和ckpt
mim download mmdet --config retinanet_r50_fpn_1x_coco --dest .
运行结果
Successfully downloaded retinanet_r50_fpn_1x_coco_20200130-c2398f9e.pth to /home/HwHiAiUser/tools/mmdeploy
Successfully dumped retinanet_r50_fpn_1x_coco.py to /home/HwHiAiUser/tools/mmdeploy
模型转换命令
python tools/deploy.py configs/mmdet/detection/detection_ascend_static-800x1344.py retinanet_r50_fpn_1x_coco.py retinanet_r50_fpn_1x_coco_20200130-c2398f9e.pth demo/resources/det.jpg --work-dir mmdeploy_models/mmdet/retinanet/cann --device cpu --dump-info
import cv2
from mmdeploy_python import Detector
#create a detector
detector = Detector(
model_path = 'mmdeploy_models/mmdet/retinanet/cann',
device_name='cpu',
device_id=0)
#read an image
img = cv2.imread('demo/resources/det.jpg')
#perform inference
bboxes, labels, _ = detector(img)
#visualize result
for index, (bbox, label_id) in enumerate(zip(bboxes,labels)):
[left, top, right, bottom],score = bbox[0:4].astype(int),bbox[4]
if score < 0.3:
continue
cv2.rectangle(img, (left,top),(right,bottom),(0,255,0))
cv2.imwrite('output_detection.png',img)
运行脚本
python det_retinanet.py