'update-mnn'
Showing
2 changed files
with
8 additions
and
7 deletions
No preview for this file type
| ... | @@ -3,9 +3,10 @@ import numpy as np | ... | @@ -3,9 +3,10 @@ import numpy as np |
| 3 | import MNN | 3 | import MNN |
| 4 | import os | 4 | import os |
| 5 | 5 | ||
| 6 | |||
| 6 | def image_infer_mnn(mnn_model_path, image_path, class_list): | 7 | def image_infer_mnn(mnn_model_path, image_path, class_list): |
| 7 | image = cv2.imread(image_path) | 8 | image = cv2.imread(image_path) |
| 8 | input_image = cv2.resize(image,(128,128)) | 9 | input_image = cv2.resize(image, (128, 128)) |
| 9 | input_data = input_image.astype(np.float32).transpose((2, 0, 1)) / 255 | 10 | input_data = input_image.astype(np.float32).transpose((2, 0, 1)) / 255 |
| 10 | interpreter = MNN.Interpreter(mnn_model_path) | 11 | interpreter = MNN.Interpreter(mnn_model_path) |
| 11 | session = interpreter.createSession() | 12 | session = interpreter.createSession() |
| ... | @@ -17,7 +18,7 @@ def image_infer_mnn(mnn_model_path, image_path, class_list): | ... | @@ -17,7 +18,7 @@ def image_infer_mnn(mnn_model_path, image_path, class_list): |
| 17 | output_data = infer_result.getData() | 18 | output_data = infer_result.getData() |
| 18 | out = output_data.index(max(output_data)) | 19 | out = output_data.index(max(output_data)) |
| 19 | 20 | ||
| 20 | cv2.putText(image,class_list[int(out)],(50, 50),cv2.FONT_HERSHEY_SIMPLEX,2,(0,0,255)) | 21 | cv2.putText(image, class_list[int(out)], (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255)) |
| 21 | return image | 22 | return image |
| 22 | 23 | ||
| 23 | 24 | ||
| ... | @@ -74,10 +75,10 @@ if __name__ == '__main__': | ... | @@ -74,10 +75,10 @@ if __name__ == '__main__': |
| 74 | image_path = 'test_image/mask_2997.jpg' | 75 | image_path = 'test_image/mask_2997.jpg' |
| 75 | mnn_model_path = 'cls_abnormal_face_mnn_1.0.0_v0.0.1.mnn' | 76 | mnn_model_path = 'cls_abnormal_face_mnn_1.0.0_v0.0.1.mnn' |
| 76 | # image | 77 | # image |
| 77 | # for i in os.listdir('test_image'): | 78 | for i in os.listdir('test_image'): |
| 78 | # image=image_infer_mnn(mnn_model_path,os.path.join('test_image',i),class_list) | 79 | image=image_infer_mnn(mnn_model_path,os.path.join('test_image',i),class_list) |
| 79 | # cv2.imshow('image',image) | 80 | cv2.imshow('image',image) |
| 80 | # cv2.waitKey(0) | 81 | cv2.waitKey(0) |
| 81 | 82 | ||
| 82 | # camera | 83 | # camera |
| 83 | camera_infer_mnn(mnn_model_path, 0) | 84 | # camera_infer_mnn(mnn_model_path, 0) | ... | ... |
-
Please register or sign in to post a comment