标签:article targe 验证 onclick present pix test get taf
使用的数据集是FER2013
kaggle FER2013 https://www.kaggle.com/c/challenges-in-representation-learning-facial-expression-recognition-challenge/data
该数据集官方的下载链接目前失效了,可通过这个链接下载:https://www.kaggle.com/shawon10/facial-expression-detection-cnn/data?select=fer2013.csv
FER2013数据集下载下来是一个总 3w5k 行左右的csv文件:
......
......
第一列emotion是图像标签,即 y:[0, 6]。分别代表7种emotion:0 - ‘angry’,1 - ‘disgusted’,2 - ‘feaful’,3 - ‘happy’,4 - ‘sad’,5 - ‘surprised’,6 - ‘neutral’
第二列是人脸图像的灰度像素值:[0, 255]
第三列是图像用途分类。根据第三列将图像分为 训练集(training),验证集(public test),测试集(private test)
读数据:
1 import pandas as pd 2 import numpy as np 3 4 data_path = "../DATA/fer2013.csv" 5 df = pd.read_csv(data_path)
其中pixel列是一个字符串,将pixel列转为 int型 的list,表示像素灰度值
1 df[‘pixels‘] = df[‘pixels‘].str.split(‘ ‘).apply(lambda x: [int(i) for i in x])
也可在此步直接将pixel reshape成48*48的:
df[‘pixels‘] = df[‘pixels‘].str.split(‘ ‘).apply(lambda x: np.array([int(i) for i in x]).reshape(48,48))
将FER2013.csv根据用途(usage)分为train、val、test
分完后记得把原来的dataframe的index重设,否则val、test的dataframe序号不连续,后面y_val转成torch.LongTensor时会报错
1 def devide_x_y(my_df): 2 return my_df[‘pixels‘].reset_index(drop=True), my_df[‘emotion‘].reset_index(drop=True) 3 4 # 分别筛选出training、publictest、privatetest对应的行 5 training = df[‘Usage‘]=="Training" 6 publicTest = df[‘Usage‘] == "PublicTest" 7 privateTest = df["Usage"] == "PrivateTest" 8 9 # 读取对应行的数据 10 train = df[training] 11 public_t = df[publicTest] 12 private_t = df[privateTest] 13 14 # 分为 X 和 y 15 train_x, train_y = devide_x_y(train) 16 val_x, val_y = devide_x_y(public_t) 17 test_x, test_y = devide_x_y(private_t)
分完后,各数据集的行数如下:
train:28709
val:3589
test:3589
len(train_x[0])每个图片长度为 2304 --> 48 * 48
画一张出来看一下
1 import matplotlib.pyplot as plt 2 3 img_test = train_x[0].reshape(48,48) 4 plt.figure() 5 plt.imshow(img_test,cmap=‘gray‘) 6 plt.show()
显示如下:
注:如果没有注明是灰度图:cmap=gray,则会显示如下:
参考:https://blog.csdn.net/mathlxj/article/details/87920084
数据集获取:
中科院数据CASME II:http://fu.psych.ac.cn/CASME/casme2.php 已发邮件
SAMM datset:http://www2.docm.mmu.ac.uk/STAFF/m.yap/dataset.php
SMIC (下载的SMIC-VIS):http://www.cse.oulu.fi/SMICDatabase 已发邮件
CK, CK+:http://www.pitt.edu/~emotion/ck-spread.htm
参考:
https://github.com/tgpcai/Microexpression_recognition
标签:article targe 验证 onclick present pix test get taf
原文地址:https://www.cnblogs.com/YeZzz/p/13224432.html