在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):zllrunning/facetools开源软件地址(OpenSource Url):https://github.com/zllrunning/facetools开源编程语言(OpenSource Language):Python 100.0%开源软件介绍(OpenSource Introduction):facetoolsEasy-to-use face related tools, including face detection, landmark localization, alignment & recognition, based on PyTorch. Quick start
from PIL import Image
from align.detector import detect_faces
from align.visualization_utils import show_results
img = Image.open('imgs/single.jpg') # modify the image path to yours
bounding_boxes, landmarks = detect_faces(img) # detect bboxes and landmarks for all faces in the image
show_results(img, bounding_boxes, landmarks) # visualize the results
from align.face_align import align
res = align('imgs/single.jpg', save_path='./result', vis=False)
res.show()
from PIL import Image
from util.extract_feature import extract_feature
from backbone.model_irse import IR_50
image_1 = Image.open('imgs/align.jpg') # modify the image path to yours
model = IR_50([112, 112])
model_cp = 'checkpoint/backbone_ir50_ms1m_epoch120.pth'
features = extract_feature(image_1, model, model_cp)
print(features.size()) # output : torch.Size([1, 512])
import numpy as np
from PIL import Image
from util.extract_feature import extract_feature
from backbone.model_irse import IR_50
from scipy.spatial.distance import pdist
face_1 = Image.open('imgs/person_1/17.jpg')
face_2 = Image.open('imgs/person_1/18.jpg') # face_1 and face_2 belong to the same one
face_3 = Image.open('imgs/person_2/151.jpg')
face_4 = Image.open('imgs/person_2/152.jpg') # face_3 and face_4 belong to the same one
model = IR_50([112, 112])
model_cp = 'checkpoint/backbone_ir50_ms1m_epoch120.pth'
data = [face_1, face_2, face_3, face_4]
features = extract_feature(data, model, model_cp)
features = [i.numpy() for i in features] # embeddings for face_1, face_2, face_3 and face_4
diff = np.subtract(features[0], features[1])
dist = np.sum(np.square(diff), 1)
print(dist) # output : 1984.6016
diff = np.subtract(features[2], features[3])
dist = np.sum(np.square(diff), 1)
print(dist) # output : 1921.2222
diff = np.subtract(features[0], features[2])
dist = np.sum(np.square(diff), 1)
print(dist) # output : 16876.32
diff = np.subtract(features[1], features[3])
dist = np.sum(np.square(diff), 1)
print(dist) # output : 17107.396
dist = pdist(np.vstack([features[0], features[1]]), 'cosine')
print(dist) # output : 0.12932935
dist = pdist(np.vstack([features[2], features[3]]), 'cosine')
print(dist) # output : 0.11706942
dist = pdist(np.vstack([features[0], features[2]]), 'cosine')
print(dist) # output : 1.09022914
dist = pdist(np.vstack([features[1], features[3]]), 'cosine')
print(dist) # output : 1.07447068
from PIL import Image
from parsing.face_parsing import parsing, vis_parsing_maps
image = Image.open('imgs/9.jpg')
res = parsing(image)
vis_parsing_maps(image, res, show=True, save_im=True) Using facetools in Your ProjectIt is easy to use facetools in your project.
In from facetools import detect_faces, show_results
from PIL import Image
def foo():
img = Image.open('/path/to/your/image')
bounding_boxes, landmarks = detect_faces(img)
show_results(img, bounding_boxes, landmarks) Acknowledgement
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论