Created
December 12, 2018 23:39
-
-
Save athena15/f912db8a27de706bb35206a85f68b0a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def process_image(path): | |
img = Image.open(path) | |
img = img.resize((224, 224)) | |
img = np.array(img) | |
return img | |
def process_data(X_data, y_data): | |
X_data = np.array(X_data, dtype = 'float32') | |
if rgb: | |
pass | |
else: | |
X_data = np.stack((X_data,)*3, axis=-1) | |
X_data /= 255 | |
y_data = np.array(y_data) | |
y_data = to_categorical(y_data) | |
return X_data, y_data | |
def walk_file_tree(relative_path): | |
X_data = [] | |
y_data = [] | |
for directory, subdirectories, files in os.walk(relative_path): | |
for file in files: | |
if not file.startswith('.') and (not file.startswith('C_')): | |
path = os.path.join(directory, file) | |
gesture_name = gestures[file[0:2]] | |
y_data.append(gestures_map[gesture_name]) | |
X_data.append(process_image(path)) | |
else: | |
continue | |
X_data, y_data = process_data(X_data, y_data) | |
return X_data, y_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment