在看官方教程时,无意中发现别人写的一个脚本,非常简洁。

官方教程地址:http://pytorch.org/tutorials/beginner/data_loading_tutorial.html#sphx-glr-beginner-data-loading-tutorial-py

使用的是dlib自带的特征点检测库,初期用来测试还是不错的

 """Create a sample face landmarks dataset.

 Adapted from dlib/python_examples/face_landmark_detection.py
See this file for more explanation. Download a trained facial shape predictor from:
http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
"""
import dlib
import glob
import csv
from skimage import io detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
num_landmarks = 68 with open('face_landmarks.csv', 'w', newline='') as csvfile:
csv_writer = csv.writer(csvfile) header = ['image_name']
for i in range(num_landmarks):
header += ['part_{}_x'.format(i), 'part_{}_y'.format(i)] csv_writer.writerow(header) for f in glob.glob('*.jpg'):
img = io.imread(f)
dets = detector(img, 1) # face detection # ignore all the files with no or more than one faces detected.
if len(dets) == 1:
row = [f] d = dets[0]
# Get the landmarks/parts for the face in box d.
shape = predictor(img, d)
for i in range(num_landmarks):
part_i_x = shape.part(i).x
part_i_y = shape.part(i).y
row += [part_i_x, part_i_y] csv_writer.writerow(row)

附上使用matplotlib显示特征点的脚本:

 from __future__ import print_function, division
import os
import torch
import pandas as pd
from skimage import io, transform
import numpy as np
import matplotlib.pyplot as plt
from torch.utils.data import Dataset, DataLoader
from torchvision import transforms, utils # Ignore warnings
import warnings
warnings.filterwarnings("ignore") plt.ion() # interactive mode landmarks_frame = pd.read_csv('faces/face_landmarks.csv') n = 5
img_name = landmarks_frame.iloc[n, 0]
landmarks = landmarks_frame.iloc[n, 1:].as_matrix()
landmarks = landmarks.astype('float').reshape(-1, 2) print('Image name: {}'.format(img_name))
print('Landmarks shape: {}'.format(landmarks.shape))
print('First 4 Landmarks: {}'.format(landmarks[:4])) def show_landmarks(image, landmarks):
"""Show image with landmarks"""
plt.imshow(image)
plt.scatter(landmarks[:, 0], landmarks[:, 1], s=10, marker='.', c='r')
plt.pause(0.001) # pause a bit so that plots are updated plt.figure()
show_landmarks(io.imread(os.path.join('faces/', img_name)),
landmarks)
plt.show()

效果图:

