-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
25 lines (22 loc) · 909 Bytes
/
data.py
File metadata and controls
25 lines (22 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import numpy as np
from os import listdir
import os
import helper
import torch
import matplotlib.pyplot as plt
def mnist():
# Define a transform to normalize the data
files = listdir("data/corruptmnist")
train_in = np.empty(shape=(0, 28, 28))
train_out = np.empty(shape=(0))
test_in = np.empty(shape=(0, 28, 28))
test_out = np.empty(shape=(0))
for f in files:
if f[0:5] == "train":
train_in = np.concatenate((train_in, np.load("data/corruptmnist/" + f)['images']), axis=0)
train_out = np.concatenate((train_out, np.load("data/corruptmnist/" + f)['labels']), axis=0)
else:
test_in = np.concatenate((test_in, np.load("data/corruptmnist/" + f)['images']), axis=0)
test_out = np.concatenate((test_out, np.load("data/corruptmnist/" + f)['labels']), axis=0)
return (train_in, train_out), (test_in, test_out)
mnist()