读取fer2013的数据为图片

import csv
import numpy as np
from PIL import Image

file='data/fer2013.csv'
with open(file,'r') as csvin:
    data=csv.reader(csvin)
    for row in data:
        if row[-1]=='Training':
            temp_pixel = []
            for pixel in row[1].split( ):
                temp_pixel.append(int(pixel))
            print(temp_pixel)
            I=np.array(temp_pixel)
            print(np.shape(I))
            I = np.reshape(I, (48, 48))
            print(np.shape(I))
            print(I)
            new_im = Image.fromarray(I.astype('uint8'))
            new_im.show()
            break

这里只读了第一行的数据

你可能感兴趣的:(读取fer2013的数据为图片)