提取文件夹的图片并将其合成为数据集(fer2013)

提取文件夹的图片并将其合成为数据集(fer2013)_第1张图片
链接:https://pan.baidu.com/s/1k3FfWMd_aSyISCtxj9nvDQ
提取码:8x2j

# -*- coding: UTF-8 -*-
#@Time : 2020/3/17 @Author : SUNLIN
import os
import cv2
import numpy as np

file='../data/fer2013/Training'
emotions=['anger','disgust','fear','happy','neutral','sad','surprised']
train_x=[]
for i in range(len(emotions)):
    folder=os.path.join(file,emotions[i])
    images_name=os.listdir(folder)
    for j in range(len(images_name)):
        image=cv2.imread(os.path.join(folder,images_name[j]),0)
        image=image[:,:,np.newaxis]
        train_x.append(image)
train_x=np.array(train_x).astype('float32')/255
print(train_x.shape)

result: (28709, 48, 48, 1)

你可能感兴趣的:(提取文件夹的图片并将其合成为数据集(fer2013))