• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

zllrunning/facetools: Easy-to-use face related tools, including face detection, ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

zllrunning/facetools

开源软件地址(OpenSource Url):

https://github.com/zllrunning/facetools

开源编程语言(OpenSource Language):

Python 100.0%

开源软件介绍(OpenSource Introduction):

facetools

Easy-to-use face related tools, including face detection, landmark localization, alignment & recognition, based on PyTorch.

Quick start

  • Do face detection and landmark localization using MTCNN
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

  • Do alignment
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])
  • Calculate the distance between two images
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
  • Do face parsing
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 Project

It is easy to use facetools in your project.

Your project
│   README.md
│   ...
│   foo.py
│
└───facetools
│
└───directory1
│   
└───...

In foo.py, you can easily import facetools by adding:

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




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap