aizootech / facemaskdetection Goto Github PK
View Code? Open in Web Editor NEW开源人脸口罩检测模型和数据 Detect faces and determine whether people are wearing mask.
Home Page: https://demo.aizoo.com/face-mask-detection.html
License: MIT License
开源人脸口罩检测模型和数据 Detect faces and determine whether people are wearing mask.
Home Page: https://demo.aizoo.com/face-mask-detection.html
License: MIT License
Thanks for your excellent work! I am using the dataset you provide to train a detection network. While turning the annotations into .json format, I found out that the image 'test_00000306.xml' in the val set has a category named 'face_nask'. I'm sure it's a typo, hope you can correct it. :)
请问会提供train的代码么
Sorry if the question will result "out of topic".
I'm having the following error after having changed the model:
model = load_pytorch_model('models/new_model.pth');
Error:
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
I'm using the pytorch_infer.py file.
How can I specify the map_location=torch.device('cpu') mapping?
I've tried with:
model = load_pytorch_model('models/new_model.pth', map_location=torch.device('cpu') );
but it doesn't work.
Sorry but I'm dealing with python only since a couple of days.
Best regards,
TK
建议只保留一个
Hi, First of all thanks for doing wonderful job.
I am new to this field but want to create for my society with custom images. Please help in training the model and use that for detection
There is a PR curve provided in the readme. Could you also please provide your best precision and recall? Thx
能否提供预训练权重?
Hi, I'm just a novice and I would like to know if you can share the train code (for any model or pytorch) to setup a complete pipeline.
One more question is what are the differences between face_mask_detection and model360 ?
Hi ,
How to run mxnet python on GPU ?
The code running on the cpu
Hi, how can we port it to android?
您好,我想用您的数据集在YOLOV3上做训练一下,尝试一下,当我尝试将xml文件转换为YOLOV3所需要的格式的时候,很多xml文件缺少size
信息(图片大小的信息)。我想问一下,是我下载文件的问题,还是您的数据集本身就没有这个信息
<annotation>
<folder>/home/daniel/Data/Dataset/FaceMaskNew/train_mafa</folder>
<filename>test_00001347.xml</filename>
<object>
<name>face_mask</name>
<difficult>0</difficult>
<bndbox>
<xmin>131</xmin>
<ymin>71</ymin>
<xmax>244</xmax>
<ymax>219</ymax>
</bndbox>
</object>
</annotation>
这是test_00001347.jpg的xml文件
什么
Hey after I cloned the repository and ran python -W pytorch_infer.py --img-path (path to my local image ) I get the following error (-W is to ignore warnings about SourceChangeWarning )
` img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'```
Hi,
Is there mxnet C++ version of the code ?
Best
thx
想用GPU加速检测,现在的速度是0.15s一帧
Hi, I adjust the input size of model to 132*132. The size of feature_map_sizes and anchor_sizes are as follows:
feature_map_sizes = [[17, 17], [9, 9], [5, 5], [3, 3], [1, 1]]
anchor_sizes = [[0.08, 0.11], [0.16, 0.22], [0.32, 0.45], [0.64, 0.72], [1,1]]
anchor_ratios = [[1, 0.62, 0.42]] * 5
In order to improve the speed of the algorithm, have you ever adjusted the input size of model?
请问pytorch和tensorflow是什么版本啊
can you proviod the train code?
windows pycharm连得anaconda的环境
改过的infer.py
import cv2
import time
import os
import argparse
import numpy as np
from PIL import Image
from keras.models import model_from_json
from anchor_generator import generate_anchors
from anchor_decode import decode_bbox
from nms import single_class_non_max_suppression
from playsound import playsound
model = model_from_json(open('models/face_mask_detection.json').read())
model.load_weights('models/face_mask_detection.hdf5')
feature_map_sizes = [[33, 33], [17, 17], [9, 9], [5, 5], [3, 3]]
anchor_sizes = [[0.04, 0.056], [0.08, 0.11], [0.16, 0.22], [0.32, 0.45], [0.64, 0.72]]
anchor_ratios = [[1, 0.62, 0.42]] * 5
anchors = generate_anchors(feature_map_sizes, anchor_sizes, anchor_ratios)
anchors_exp = np.expand_dims(anchors, axis=0)
id2class = {0: 'MASK', 1: 'NOMASK'}
def inference(image,
conf_thresh=0.5,
iou_thresh=0.4,
target_shape=(160, 160),
draw_result=True,
show_result=True
):
'''
Main function of detection inference
:param image: 3D numpy array of image
:param conf_thresh: the min threshold of classification probabity.
:param iou_thresh: the IOU threshold of NMS
:param target_shape: the model input size.
:param draw_result: whether to daw bounding box to the image.
:param show_result: whether to display the image.
:return:
'''
# image = np.copy(image)
output_info = []
height, width, _ = image.shape
image_resized = cv2.resize(image, target_shape)
image_np = image_resized / 255.0 # 归一化到0~1
image_exp = np.expand_dims(image_np, axis=0)
result = model.predict(image_exp)
y_bboxes_output = result[0]
y_cls_output = result[1]
# remove the batch dimension, for batch is always 1 for inference.
y_bboxes = decode_bbox(anchors_exp, y_bboxes_output)[0]
y_cls = y_cls_output[0]
# To speed up, do single class NMS, not multiple classes NMS.
bbox_max_scores = np.max(y_cls, axis=1)
bbox_max_score_classes = np.argmax(y_cls, axis=1)
# keep_idx is the alive bounding box after nms.
keep_idxs = single_class_non_max_suppression(y_bboxes,
bbox_max_scores,
conf_thresh=conf_thresh,
iou_thresh=iou_thresh,
)
for idx in keep_idxs:
conf = float(bbox_max_scores[idx])
class_id = bbox_max_score_classes[idx]
bbox = y_bboxes[idx]
# clip the coordinate, avoid the value exceed the image boundary.
xmin = max(0, int(bbox[0] * width))
ymin = max(0, int(bbox[1] * height))
xmax = min(int(bbox[2] * width), width)
ymax = min(int(bbox[3] * height), height)
if draw_result:
if class_id == 0:
color = (0, 255, 0)
else:
color = (255, 0 , 0)
cv2.rectangle(image, (xmin, ymin), (xmax, ymax), color, 2)
cv2.putText(image, "%s: %.2f" % (id2class[class_id], conf), (xmin + 2, ymin-2),
cv2.FONT_HERSHEY_SIMPLEX, 0.8, color)
output_info.append([class_id, conf, xmin, ymin, xmax, ymax])
if show_result:
Image.fromarray(image).show()
return output_info
def run_on_video(video_path, output_video_name, conf_thresh):
cap = cv2.VideoCapture(video_path)
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
fps = cap.get(cv2.CAP_PROP_FPS)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
writer = cv2.VideoWriter(output_video_name, fourcc, int(fps), (int(width), int(height)))
total_frames = cap.get(cv2.CAP_PROP_FRAME_COUNT)
cv2.imwrite("/saimg" + '.img', cap.read())
if not cap.isOpened():
raise ValueError("Video open failed.")
return
status = True
idx = 0
while status:
start_stamp = time.time()
status, img_raw = cap.read()
cv2.imwrite("/saimg"+'.png', img_raw)
img_raw = cv2.cvtColor(img_raw, cv2.COLOR_BGR2RGB)
read_frame_stamp = time.time()
if (status):
inference(img_raw,
conf_thresh,
iou_thresh=0.5,
target_shape=(260, 260),
draw_result=True,
show_result=False)
cv2.imshow('image', img_raw[:,:,::-1])
cv2.waitKey(1)
inference_stamp = time.time()
writer.write(img_raw)
write_frame_stamp = time.time()
idx += 1
print("%d of %d" % (idx, total_frames))
print("read_frame:%f, infer time:%f, write time:%f" % (read_frame_stamp - start_stamp,
inference_stamp - read_frame_stamp,
write_frame_stamp - inference_stamp))
writer.release()
if name == "main":
parser = argparse.ArgumentParser(description="Face Mask Detection")
parser.add_argument('--img-mode', type=int, default=1, help='set 1 to run on image, 0 to run on video.')
parser.add_argument('--img-path', type=str, help='path to your image.')
parser.add_argument('--video-path', type=str, default='0', help='path to your video, 0
means to use camera.')
# parser.add_argument('--hdf5', type=str, help='keras hdf5 file')
args = parser.parse_args()
if args.img_mode:
imgPath = args.img_path
img = cv2.imread(imgPath)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
inference(img, show_result=True, target_shape=(260, 260))
else:
video_path = args.video_path
if args.video_path == '0':
video_path = 0
run_on_video(video_path, '', conf_thresh=0.5)
错误日志:
(base) C:\Users\xiaomi\PycharmProjects\untitled8\FaceMaskDetection-master>python infer.py --img-mode 0 --video-path 0
Using TensorFlow backend.
WARNING:tensorflow:From C:\Users\xiaomi\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:517: The name tf.p
laceholder is deprecated. Please use tf.compat.v1.placeholder instead.
WARNING:tensorflow:From C:\Users\xiaomi\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:4185: The name tf.
truncated_normal is deprecated. Please use tf.random.truncated_normal instead.
WARNING:tensorflow:From C:\Users\xiaomi\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:245: The name tf.g
et_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.
WARNING:tensorflow:From C:\Users\xiaomi\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:174: The name tf.g
et_default_session is deprecated. Please use tf.compat.v1.get_default_session instead.
WARNING:tensorflow:From C:\Users\xiaomi\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:181: The name tf.C
onfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead.
WARNING:tensorflow:From C:\Users\xiaomi\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:186: The name tf.S
ession is deprecated. Please use tf.compat.v1.Session instead.
2020-03-03 16:44:54.419321: I tensorflow/core/platform/cpu_feature_guard.cc:145] This TensorFlow binary is optimized with
Intel(R) MKL-DNN to use the following CPU instructions in performance critical operations: AVX AVX2
To enable them in non-MKL-DNN operations, rebuild TensorFlow with the appropriate compiler flags.
2020-03-03 16:44:54.434687: I tensorflow/core/common_runtime/process_util.cc:115] Creating new thread pool with default in
ter op setting: 8. Tune using inter_op_parallelism_threads for best performance.
WARNING:tensorflow:From C:\Users\xiaomi\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:190: The name tf.g
lobal_variables is deprecated. Please use tf.compat.v1.global_variables instead.
WARNING:tensorflow:From C:\Users\xiaomi\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:199: The name tf.i
s_variable_initialized is deprecated. Please use tf.compat.v1.is_variable_initialized instead.
WARNING:tensorflow:From C:\Users\xiaomi\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:206: The name tf.v
ariables_initializer is deprecated. Please use tf.compat.v1.variables_initializer instead.
WARNING:tensorflow:From C:\Users\xiaomi\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:1834: The name tf.
nn.fused_batch_norm is deprecated. Please use tf.compat.v1.nn.fused_batch_norm instead.
WARNING:tensorflow:From C:\Users\xiaomi\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:133: The name tf.p
laceholder_with_default is deprecated. Please use tf.compat.v1.placeholder_with_default instead.
WARNING:tensorflow:From C:\Users\xiaomi\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:3976: The name tf.
nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.
WARNING:tensorflow:From C:\Users\xiaomi\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:4138: The name tf.
random_uniform is deprecated. Please use tf.random.uniform instead.
[ERROR:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap.cpp (415) cv::VideoWriter::open VIDEOIO(CV_IMAGE
S): raised OpenCV exception:
OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\videoio\src\cap_images.cpp:207: error: (-215:Assertion failed) !fil
ename.empty() in function 'cv::icvExtractPattern'
Traceback (most recent call last):
File "infer.py", line 159, in
run_on_video(video_path, '', conf_thresh=0.5)
File "infer.py", line 111, in run_on_video
cv2.imwrite("/saimg" + '.img', cap.read())
TypeError: Expected Ptrcv::UMat for argument 'img'
[ WARN:1] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (674) SourceReaderCB::~SourceReaderCB t
erminating async callback
opencv版本:3.4.1
Hello, may I ask if your detection network contains face alignment? Can I do face recognition based on the detection results of your network model
如題,有高手提供source code,感謝!!
I used your code in desktop with CPU and all it is ok.
Now I would test on Jetson Nano with GPU but I have problems.
I am using your pre-trained model for tensorflow.
Can you help me with the problem?
I have to setting something or the problem is the Jetson Nano?
Thanks
在Ubuntu系统下面测试pytorch_infer调用摄像头会遇到下面的报错:
FaceMaskDetection/utils/anchor_decode.py", line 21, in decode_bbox
predict_center_x = raw_outputs_rescale[:, :, 0:1] * anchors_w + anchor_centers_x
ValueError: operands could not be broadcast together with shapes (1,5456,1) (1,11000,1)
尝试导出,发现并未成功
整体bbox的性能很棒, 大角度戴口罩的侧脸也没有出现box变小的情况.
请问下是否做了基于欧拉角的增广? 还是说有什么特殊方法增强了这种情景的表现?
我训出来出现戴口罩大角度的box检测不准
(或者也可能是我自己的模型太轻了? 只有20w的参数量
如题。顺便问一下这个MainModel.py原本是用来干嘛的?我看推理的代码里没有调用这个了。
tflite https://github.com/shaqian/flutter_tflite
return Tflite.loadModel(
model: "assets/model_unquant.tflite",
labels: "assets/labels.txt",
);
也就是labels这个key对应的value为一个标签文本,那么这个文本该如何编写呢?
Hello and good job.
Could be possible have the model compiled for the Google Coral edgetpu?
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv::ipp_cvtColor, file ......\modules\imgproc\src\color.cpp, line 7341
Traceback (most recent call last):
File "tenforflow_infer.py", line 142, in
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
cv2.error: ......\modules\imgproc\src\color.cpp:7341: error: (-215) scn == 3 || scn == 4 in function cv::ipp_cvtColor
I want to use face_mask_detection.tflite port into android.
and there is a question, why label just 2 type [NoMask, Mask], but the dimension of this file are [1, 5972, 4] and [1,5972, 2] ?
使用‘pytorch_infer.py’和在线测试的结果不一样,请问是两者的模型不同吗?
Hi, is it possible to change resolution of video to 640x480px or it is necessary to rebuild the model?
Thanks for support.
请问在keras或者tf2.0上如何将conv和bn进行融合?
是否有代码教程?可以分享一下吗?
非常感谢~
博主有训练好的.h5模型不
非常感谢作者开源的模型和数据,很良心了。请问一下有C/C++调用caffe版模型的示例代码吗?
请问您的训练代码所使用的是tf.keras(tf2)还是keras?
Hello,
First off, great implementation. Thank you for sharing this.
I am wondering if you are planning to provide the tensorflow.js implementation. I converted the model from keras to tensorflow.js, but It seems that the post-processing part should be done in order to print the bboxes and detections of the masks.
Any idea or tip of how should be done?
Thank you in advance
How you have trained model on keras?
how to train model on new data on keras to detect accurately or upload keras training file.
please upload the dataset otherthan baidu. As baidu is blocking non-Chinese users
要用pytorch框架的话直接运行pytorch_infer文件就可以了吗?
我想训练。我如何获取数据集。感谢分享。
我运行python pytorch_infer.py --img-mode 0 --video-path 0
,CPU占用在60%左右。
CPU Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
作者是怎么在网站上放这个程序的,有没有什么大概思路介绍一下
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.