Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
affective_computing
/
face_mask_classifier
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
b8d9812e
authored
2022-02-09 14:12:21 +0800
by
乔峰昇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
mnn
1 parent
386478a4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
38 deletions
.idea/workspace.xml
mobilenet_v2.mnn → cls_abnormal_face_mnn_1.0.0_v0.0.1.mnn
mobilenet_v2.onnx → cls_abnormal_face_onnx_1.0.0_v0.0.1.onnx
infer_mnn.py
.idea/workspace.xml
View file @
b8d9812
...
...
@@ -2,29 +2,34 @@
<project
version=
"4"
>
<component
name=
"ChangeListManager"
>
<list
default=
"true"
id=
"8255f694-c607-4431-a530-39f2e0df4506"
name=
"Default Changelist"
comment=
""
>
<change
beforePath=
"$PROJECT_DIR$/.idea/.gitignore"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/.idea/face_mask_classifier.iml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/.idea/face_mask_classifier.iml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/.idea/misc.xml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/.idea/misc.xml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/dataset.py"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/image/img.png"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/image/img_1.png"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/infer.py"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/infer.py"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/net.py"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/params/cls_face_mobilenet_v2.pth"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/test.py"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/train.py"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/train.py"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/utils.py"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/.idea/workspace.xml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/.idea/workspace.xml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/infer_mnn.py"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/infer_mnn.py"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/mobilenet_v2.mnn"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/cls_abnormal_face_mnn_1.0.0_v0.0.1.mnn"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/mobilenet_v2.onnx"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/cls_abnormal_face_onnx_1.0.0_v0.0.1.onnx"
afterDir=
"false"
/>
</list>
<option
name=
"SHOW_DIALOG"
value=
"false"
/>
<option
name=
"HIGHLIGHT_CONFLICTS"
value=
"true"
/>
<option
name=
"HIGHLIGHT_NON_ACTIVE_CHANGELIST"
value=
"false"
/>
<option
name=
"LAST_RESOLUTION"
value=
"IGNORE"
/>
</component>
<component
name=
"FileTemplateManagerImpl"
>
<option
name=
"RECENT_TEMPLATES"
>
<list>
<option
value=
"Python Script"
/>
</list>
</option>
</component>
<component
name=
"Git.Settings"
>
<option
name=
"RECENT_GIT_ROOT_PATH"
value=
"$PROJECT_DIR$"
/>
</component>
<component
name=
"GitSEFilterConfiguration"
>
<file-type-list>
<filtered-out-file-type
name=
"LOCAL_BRANCH"
/>
<filtered-out-file-type
name=
"REMOTE_BRANCH"
/>
<filtered-out-file-type
name=
"TAG"
/>
<filtered-out-file-type
name=
"COMMIT_BY_MESSAGE"
/>
</file-type-list>
</component>
<component
name=
"ProjectId"
id=
"24r53vDpNxHFy2XFaKewyUFOSTL"
/>
<component
name=
"ProjectViewState"
>
<option
name=
"hideEmptyMiddlePackages"
value=
"true"
/>
...
...
@@ -34,10 +39,52 @@
<component
name=
"PropertiesComponent"
>
<property
name=
"RunOnceActivity.OpenProjectViewOnStart"
value=
"true"
/>
<property
name=
"RunOnceActivity.ShowReadmeOnStart"
value=
"true"
/>
<property
name=
"last_opened_file_path"
value=
"$PROJECT_DIR$"
/>
<property
name=
"last_opened_file_path"
value=
"$PROJECT_DIR$
/../Pytorch-Image-Classifier-Collection
"
/>
<property
name=
"settings.editor.selected.configurable"
value=
"com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable"
/>
</component>
<component
name=
"RunManager"
>
<component
name=
"RunManager"
selected=
"Python.infer_mnn"
>
<configuration
name=
"cc"
type=
"PythonConfigurationType"
factoryName=
"Python"
temporary=
"true"
nameIsGenerated=
"true"
>
<module
name=
"face_mask_classifier"
/>
<option
name=
"INTERPRETER_OPTIONS"
value=
""
/>
<option
name=
"PARENT_ENVS"
value=
"true"
/>
<envs>
<env
name=
"PYTHONUNBUFFERED"
value=
"1"
/>
</envs>
<option
name=
"SDK_HOME"
value=
""
/>
<option
name=
"WORKING_DIRECTORY"
value=
"$PROJECT_DIR$"
/>
<option
name=
"IS_MODULE_SDK"
value=
"true"
/>
<option
name=
"ADD_CONTENT_ROOTS"
value=
"true"
/>
<option
name=
"ADD_SOURCE_ROOTS"
value=
"true"
/>
<option
name=
"SCRIPT_NAME"
value=
"$PROJECT_DIR$/cc.py"
/>
<option
name=
"PARAMETERS"
value=
""
/>
<option
name=
"SHOW_COMMAND_LINE"
value=
"false"
/>
<option
name=
"EMULATE_TERMINAL"
value=
"false"
/>
<option
name=
"MODULE_MODE"
value=
"false"
/>
<option
name=
"REDIRECT_INPUT"
value=
"false"
/>
<option
name=
"INPUT_FILE"
value=
""
/>
<method
v=
"2"
/>
</configuration>
<configuration
name=
"ddd"
type=
"PythonConfigurationType"
factoryName=
"Python"
temporary=
"true"
nameIsGenerated=
"true"
>
<module
name=
"face_mask_classifier"
/>
<option
name=
"INTERPRETER_OPTIONS"
value=
""
/>
<option
name=
"PARENT_ENVS"
value=
"true"
/>
<envs>
<env
name=
"PYTHONUNBUFFERED"
value=
"1"
/>
</envs>
<option
name=
"SDK_HOME"
value=
""
/>
<option
name=
"WORKING_DIRECTORY"
value=
"$PROJECT_DIR$"
/>
<option
name=
"IS_MODULE_SDK"
value=
"true"
/>
<option
name=
"ADD_CONTENT_ROOTS"
value=
"true"
/>
<option
name=
"ADD_SOURCE_ROOTS"
value=
"true"
/>
<option
name=
"SCRIPT_NAME"
value=
"$PROJECT_DIR$/ddd.py"
/>
<option
name=
"PARAMETERS"
value=
""
/>
<option
name=
"SHOW_COMMAND_LINE"
value=
"false"
/>
<option
name=
"EMULATE_TERMINAL"
value=
"false"
/>
<option
name=
"MODULE_MODE"
value=
"false"
/>
<option
name=
"REDIRECT_INPUT"
value=
"false"
/>
<option
name=
"INPUT_FILE"
value=
""
/>
<method
v=
"2"
/>
</configuration>
<configuration
name=
"infer_mnn"
type=
"PythonConfigurationType"
factoryName=
"Python"
temporary=
"true"
nameIsGenerated=
"true"
>
<module
name=
"face_mask_classifier"
/>
<option
name=
"INTERPRETER_OPTIONS"
value=
""
/>
...
...
@@ -53,15 +100,22 @@
<option
name=
"SCRIPT_NAME"
value=
"$PROJECT_DIR$/infer_mnn.py"
/>
<option
name=
"PARAMETERS"
value=
""
/>
<option
name=
"SHOW_COMMAND_LINE"
value=
"false"
/>
<option
name=
"EMULATE_TERMINAL"
value=
"
fals
e"
/>
<option
name=
"EMULATE_TERMINAL"
value=
"
tru
e"
/>
<option
name=
"MODULE_MODE"
value=
"false"
/>
<option
name=
"REDIRECT_INPUT"
value=
"false"
/>
<option
name=
"INPUT_FILE"
value=
""
/>
<method
v=
"2"
/>
</configuration>
<list>
<item
itemvalue=
"Python.cc"
/>
<item
itemvalue=
"Python.ddd"
/>
<item
itemvalue=
"Python.infer_mnn"
/>
</list>
<recent_temporary>
<list>
<item
itemvalue=
"Python.infer_mnn"
/>
<item
itemvalue=
"Python.ddd"
/>
<item
itemvalue=
"Python.cc"
/>
</list>
</recent_temporary>
</component>
...
...
mobilenet_v2
.mnn
→
cls_abnormal_face_mnn_1.0.0_v0.0.1
.mnn
View file @
b8d9812
No preview for this file type
mobilenet_v2
.onnx
→
cls_abnormal_face_onnx_1.0.0_v0.0.1
.onnx
View file @
b8d9812
No preview for this file type
infer_mnn.py
View file @
b8d9812
import
os
import
cv2
from
PIL
import
Image
,
ImageFont
,
ImageDraw
import
torch
from
torchvision
import
transforms
import
MNN
import
numpy
as
np
def
keep_shape_resize
(
frame
,
size
=
128
):
...
...
@@ -24,12 +20,10 @@ def keep_shape_resize(frame, size=128):
def
image_infer_mnn
(
mnn_model_path
,
image_path
,
class_list
):
image
=
Image
.
open
(
image_path
)
input_image
=
keep_shape_resize
(
image
)
preprocess
=
transforms
.
Compose
([
transforms
.
ToTensor
()])
input_data
=
preprocess
(
input_image
)
input_data
=
np
.
array
(
input_image
)
.
astype
(
np
.
float32
)
.
transpose
((
2
,
0
,
1
))
/
255
interpreter
=
MNN
.
Interpreter
(
mnn_model_path
)
session
=
interpreter
.
createSession
()
input_tensor
=
interpreter
.
getSessionInput
(
session
)
input_data
=
input_data
.
cpu
()
.
numpy
()
.
squeeze
()
tmp_input
=
MNN
.
Tensor
((
1
,
3
,
128
,
128
),
MNN
.
Halide_Type_Float
,
input_data
,
MNN
.
Tensor_DimensionType_Caffe
)
input_tensor
.
copyFrom
(
tmp_input
)
interpreter
.
runSession
(
session
)
...
...
@@ -53,9 +47,7 @@ def video_infer_mnn(mnn_model_path, video_path):
image_data
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2RGB
)
image_data
=
Image
.
fromarray
(
image_data
)
image_data
=
keep_shape_resize
(
image_data
,
128
)
preprocess
=
transforms
.
Compose
([
transforms
.
ToTensor
()])
input_data
=
preprocess
(
image_data
)
input_data
=
input_data
.
cpu
()
.
numpy
()
.
squeeze
()
input_data
=
np
.
array
(
image_data
)
.
astype
(
np
.
float32
)
.
transpose
((
2
,
0
,
1
))
/
255
tmp_input
=
MNN
.
Tensor
((
1
,
3
,
128
,
128
),
MNN
.
Halide_Type_Float
,
input_data
,
MNN
.
Tensor_DimensionType_Caffe
)
input_tensor
.
copyFrom
(
tmp_input
)
interpreter
.
runSession
(
session
)
...
...
@@ -81,9 +73,7 @@ def camera_infer_mnn(mnn_model_path, camera_id):
image_data
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2RGB
)
image_data
=
Image
.
fromarray
(
image_data
)
image_data
=
keep_shape_resize
(
image_data
,
128
)
preprocess
=
transforms
.
Compose
([
transforms
.
ToTensor
()])
input_data
=
preprocess
(
image_data
)
input_data
=
input_data
.
cpu
()
.
numpy
()
.
squeeze
()
input_data
=
np
.
array
(
image_data
)
.
astype
(
np
.
float32
)
.
transpose
((
2
,
0
,
1
))
/
255
tmp_input
=
MNN
.
Tensor
((
1
,
3
,
128
,
128
),
MNN
.
Halide_Type_Float
,
input_data
,
MNN
.
Tensor_DimensionType_Caffe
)
input_tensor
.
copyFrom
(
tmp_input
)
interpreter
.
runSession
(
session
)
...
...
@@ -98,14 +88,12 @@ def camera_infer_mnn(mnn_model_path, camera_id):
break
if
__name__
==
'__main__'
:
class_list
=
[
'mask'
,
'no_mask'
]
image_path
=
'test_image/mask_299
7
.jpg'
mnn_model_path
=
'
mobilenet_v2
.mnn'
image_path
=
'test_image/mask_299
5
.jpg'
mnn_model_path
=
'
cls_abnormal_face_mnn_1.0.0_v0.0.1
.mnn'
# image
# image=image_infer_mnn(mnn_model_path,image_path,class_list)
# image.show()
image
=
image_infer_mnn
(
mnn_model_path
,
image_path
,
class_list
)
image
.
show
()
# camera
camera_infer_mnn
(
mnn_model_path
,
0
)
# camera_infer_mnn(mnn_model_path,
0)
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment