()
| 35 | |
| 36 | |
| 37 | def getImageData(): |
| 38 | N = 50000 |
| 39 | savedXpath = '../large_files/cifar10/train_all.npy' |
| 40 | if not os.path.exists(savedXpath): |
| 41 | X = np.zeros((N, 3, 32, 32)) |
| 42 | for i in xrange(N): |
| 43 | im = Image.open("../large_files/cifar10/train/%s.png" % (i + 1)) |
| 44 | X[i] = image2array(im) |
| 45 | if i % 1000 == 0: |
| 46 | print i |
| 47 | np.save(savedXpath, X.astype(np.uint8)) |
| 48 | else: |
| 49 | X = np.load(savedXpath) |
| 50 | X = X.astype(np.float32) / 255.0 |
| 51 | |
| 52 | # load labels |
| 53 | Y = np.zeros(N) |
| 54 | df = pd.read_csv('../large_files/cifar10/trainLabels.csv') |
| 55 | S = df['label'].tolist() |
| 56 | idx = 0 |
| 57 | label2idx = {} |
| 58 | i = 0 |
| 59 | for s in S: |
| 60 | if s not in label2idx: |
| 61 | label2idx[s] = idx |
| 62 | idx += 1 |
| 63 | Y[i] = label2idx[s] |
| 64 | i += 1 |
| 65 | print "done loading data" |
| 66 | X, Y = shuffle(X, Y) |
| 67 | return X[:30000], Y[:30000] |
| 68 | |
| 69 | |
| 70 | class HiddenLayer(object): |
no test coverage detected