[0., 1., 1., 0., 1., 0., 0., 1., 0., 1., 1., 0., 1., 0., 0., 1.], [8, 2]) data = nn.Dataset(x, y) # 입력층 뉴련이 2개인 네트워크 생성 network = nn.Network(2) # 뉴런이 4개인 히든층 network.append_affine( 4).append_batchnormalization().append_shift().append_sigmoid() # 뉴런이 2개인 출력층 network.append_affine(2).append_softmax() # 옵티마이저 optimizer = nn.optimizer.SGD(0.01) # 학습을 위한 객체 생성 learner = nn.Learner(data, network, optimizer) # 4개의 배치 사이즈로 내부 신경망을 초기화 learner.init(8) # 처음 정확도 출력하기 print(learner.findAccuracy()) # 학습 learner.learn(1000, True) # 결과 print(learner.findAccuracy())
import sys sys.path.append(__file__.replace('\\NN\\example\\ex3_mnist1.py','')) import NN as nn import tensor import pickle network = nn.NetworkPlus(28*28) network.append_affine(25).append_batchnormalization().append_relu() network.append_affine(10).append_softmax() optimizer = nn.optimizer.SGD() with open(__file__.replace('ex3_mnist1.py', 'tensor_train_img.pkl'), 'rb') as f: train_img = pickle.load(f) with open(__file__.replace('ex3_mnist1.py', 'tensor_train_label.pkl'), 'rb') as f: train_label = pickle.load(f) train_img.shape = [train_img.shape[0], 28 * 28] learner = nn.Learner(train_img, train_label, network, optimizer, 100) learner.init() learner.learn(10, True) print(learner.findAccuracy())