args=parser.parse_args() current_working_dir = os.getcwd() print('current_working_dir: ', current_working_dir) pre = Preprocessing('fer2013', root_dir=current_working_dir) pre.load_data('train_reduced_norm.csv.gz', name='train') pre.load_data('test_public_norm.csv.gz', name='val') X = pre.get('val').drop(columns=['emotion']) y = pre.get('val')['emotion'] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.20, random_state = 42) val = pd.DataFrame(X_test) val['emotion'] = y_test pre.set(name='val', value=val) print(pre.get(name='val').head()) train_pixels = pre.get(name='train').drop(columns=['emotion']) val_pixels = pre.get(name='val').drop(columns=['emotion']) print('data loaded') img_conv = ImageConverter() train_pixel_np = train_pixels.values train_pixel_224_np = np.zeros(shape=[train_pixel_np.shape[0], 224 * 224]) for i in range(train_pixel_np.shape[0]): image = train_pixel_np[i].reshape(48, 48) newimg = img_conv.upscale(image)
X_train_encoded = trained_model.encoder(X_train) X_test_encoded = trained_model.encoder(X_test) X_test_decoded = trained_model.decoder(X_test_encoded) X_train_encoded_df = pd.DataFrame(X_train_encoded.detach().numpy()) X_test_encoded_df = pd.DataFrame(X_test_encoded.detach().numpy()) cols = list(range(1, n_features_encoded + 1)) X_train_encoded_df.columns = cols X_test_encoded_df.columns = cols train_encoded_data = X_train_encoded_df.join(y_train_df) test_encoded_data = X_test_encoded_df.join(y_test_df) pre.set('train_encoded', train_encoded_data) pre.set('test_encoded', test_encoded_data) pre.save('train_encoded') pre.save('test_encoded') plt.figure(1, figsize=(30, 20)) for idx in range(30): image = X_test[idx].detach().numpy().reshape(48, 48) image2 = X_test_encoded[idx].detach().numpy().reshape( int(math.sqrt(n_features_encoded)), int(math.sqrt(n_features_encoded))) image3 = X_test_decoded[idx].detach().numpy().reshape(48, 48) # Call signature: subplot(nrows, ncols, index, **kwargs) plt.subplot(10, 9, 1 + idx * 3) plt.imshow(image, cmap='hot', interpolation='none')