Skip to content

Instantly share code, notes, and snippets.

@Kakarot-2000
Created May 3, 2021 05:50
Show Gist options
  • Save Kakarot-2000/0959ef5de08660796aab3c60ad910f90 to your computer and use it in GitHub Desktop.
Save Kakarot-2000/0959ef5de08660796aab3c60ad910f90 to your computer and use it in GitHub Desktop.
df1 = pd.read_csv("fer2013.csv") #make sure the file is in the root location
# Preprocessing
x_train=[]
x_test=[]
y_train=[]
y_test=[]
for i,row in df1.iterrows():
k=row['pixels'].split(" ")
if(row['Usage']=='Training'):
x_train.append(np.array(k))
y_train.append(row['emotion'])
elif(row['Usage']=='PublicTest'):
x_test.append(np.array(k))
y_test.append(row['emotion'])
x_train=np.array(x_train)
x_test=np.array(x_test)
y_train=np.array(y_train)
y_test=np.array(y_test)
x_train=x_train.reshape(x_train.shape[0],48,48)
x_test=x_test.reshape(x_test.shape[0],48,48)
y_train=tf.keras.utils.to_categorical(y_train,num_classes=7)
y_test=tf.keras.utils.to_categorical(y_test,num_classes=7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment