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

官方教程地址: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. 一个空格引起的错误。 python

    'render_field' tag requires a form field followed by a list of attributes and values in the form att ...

  2. C博客作业01——分支、顺序结构

    1.本章学习总结 1.1思维导图 本章学习体会及代码量学习体会 1.2.1学习体会 在暑假的时候就有加入新生学习群,对C语言有一定的基础,所以这周的学习相对轻松,但一些细节方面的知识并不是很了解.在这 ...

  3. liunx定时任务

    为当前用户创建cron服务 1.  键入 crontab  -e 编辑crontab服务文件 例如 文件内容如下: */2 * * * * /bin/sh /home/admin/jiaoben/bu ...

  4. react和vue的不同

    React严格上只针对MVC的view层,Vue则是MVVM模式 virtual DOM不一样,vue会跟踪每一个组件的依赖关系,不需要重新渲染整个组件树.而对于React而言,每当应用的状态被改变时 ...

  5. 后缀html和htm文件的区别

    后缀html和htm文件的区别: (1)如果一个网站有index.html和index.htm,默认情况下,优先访问.html. (2).htm后缀是为了兼容以前的dos系统8.3的命名规范

  6. Public_1.bat

    :: targetset targetFileName=Public_2set targetPath=./:: sourceset sourceFileName=Public_1@echo ui ru ...

  7. js零碎知识汇总

    1.window.location.href 表示在当前页面打开,不会打开新窗口. window.open 表示打开新窗口. 2.<input name="action" t ...

  8. padding属性很有用

    html代码中的text-align有时失效,特别是用bootstrap时,用padding-left:xx%,能够很好定位,而且只能够电脑和手机浏览器显示的统一.

  9. SharePoint CU、Hotfix和SP版本的区别

    1.Hotfix:通常是对一个特殊问题的修复包 2.CU(Cumulative Update):Hotfix的集合,包含从上一个SP(Service Pack)版本以来所有的Hotfix 3.SP(S ...

  10. 开发部署项目时出现:java.lang.OutOfMemoryError: PermGen space

    java.lang.OutOfMemoryError: PermGen space 错误: 原文地址:http://www.cnblogs.com/shihujiang/archive/2012/06 ...