当前位置:网站首页>戴口罩人臉數據集和戴口罩人臉生成方法
戴口罩人臉數據集和戴口罩人臉生成方法
2022-06-29 00:38:00 【pan_jinquan】
戴口罩人臉數據集和戴口罩人臉生成方法
目錄
4. 戴口罩人臉檢測和戴口罩識別(含Python Android源碼)
目前網上已經開源了很多免費的人臉識別/人臉檢測數據集,比如常見的LFW,FDDB,WIDER FACE,300W等,估計加起來都有好幾個憶了。但這些人臉數據絕大部分都是不戴口罩的人臉,不能直接用於戴口罩識別中。網上也有少許開源的戴口罩人臉數據集,鄙人花了點時間,整理一下目前常見的戴口罩人臉數據集,以及戴口罩人臉數據的合成/生成方法。
- 包含5個數據集: facemask-train1, facemask-train2,facemask-train3, synthetic-train1,synthetic-train2 ,facemask-test ,總共約有50000+的數據:
- 生成戴口罩人臉代碼: python create_facemask.py
項目數據和生成戴口罩人臉源碼下載地址:戴口罩人臉數據集和生成戴口罩人臉數據
1.戴口罩人臉數據集
(1)開源數據集-戴口罩人臉數據集
一些開源的,免費的戴口罩人臉數據集,download下來,發現這些開源的數據比較髒,有挺多也是標注錯誤的,需求自己清洗一下哦~
| 數據集 | 說明 |
| virus-mask-dataset |
|
| MaskedFace-Net |
|
| Real-World Masked Face Datase |
(2)生成戴口罩人臉的數據集
網上絕大部分人臉數據都是不戴口罩的人臉,不能直接用於戴口罩識別中。鑒於此,我們可以考慮自己合成/生成戴口罩的人臉數據,以下是鄙人收藏和整理的戴口罩人臉數據集和合成的數據集,總共約有50000+的數據:
| 數據集 | 說明 |
| facemask-train1 |
|
| facemask-train2 |
|
| facemask-train3 |
|
| synthetic-train1 |
|
| synthetic-train2 |
|
| facemask-test |
|
2.戴口罩人臉生成方法
(1)生成戴口罩人臉思路
- 首先進行人臉檢測和人臉關鍵點檢測
- 根據人臉關鍵點,計算臉頰的寬度和鼻梁比特置等比特置信息,同理,需要計算出口罩模板的大小、方向和比特置;
- 最後把口罩模板貼在人臉比特置上,等到合成的戴口罩人臉圖片
一些戴口罩生成代碼參考:
GitHub - sevenHsu/FaceMask_CelebA: Simulated masked face with dataset CelebA
給人臉戴上口罩,Python實戰項目來了_我愛Python數據挖掘的博客-CSDN博客
我測試了目前網上的生成戴口罩代碼,對於已經矯正的人臉,生成效果還是不錯的,但如果原始人臉本身就是傾斜(歪頭),這時直接使用原始代碼,合成的效果就很差了,在此基礎上,我做了優化工作:
- 增加了口罩模板,共有29種不同類型的口罩模板,提供合成口罩數據的多樣性
- 優化了口罩傾斜角度,使得人臉傾斜(歪頭)時,合成的效果也不錯
- 優化了人臉檢測,采用輕量化人臉檢測,加速生成速度
| 原始圖片 | 原始代碼生成戴口罩 | 優化後生成戴口罩 |
![]() | ![]() | ![]() |
| 對於已經矯正的人臉,生成效果還是不錯的,但如果原始人臉本身就是傾斜(歪頭),這時直接使用原始代碼,合成的效果就很差了 | ||
(2)口罩模板
口罩模板即口罩Mask圖像(PNG格式),可以通過Photoshop摳圖的方式,把背景去除;目前已經提供了共有29種不同類型的口罩模板,保證了口罩數據的多樣性。


