Comments (3)
megaFace raw image seems not available publicly , following code can add the masks , but it may not be totally the same as FaceXZoo's implementation .
import math
import sys, os
import cv2
import yaml
import numpy as np
from tqdm import tqdm
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../")
from core.image_cropper.arcface_cropper.FaceRecImageCropper import FaceRecImageCropper
from core.model_handler.face_alignment.FaceAlignModelHandler import FaceAlignModelHandler
from core.model_handler.face_detection.FaceDetModelHandler import FaceDetModelHandler
from core.model_loader.face_alignment.FaceAlignModelLoader import FaceAlignModelLoader
from core.model_loader.face_detection.FaceDetModelLoader import FaceDetModelLoader
from addition_module.face_mask_adding.FMA3D.face_masker import FaceMasker
def distance2center(x1, y1, x2, y2, image):
im_cx = int(image.shape[1] / 2)
im_cy = int(image.shape[0] / 2)
cx = ((x2 + x1) / 2).astype(int)
cy = ((y2 + y1) / 2).astype(int)
return math.sqrt(math.pow(im_cx - cx, 2) + math.pow(im_cy - cy, 2))
def Filter2centerBox(boundingBoxes, frame):
min_distance = 999999999
min_idx = -1
for i, det in enumerate(boundingBoxes):
distance = distance2center(det[0], det[1], det[2], det[3], frame)
# cv2.rectangle(frame, (int(det[0]), int(det[1])), (int(det[2]), int(det[3])), (2, 255, 0), 1)
# cv2.imshow("x", frame)
# cv2.waitKey(0)
if distance < min_distance:
min_idx = i
min_distance = distance
return np.array([boundingBoxes[min_idx]])
def GetFaceLandMark(image_path):
print("aligning {}".format(image_path))
image = cv2.imread(image_path, cv2.IMREAD_COLOR)
dets = faceDetModelHandler.inference_on_image(image)
dets = Filter2centerBox(dets, image)
assert (len(dets) == 1) # only one face in picture
landmarks = faceAlignModelHandler.inference_on_image(image, dets[0])
return landmarks
input_root = "/home/leo/workspace/data_set/megaface/facescrub_images"
out_root = "/home/leo/workspace/data_set/megaface/facescrub_images_addmasked"
if __name__ == '__main__':
with open('config/model_conf.yaml') as f:
model_conf = yaml.load(f)
model_path = 'models'
# detect init
scene = 'non-mask'
model_category = 'face_detection'
model_name = model_conf[scene][model_category]
faceDetModelLoader = FaceDetModelLoader(model_path, model_category, model_name)
modelDet, cfgDet = faceDetModelLoader.load_model()
faceDetModelHandler = FaceDetModelHandler(modelDet, 'cuda:0', cfgDet)
# alignment init
model_category = 'face_alignment'
model_name = model_conf[scene][model_category]
faceAlignModelLoader = FaceAlignModelLoader(model_path, model_category, model_name)
modelAli, cfgAli = faceAlignModelLoader.load_model()
faceAlignModelHandler = FaceAlignModelHandler(modelAli, 'cuda:0', cfgAli)
# face croper
face_cropper = FaceRecImageCropper()
# face masker
face_masker = FaceMasker(is_aug=True)
template_name = ['0.png', '1.png', '2.png', '3.png', '4.png', '5.png', '6.png', '7.png']
idx = 0
all_pathes = []
for root, dirs, files in os.walk(input_root):
for file in files:
image_path = os.path.join(root, file)
all_pathes.append(image_path)
for image_path in tqdm(all_pathes):
masked_face_path = image_path.replace(input_root, out_root)
if os.path.exists(os.path.dirname(masked_face_path)) is False:
os.makedirs(os.path.dirname(masked_face_path))
lms = GetFaceLandMark(image_path)
face_lms = list(lms.reshape(-1))
face_masker.add_mask_one(image_path, face_lms, template_name[idx % 8], masked_face_path)
idx += 1
from facex-zoo.
Just run 'add_mask_all.py' with the provided 'facescrub2template_name.txt' and 'facescrub_face_info.txt'.
from facex-zoo.
Just run 'add_mask_all.py' with the provided 'facescrub2template_name.txt' and 'facescrub_face_info.txt'.
thanks for reply , and i have tried the method you mentioned , it seems that the origin megaFace face pictures which is not aligned are needed . but the original raw megaface pictures probably are not available in the official website.
any suggestions ?
from facex-zoo.
Related Issues (20)
- 这个是一个pytorch的库吗
- 请问有没有pytorch安装接口?
- add a mask
- [face_sdk] Error when detect and align face-down
- render_cy error
- loading pretrained backbones
- model4 is missing on net disk
- semi-siamese traning error
- semi-siamese training error
- multi-processing
- Questions about DMUE training on different datasets HOT 3
- FileNotFoundError: [Errno 2] No such file or directory: './weights/AffectNet_res18_acc0.6285.pth'
- CASIA-MFSD Dataset
- swin transformer depoly HOT 1
- face_parsing first time inference waits too long
- Training and Testing Image Format - Was the training done on BGR images and testing on RGB?
- face_sdk的face_pipeline里,人脸检测模型已经输出了5个关键点,为什么还要用faceAlignModel再检测关键点?
- DMUE pre-trained models
- 请问,我在lfw测试上效果不好?
- File "logging.conf" has a redundant ']' in line 32
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from facex-zoo.