Beispiel #1
0
import numpy as np
import Mln as mln
import dump as dp
import progress as prg

from sklearn.preprocessing import LabelBinarizer

start = time.time()

# 多層パーセプトロン
learning_count = 100000
#neuro_obj = mln.Mln().make_neuralnet([28*28, 100, 10], ['tanh', 'softmax'], 0.01, solved = 'classification')
#neuro_obj = mln.Mln().make_neuralnet([28*28, 1000, 10], ['tanh', 'softmax'], 0.01, solved = 'classification')
neuro_obj = mln.Mln().make_neuralnet([28*28, 10000, 10], ['tanh', 'softmax'], 0.01, solved = 'classification')

labels     = dp.label_file_read('../../mnist/train-labels-idx1-ubyte', True)
input_data = dp.image_file_read('../../mnist/train-images-idx3-ubyte', True) 
# ピクセルの値を0.0-1.0に規格化
input_data = input_data.astype(np.float64)
input_data /= input_data.max()
print "input max : ", input_data.max()

print 'data  size : ', len(input_data)
print 'label size : ', len(labels)

# 教師信号の数字を1-of-K表記に変換
# 0 => [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
# 1 => [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
# ...
# 9 => [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
labels_train = LabelBinarizer().fit_transform(labels)
Beispiel #2
0
#!/usr/bin/python
# coding=utf-8

# Measure Modules
# Handmade Modules
import dump as dp

num_class = 10

print '##### read training data. #####'
training_data  = dp.image_file_read('../../mnist/train-images-idx3-ubyte', normalize = 'max', show = True)

print '##### read training label. #####'
training_label = dp.label_file_read('../../mnist/train-labels-idx1-ubyte', num_class, show = True)

#print '##### compress training data. #####'
#dp.obj_dump_gzip(training_data, '../../mnist/mnist-training_data.pkl.gz')

#print '##### compress training label. #####'
#dp.obj_dump_gzip(training_label, '../../mnist/mnist-training_label.pkl.gz')


print '##### make mnist data & label. #####'
xxx = []
for tdi, tli in zip(training_data, training_label):
    xxx.append([tdi, tli])

print '##### compress training data and label. #####'
dp.obj_dump_gzip(xxx, '../../mnist/mnist-training_all.pkl.gz')