Spaces:
Sleeping
Sleeping
Download src/app/utils/preprocess.py from JEPHONETORRE/FINALPROJ: direct link, hf CLI and curl.
- Browser
- Download file 759 Bytes
-
https://huggingface.co/spaces/JEPHONETORRE/FINALPROJ/resolve/main/src/app/utils/preprocess.py
- Command line
-
hf download hf://spaces/JEPHONETORRE/FINALPROJ/src/app/utils/preprocess.py
-
curl -L -o preprocess.py https://huggingface.co/spaces/JEPHONETORRE/FINALPROJ/resolve/main/src/app/utils/preprocess.py
759 Bytes
| import os | |
| import cv2 | |
| import numpy as np | |
| def load_images_from_folder(folder_path, img_size): | |
| emotions = sorted(os.listdir(folder_path)) | |
| x_data = [] | |
| y_data = [] | |
| for idx, emotion in enumerate(emotions): | |
| emotion_folder = os.path.join(folder_path, emotion) | |
| for filename in os.listdir(emotion_folder): | |
| img_path = os.path.join(emotion_folder, filename) | |
| img = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE) | |
| if img is not None: | |
| img = cv2.resize(img, img_size) | |
| x_data.append(img) | |
| y_data.append(idx) | |
| x_data = np.array(x_data) | |
| y_data = np.array(y_data) | |
| x_data = x_data.reshape(-1, img_size[0], img_size[1], 1) | |
| return x_data, y_data, emotions | |