-
Notifications
You must be signed in to change notification settings - Fork 1
/
dataset_loader.py
65 lines (53 loc) · 1.68 KB
/
dataset_loader.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 14 15:47:17 2020
@author: CupakabraNo1
"""
import keras
import gzip
import numpy as np
import constants as const
#< TRAINGING SET LOADING >#
f = gzip.open(const.TRAIN_SET_IMAGES, 'r')
f.read(16)
buf = f.read(const.IMAGE_SIZE * const.IMAGE_SIZE * const.TRAIN_DATA)
frombuff = np.frombuffer(buf, dtype=np.uint8).astype(np.float32)
train_image_data = frombuff.reshape(
const.TRAIN_DATA, const.IMAGE_SIZE, const.IMAGE_SIZE, 1)
f = gzip.open(const.TRAIN_SET_LABELS, 'r')
f.read(8)
buf = f.read(const.TRAIN_DATA)
buff = np.frombuffer(buf, dtype=np.uint8).astype(np.int)
train_label_data = buff.reshape(const.TRAIN_DATA, 1)
#< TEST SET LOADING >#
f = gzip.open(const.TEST_SET_IMAGES, 'r')
f.read(16)
buf = f.read(const.IMAGE_SIZE * const.IMAGE_SIZE * const.TEST_DATA)
frombuff = np.frombuffer(buf, dtype=np.uint8).astype(np.float32)
test_image_data = frombuff.reshape(
const.TEST_DATA, const.IMAGE_SIZE, const.IMAGE_SIZE, 1)
f = gzip.open(const.TEST_SET_LABELS, 'r')
f.read(8)
buf = f.read(const.TEST_DATA)
buff = np.frombuffer(buf, dtype=np.uint8).astype(np.int)
test_label_data = buff.reshape(const.TEST_DATA, 1)
f.close()
train_image_data = train_image_data.astype('float32')
test_image_data = test_image_data.astype('float32')
train_image_data /= 255
test_image_data /= 255
train_label_data = keras.utils.to_categorical(
train_label_data, const.CLASS_NUMBER)
test_label_data = keras.utils.to_categorical(
test_label_data, const.CLASS_NUMBER)
#buff.close()
# 0 #A #K #U #e #o #y
# 1 #B #L #V #f #p #z
# 2 #C #M #W #g #q
# 3 #D #N #X #h #r
# 4 #E #O #Y #i #s
# 5 #F #P #Z #j #t
# 6 #G #Q #a #k #u
# 7 #H #R #b #l #v
# 8 #I #S #c #m #w
# 9 #J #T #d #n #x