(3)戴口罩人臉生成Demo
安裝好python相關依賴包
pybaseutils
opencv-python==4.5.1.48
face_recognition
tqdm
torch
torchvision代碼已經自帶了測試圖片和數據,你也可以更換成自己的人臉數據集:
python create_facemask.py# -*-coding: utf-8 -*-
"""
@Author : panjq
@E-mail : [email protected]
@Date : 2022-06-25 22:23:11
@Brief : 生成戴口罩人臉數據集
"""
import os
import sys
sys.path.insert(0, os.getcwd())
sys.path.insert(0, "libs")
from tqdm import tqdm
from facemask.wearmask import FaceMaskCreator
from pybaseutils import file_utils, image_utils
class FaceMaskDemo(object):
def __init__(self):
self.mask_creator = FaceMaskCreator(detect_face=True, alignment=False)
def create_wear_mask_faces(self, image_dir, out_dir=None, vis=True):
"""
生成戴口罩人臉數據集
:param image_dir: 人臉圖片目錄
:param out_dir: 生成戴口罩人臉輸出目錄
:param vis: 是否可視化效果
:return:
"""
image_list = file_utils.get_files_lists(image_dir)
for image_path in tqdm(image_list):
image_id = os.path.basename(image_path).split(".")[0]
image = image_utils.read_image(image_path, size=(512, None), use_rgb=True)
mask, face_rects = self.mask_creator.create_masks(image, mask_type="random", vis=vis)
if out_dir:
self.mask_creator.save_image(image, mask, face_rects, out_dir, image_id)
if __name__ == '__main__':
image_dir = "./facemask/test_image" # 人臉圖片
out_dir = "./output" # 生成戴口罩人臉輸出目錄
fm = FaceMaskDemo()
fm.create_wear_mask_faces(image_dir, out_dir, vis=True)
(4)生成戴口罩人臉效果展示
| 原圖 | 合成帶口罩圖 |
![]() | ![]() |
![]() | ![]() |
![]() | ![]() |
![]() | ![]() |
3. 生成戴口罩數據集和源碼下載
下載地址包含內容有:
https://mp.weixin.qq.com/s/4dtC9CeP50M-3nn3xel1Ow
- 包含5個數據集: facemask-train1, facemask-train2,facemask-train3, synthetic-train1,synthetic-train2 ,facemask-test ,總共約有50000+的數據:
- 生成戴口罩人臉代碼: python create_facemask.py

4. 戴口罩人臉檢測和戴口罩識別(含Python Android源碼)
准備好人臉數據集和戴口罩人臉數據集,下一步就可以開始訓練戴口罩識別模型,請參考:
边栏推荐
- 大型网站架构基础之笔记
- Basic use of Chrome browser
- Summary of the 25-year-old Ma Nong who graduated three years ago
- 每日一题:数组中数字出现的次数2
- 搭建单机 nacos 负载均衡ribbon 轮询策略 权重2种方式
- Along with the notes: methods simulating array like classes
- LG. Hankson's interesting questions, C language
- [Gym 102423]-Elven Efficiency | 思维
- JVM工作原理介绍
- 光纤滑环价格过高的原因
猜你喜欢

How to calculate the income tax of foreign-funded enterprises

Haskell configuring vs code development environment (june2022)

运营级智慧校园系统源码 智慧校园小程序源码+电子班牌+人脸识别系统

Along with the notes: methods simulating array like classes

10. Yolo series

每日一题:消失的数字

Baidu online disk login verification prompt: unable to access this page, or the QR code display fails, the pop-up window shows: unable to access this page, ensure the web address....

Structure of the actual combat battalion | module 5

Typescript -- Section 3: Interface

This thing is called a jump watch?
随机推荐
每日一题:数组中数字出现的次数2
The magical zero knowledge proof can not only keep secrets, but also make others believe you!
[image denoising] matlab code for removing salt and pepper noise based on fast and effective multistage selective convolution filter
大智慧上开户是安全的吗
旋轉接頭安裝使用注意事項
UI高度自适应的修改方案
The company has a new Post-00 test paper king. The old oilman said that he could not do it. He has been
Excel使用过程中的参考资料
【LeetCode】21. Merge two ordered linked lists - go language solution
Reasons for high price of optical fiber slip ring
Summary of the 25-year-old Ma Nong who graduated three years ago
Difference between applying for trademark in the name of individual and company
JVM工作原理介绍
Is it safe to open an account on the flush
Xiaobai's e-commerce business is very important to choose the right mall system!
FATAL ERROR: Could not find ./ bin/my_ print_ Solutions to defaults
卷绕工艺与叠片工艺的对比
手下两个应届生:一个踏实喜欢加班,一个技术强挑活,怎么选??
Daily practice: delete duplicates in the ordered array
ES6:let、const、箭头函数











https://panjinquan.blog.csdn.net/article/details/125428609