import numpy as np
import matplotlib.pylab as plt
from data_loader import dataset_loader
from common.util import shuffle_dataset
from common.multi_layer_net import MultiLayerNet
from common.trainer import Trainer

x_train, t_train, x_test, t_test = dataset_loader()

x_train = x_train[:500]
t_train = t_train[:500]

validation_rate = 0.2
validation_num = int(x_train.shape[0] * validation_rate)
x_train, t_train = shuffle_dataset(x_train, t_train)

x_valuation = x_train[:validation_num]
t_valuation = t_train[:validation_num]
x_train = x_train[validation_num:]
t_train = t_train[validation_num:]


def __train(lr, weight_decay, epoches=50):

    net = MultiLayerNet(input_size=784,
                        hidden_size_list=[100, 100, 100, 100, 100, 100],
                        output_size=10,
                        weight_decay_lambda=weight_decay)
    trainer = Trainer(net,
                      x_train,
                      t_train,
Esempio n. 2
0
import numpy as np
import matplotlib.pylab as plt
from data_loader import dataset_loader
from simple_convnet import SimpleConvnet
from common.trainer import Trainer

x_train, t_train, x_test, t_test = dataset_loader(
    "/home/zjy/nlp/Machine_Learning_and_Deep_Learning_Algorithms/datasets",
    flatten=False)

# x_train = x_train[:500]
# t_train = t_train[:500]

max_epoches = 20
net = SimpleConvnet(input_dim=(1, 28, 28),
                    conv_param={
                        'filter_num': 30,
                        'filter_size': 5,
                        'pad': 0,
                        'stride': 1
                    },
                    hidden_size=100,
                    output_size=10,
                    weight_init_std=0.01)
trainer = Trainer(net,
                  x_train,
                  t_train,
                  x_test,
                  t_test,
                  epoches=max_epoches,
                  mini_batch_size=100,