cnblogs321114287

2017-08-28  21:13:22

初学tensorflow,感觉需要来点项目练练手,刚好搜到一篇关于人脸关键点识别(facial keypoint detection)的文章blog[1]

项目主要来源是Kaggle上的一个competition,链接在此

可以在上面下到相关的数据集,在discuss中也可以看到别人的一些方案,本文的主要代码(Ctrl+C+V)也是来自于里面

先看一下它的数据集:

前面的mouth nose什么的指的是一个相对坐标,后面的Image则是这幅图像的像素值(注意图像像素是竖着排列的),先通过一段代码[2]看一下这些图像:

 1 from PIL import Image
 2 import pandas as pd
 3 
 4 import os
 5 
 6 data = pd.read_csv(\'training.csv\')
 7 
 8 
 9 def getimage(each):
10     img = Image.new(\'RGB\', (96, 96), "black")
11     pixels = img.load()  # create the pixel map
12 
13     cot = [int(i) for i in each.split(\' \')]
14     print (cot[0])
15     for i in range(img.size[0]):  # for every pixel:
16         for j in range(img.size[1]):
17             pixels[i, j] = (cot[i + j * 96], cot[i + j * 96], cot[i + j * 96])  # set the colour accordingly, it doesn\'t matter if you change it to j+i*96, because you just rotate it
18     return img
19 
20 
21 if __name__ == \'__main__\':
22     data = pd.read_csv(\'training.csv\')
23     try:
24         os.mkdir(os.getcwd() + \'/imgs\')  # Return a string representing the current working directory
25     except:
26         print (\'X\')
27 
28     print(\'there are \' + str(len(data.Image)) + \' images in total\nstart extracting......\')     #data.*** means the column of the excel data
29     for i in range(1, len(data.Image) + 1):
30         getimage(data.Image[i - 1]).save(os.getcwd() + \'/imgs/\' + str(i) + \'.jpg\')
View Code

 

 

 

 

 

 

 

[1]  thriving_fcl  http://blog.csdn.net/thriving_fcl/article/details/50909109

[2]  shichaoji2016  https://github.com/shichaoji2016/img_extract

分类:

技术点:

相关文章: