WuJie1010 / Facial-Expression-Recognition.Pytorch

A CNN based pytorch implementation on facial expression recognition (FER2013 and CK+), achieving 73.112% (state-of-the-art) in FER2013 and 94.64% in CK+ dataset
MIT License
1.78k stars 545 forks source link

ValueError: cannot reshape array of size 0 into shape (28709,48,48) #93

Closed ZangHuanyu closed 4 years ago

ZangHuanyu commented 4 years ago

Hi guys, when I'm running "mainpro_FER.py", I got this error

"Traceback (most recent call last): File "C:/Users/Machine Learning 2/Downloads/Huanyu/Wujie_FER_ResNet/mainpro_FER.py", line 57, in trainset = FER(split = 'Training', transform=transform_train) File "C:\Users\Machine Learning 2\Downloads\Huanyu\Wujie_FER_ResNet\fer.py", line 31, in init self.train_data = self.train_data.reshape(28709, 48, 48) ValueError: cannot reshape array of size 0 into shape (28709,48,48)".

It doesn't show any error report when running the "fer.py", but appears during going "mainpro_FER.py". I posted the related pieces of code here, hope someone can help, thx a lot!

class FER(data.Dataset): """FER2013 Dataset.

Args:
    train (bool, optional): If True, creates dataset from training set, otherwise
        creates from test set.
    transform (callable, optional): A function/transform that  takes in an PIL image
        and returns a transformed version. E.g, ``transforms.RandomCrop``
"""

def __init__(self, split='Training', transform=None):
    self.transform = transform
    self.split = split  # training set or test set
    self.data = h5py.File('./data/data.h5', 'r', driver='core')

    # now load the picked numpy arrays
    if self.split == 'Training':
        self.train_data = self.data['Training_pixel']
        self.train_labels = self.data['Training_label']
        self.train_data = np.asarray(self.train_data)
        print(self.train_data)
        #self.train_data = self.train_data.reshape((28709, 48, 48))
        self.train_data = self.train_data.reshape(28709, 48, 48)

    elif self.split == 'PublicTest':
        self.PublicTest_data = self.data['PublicTest_pixel']
        self.PublicTest_labels = self.data['PublicTest_label']
        self.PublicTest_data = np.asarray(self.PublicTest_data)
        #self.PublicTest_data = self.PublicTest_data.reshape((3589, 48, 48))
        self.PublicTest_data = self.PublicTest_data.reshape(3589, 48, 48)

    else:
        self.PrivateTest_data = self.data['PrivateTest_pixel']
        self.PrivateTest_labels = self.data['PrivateTest_label']
        self.PrivateTest_data = np.asarray(self.PrivateTest_data)
        self.PrivateTest_data = self.PrivateTest_data.reshape(3589, 48, 48)

`

ZangHuanyu commented 4 years ago

And btw, the result of "print(self.train_data)" is "[ ]". So I think the error maybe due to different code writing between python2 and 3.

AZyfen commented 1 year ago

Then how should I rewrite it?

AZyfen commented 1 year ago

请问这个问题,您后来找到解决办法了吗?