Created
January 23, 2019 11:52
-
-
Save arjun-kava/649da77c7a8b85b971bcc66ab4187718 to your computer and use it in GitHub Desktop.
This file contains 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
from keras.datasets import mnist | |
import cv2 | |
import os | |
from tqdm import tqdm | |
from config import * | |
(x_train, y_train), (x_test, y_test) = mnist.load_data() | |
def extract(x,y,dir_path): | |
for index in tqdm(range(x.shape[0]),desc="extracting..."): | |
image = x[index] | |
label = y[index] | |
file_name = str(index) + ".jpg" | |
target_dir_path = os.path.join(dir_path, str(label)) | |
if os.path.exists(target_dir_path) == False: | |
os.makedirs(target_dir_path) | |
cv2.imwrite(os.path.join(target_dir_path, file_name), image) | |
train_dir_path = os.path.join(DATASET_PATH, "train") | |
extract(x_train, y_train, train_dir_path) | |
test_dir_path = os.path.join(DATASET_PATH, "test") | |
extract(x_test, y_test, test_dir_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment