Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba49bfc

Browse files
committed
Create data.py
1 parent 09c2000 commit ba49bfc

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

DeepLearning/CNN_mnist/data.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
import os
3+
from PIL import Image
4+
import numpy as np
5+
6+
def load_data():
7+
print 'start loading data...'
8+
data = np.empty((42000,1,28,28),dtype="float32")
9+
label = np.empty((42000,),dtype="uint8")
10+
11+
imgs = os.listdir("./mnist")
12+
num = len(imgs)
13+
for i in range(num):
14+
img = Image.open("./mnist/"+imgs[i])
15+
arr = np.asarray(img,dtype="float32")
16+
data[i,:,:,:] = arr
17+
label[i] = int(imgs[i].split('.')[0])
18+
return data,label
19+

0 commit comments

Comments
 (0)