text_plain_output_2.png text_plain_output_1.png
import gc

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

dataset = pd.read_csv('../input/challenges-in-representation-learning-facial-expression-recognition-challenge/icml_face_data.csv')
dataset.columns = ['emotion', 'Usage', 'pixels']
test_dataset = dataset.loc[dataset['Usage'] == 'PublicTest', ['emotion', 'pixels']]
train_dataset = dataset.loc[dataset['Usage'] == 'Training', ['emotion', 'pixels']]
validation_dataset = dataset.loc[dataset['Usage'] == 'PrivateTest', ['emotion', 'pixels']]

def pixels_to_array(pixels):
    array = np.array(pixels.split(), 'uint8')
    return array
def image_reshape(data):
    image = np.reshape(data['pixels'].to_list(), (data.shape[0], 48, 48, 1))
    image = np.repeat(image, 3, -1)
    return image

train_dataset['pixels'] = train_dataset['pixels'].apply(pixels_to_array)
test_dataset['pixels'] = test_dataset['pixels'].apply(pixels_to_array)
validation_dataset['pixels'] = validation_dataset['pixels'].apply(pixels_to_array)
print('Train:')
print(type(train_dataset['pixels']))
print(train_dataset.shape)
print('Validation:')
print(type(validation_dataset['pixels']))
print(validation_dataset.shape)
print('Test:')
print(type(test_dataset['pixels']))
print(test_dataset.shape)
X_train = image_reshape(train_dataset)
y_train = train_dataset['emotion']
print(X_train.shape)
X_test = image_reshape(test_dataset)
y_test = test_dataset['emotion']
print(X_test.shape)
X_val = image_reshape(validation_dataset)
y_val = validation_dataset['emotion']
print(X_val.shape)
del dataset
gc.collect()