深度学习(PYTORCH)-2.python调用dlib提取人脸68个特征点的更多相关文章

  1. Python 3 利用 Dlib 实现人脸 68个 特征点的标定

    0. 引言 利用 Dlib 官方训练好的模型 “shape_predictor_68_face_landmarks.dat” 进行 68 个点标定: 利用 OpenCv 进行图像化处理,在人脸上画出 ...

  2. MINIST深度学习识别:python全连接神经网络和pytorch LeNet CNN网络训练实现及比较(三)

    版权声明:本文为博主原创文章,欢迎转载,并请注明出处.联系方式:460356155@qq.com 在前两篇文章MINIST深度学习识别:python全连接神经网络和pytorch LeNet CNN网 ...

  3. [深度学习工具]·极简安装Dlib人脸识别库

    [深度学习工具]·极简安装Dlib人脸识别库 Dlib介绍 Dlib是一个现代化的C ++工具箱,其中包含用于在C ++中创建复杂软件以解决实际问题的机器学习算法和工具.它广泛应用于工业界和学术界,包 ...

  4. 深度学习 + OpenCV,Python实现实时视频目标检测

    使用 OpenCV 和 Python 对实时视频流进行深度学习目标检测是非常简单的,我们只需要组合一些合适的代码,接入实时视频,随后加入原有的目标检测功能. 在本文中我们将学习如何扩展原有的目标检测项 ...

  5. PDNN: 深度学习的一个Python工具箱

    PDNN: 深度学习的一个Python工具箱 PDNN是一个在Theano环境下开发出来的一个Python深度学习工具箱.它由苗亚杰(Yajie Miao)原创.现在仍然在不断努力去丰富它的功能和扩展 ...

  6. [深度学习] Pytorch(三)—— 多/单GPU、CPU,训练保存、加载模型参数问题

    [深度学习] Pytorch(三)-- 多/单GPU.CPU,训练保存.加载预测模型问题 上一篇实践学习中,遇到了在多/单个GPU.GPU与CPU的不同环境下训练保存.加载使用使用模型的问题,如果保存 ...

  7. [深度学习] Pytorch学习(一)—— torch tensor

    [深度学习] Pytorch学习(一)-- torch tensor 学习笔记 . 记录 分享 . 学习的代码环境:python3.6 torch1.3 vscode+jupyter扩展 #%% im ...

  8. 一个可扩展的深度学习框架的Python实现(仿keras接口)

    一个可扩展的深度学习框架的Python实现(仿keras接口) 动机 keras是一种非常优秀的深度学习框架,其具有较好的易用性,可扩展性.keras的接口设计非常优雅,使用起来非常方便.在这里,我将 ...

  9. 【神经网络与深度学习】【python开发】caffe-windows使能python接口使用draw_net.py绘制网络结构图过程

    [神经网络与深度学习][python开发]caffe-windows使能python接口使用draw_net.py绘制网络结构图过程 标签:[神经网络与深度学习] [python开发] 主要是想用py ...

随机推荐

  1. hbase-0.92.1集群部署

    环境 主机名 IP地址 角色 安装目录 sht-sgmhadoopnn-01 172.16.101.55 NameNode.SecondaryNameNode. JobTracker.HMaster ...

  2. JAVA写接口傻瓜(#)教程(四)

    接上篇 7.sevlert 啊啊啊终于写到最重要的实现部分了.Servlet = Service + Applet,表示小服务程序.Servlet 是在服务器上运行的小程序.这个词是在 Java ap ...

  3. 局域网内Ping不通

    局域网ping不通, 原来不可忽视这步......... 通常,经常在局域网里面,为了检测网络是否顺畅,都会ping一下IP,如果网络正常,就可以上网或者远程处理其他故障.但是会出现ping别人的主机 ...

  4. 正则-关于一个结果不确定现象怪的研究(reg.test(‘-1’))

    先看下边代码 var value = '-1'; var reg = /^-{0,1}\d+$/g; debugger; if (reg.test(value)||reg2.test(value)) ...

  5. 【转载】MessageFormat.format方法

    MessageFormat.format方法实例 public static void main(String[] args) { String a= "aaa"; String ...

  6. 【转】FluentAPI详细用法

    设置主键modelBuilder.Entity<x>().HasKey(t => t.Name); 设置联合主键modelBuilder.Entity<x>().HasK ...

  7. Angular2+URL中的 # 引发的思考

    1.先分析 # 的作用 1.1. # 的涵义 #代表网页中的位置.其右面的字符就是该位置的标识符.比如,http://www.example.com/index.html#print就代表网页inde ...

  8. java使用SimpleDateFormat实现字符串和日期的相互转换

    public class TimeTwo { public static void main(String[] args) throws ParseException{ String s = &quo ...

  9. Android反编译apk并重新打包签名(Mac环境)

    工具下载 apktool :https://ibotpeaches.github.io/Apktool/install dex2jar:https://github.com/pxb1988/dex2j ...

  10. 软件151 王楚博 JavaEE的配置

    一.准备以下压缩包 1.JDK1.7 文件:jdk1.7.rar 2. eclipse-jee-mars-2 文件:32位系统准备eclipse-jee-mars-2-win32.zip,64位系统准 ...