fer2013数据集 | 您所在的位置:网站首页 › 男生160斤穿多大码的裤子呢 › fer2013数据集 |
目录
写在前面:一:查看fer2013数据集(cvs格式)二:使用Pandas读取csv三:使用cv2查看其中一张图片四:将数据集划分五:将数据转换为数组(array)格式,否则keras会报错六:使用matplotlib显示照片七:搭建模型八:查看模型结构图(使用pydot)九:开始训练十:使用matplotlib绘图查看结果10.1:batch_size对于训练的影响10.2:评估结果
总结补充
写在前面:
此代码主要来源于:人脸表情识别 深度神经网络 python实现 简单模型fer2013数据集因为是新手,所以直接拿别人的代码来测试一下这个数据集。 此外,由于本人电脑没有独显,只能CPU跑。原始链接中batch_size 设置为8,由于种种原因我没有测试,只测试了128和512的情况在下面的结果中也可以看到20代大约训练了40分钟靠上。原数据集在kaggle中可以下载:fer2013数据集下载页面,或者在我分享的百度网盘中下载链接:百度网盘分享 提取码:u6so
一:查看fer2013数据集(cvs格式)
截止到目前的数据集总量为35887。 三:使用cv2查看其中一张图片 import cv2 img0 = list(map(eval,pixels[0].split(' '))) np_img0 = np.asarray(img0) img0 = np_img0.reshape(48,48) import matplotlib.pyplot as plt plt.imshow(img0, cmap="gray")
在其中,为了更直观地查看图片,将其转换为png格式,其实在本代码中是没有必要的。 from keras.utils import to_categorical from PIL import Image import os num_classes = 7 #表情的类别数目 x_train,y_train,x_val,y_val,x_test,y_test = [],[],[],[],[],[] from tqdm import tqdm for i in tqdm(range(num_of_instances)): usages_name = usages[i] emotions_Str_Nmae = emotions_Str[emotions[i]] one_hot_label = to_categorical(emotions[i],num_classes) #标签转换为one-hot编码,以满足keras对于数据的要求 img = list(map(eval,pixels[i].split(' '))) np_img = np.asarray(img) img = np_img.reshape(48,48) if usages[i] == 'Training': x_train.append(img) y_train.append(one_hot_label) elif usages[i] == 'PrivateTest': x_val.append(img) y_val.append(one_hot_label) else: x_test.append(img) y_test.append(one_hot_label) subfolder = os.path.join('C:\\Users\\24651\\Desktop\\',usages_name,emotions_Str_Nmae) if not os.path.exists(subfolder): os.makedirs(subfolder) im = Image.fromarray(img).convert('L') im.save(os.path.join(subfolder , (str(i)+'.jpg') )) 100%|████████████████████████████████████████████████████████████████████████████| 35887/35887 [06:10 |
CopyRight 2018-2019 实验室设备网 版权所有 |