def __init__(self, inputDim, convFilterNum, convFilterDim, convImageSize, poolFilterDim, poolImageSize, hiddenDim, outputDim, seed=1): #畳み込み+プーリング付き3層ニューラルネット self.inputLayer = layer.InputLayer(inputDim) self.convLayer = layer.ConvolutionalLayer(convFilterNum, convFilterDim, convImageSize, self.inputLayer, seed) self.poolLayer = layer.PoolingLayer(poolFilterDim, poolImageSize, self.convLayer) self.hiddenLayer = layer.HiddenLayer(hiddenDim, self.poolLayer, seed) self.outputLayer = layer.OutputLayer(outputDim, self.hiddenLayer, seed) self.hiddenLayer.setActivator(util.relu) self.hiddenLayer.setBackPropagator(learning.backPropReLU) # 正解データ self.answer = np.zeros(outputDim)
def __init__(self, sizes, cost=CrossEntropyCost, act=SigmoidActivation): """The list ``sizes`` contains the number of neurons in the respective layers of the network. For example, if the list was [2, 3, 1] then it would be a three-layer network, with the first layer containing 2 neurons, the second layer 3 neurons, and the third layer 1 neuron. The biases and weights for the network are initialized randomly, using a Gaussian distribution with mean 0, and variance 1. Note that the first layer is assumed to be an input layer, and by convention we won't set any biases for those neurons, since biases are only ever used in computing the outputs from later layers.""" self.num_layers = len(sizes) self.sizes = sizes self.default_weight_initializer() self.cost = cost self.activ_fn = act # line zip is to generate a full connected network weights self.layers = [ layer.BNLayer(w, b, act) for w, b in zip(self.weights[:-1], self.biases[:-1]) ] ' output can be configured by output config string ' cost_act = None if cost.combined() else act self.output_layer = layer.OutputLayer(self.weights[-1], self.biases[-1], cost_act, cost)
def __init__(self, inputDim, hiddenDim, outputDim, seed=1): # 三層ニューラルネットワーク self.inputLayer = layer.InputLayer(inputDim) self.hiddenLayer = layer.HiddenLayer(hiddenDim, self.inputLayer, seed) self.outputLayer = layer.OutputLayer(outputDim, self.hiddenLayer, seed) # 正解データ self.answer = np.zeros(outputDim)
def calcLossTest(): driver = DriverLayer() outputLayer = layer.OutputLayer(9, driver) out = outputLayer.calculate() label = np.array([[0], [0], [0], [1], [0], [0], [0], [0], [0]]) print(out) print(label) print(util.crossEntropy(out, label))
def __init__(self, inputDim, hiddenDim, outputDim, seed=1): # 三層ニューラルネットワーク self.inputLayer = layer.InputLayer(inputDim) self.hiddenLayer = layer.HiddenLayer(hiddenDim, self.inputLayer, seed) self.outputLayer = layer.OutputLayer(outputDim, self.hiddenLayer, seed) self.hiddenLayer.setActivator(util.relu) self.hiddenLayer.setBackPropagator(learning.backPropReLU) # 正解データ self.answer = np.zeros(outputDim)
def outputLayerTest(): driver = DriverLayer() outputLayer = layer.OutputLayer(9, driver) print(outputLayer.calculate()) outputLayer.setActivator(util.correctedSoftmax) print(outputLayer.calculate()) outputLayer.setWeight( outputLayer.maker.getIdentityComplex(outputLayer.weightSize)) outputLayer.setShift(np.zeros(outputLayer.shiftSize)) print(outputLayer.calculate()) #print(outputLayer.getOutput()) return outputLayer.getOutput()
def __init__(self, layers): # 输入一个list,存放每一个hiddenLayer的节点数 self.network = [] self.network.append(layer.InputLayer()) # 输入层 i = 0 while i < len(layers): self.network.append( layer.HiddenLayer(layers[i], self.network[i], None)) i = i + 1 self.network.append(layer.OutputLayer(self.network[i])) i = 0 while i < len(self.network) - 1: self.network[i].next_layer = self.network[i + 1] if i != 0: self.network[i].initialize() # 对中间层重新进行初始化 i = i + 1 self.network[-1].initialize()
def inputConvTest(): inputM = ioex.InputManager() outputM = ioex.OutputManager() trainingData = inputM.getMnistTrainingData() sample = trainingData.getImageBatch(5) outputM.showPictureFromBatch(sample, (28, 28)) inputLayer = layer.InputLayer(28 * 28) conv = layer.ConvolutionalLayer(4, 3, inputLayer) outputLayer = layer.OutputLayer(10, conv) #conv.setWeight(np.array([[1,1,1,1,-8,1,1,1,1],[1,0,1,0,-4,0,1,0,1],[0,1,0,1,-4,1,0,1,0],[0,0,0,0,1,0,0,0,0]])) inputLayer.setInputBatch(sample) for i in range(0, 10000): outputLayer.calculate() if i % 1000 == 0: outputM.showPictureFromBatch(conv.getOutput(), (28 * 4, 28)) print(conv.getWeight()) outputLayer.update(trainingData.getAnswerVecotrBatch(5))
import ioex import layer import util print("### task1 ###") # 入出力準備 inputM = ioex.InputManager() outputM = ioex.OutputManager() testingData = inputM.getMnistTestingData() # 3層ニューラルネットワーク inputLayer = layer.InputLayer(28 * 28) hiddenLayer = layer.HiddenLayer(50, inputLayer, 1, 1) outputLayer = layer.OutputLayer(10, hiddenLayer, 1, 1) # ニューラルネットワークの設定 #outputLayer.setActivator(util.correctedSoftmax) #入出力 loop = True while (loop): # 入力 targetNum = inputM.selectNumber() sample = testingData.getSingleData(targetNum) inputLayer.setInput(sample.getImage()) # 出力 result = outputLayer.calculate() outputM.printMaxLikelihood(result) print(result)
def _set_layers(self): last_layer = self.depth - 1 self.layers.append(layer.InputLayer(self.form[0])) for i in range(1, last_layer): self.layers.append(layer.HiddenLayer(self.form[i], [], [])) self.layers.append(layer.OutputLayer(self.form[last_layer], [], []))
import sys import time print "Initialising the training data (golden standard)" netInputVector = [[0.05, 0.1], [0.1, 0.2]] netOutputVector = [[0.01, 0.99], [0.04, 0.99]] print "Setting up the net" net = net.Net() inputLayer = layer.InputLayer(2, net, neuron.SigmoidNeuron) net.setInputLayer(inputLayer) hiddenLayer1 = layer.HiddenLayer(3, net, neuron.SigmoidNeuron) net.addHiddenLayer(hiddenLayer1) hiddenLayer2 = layer.HiddenLayer(5, net, neuron.SigmoidNeuron) net.addHiddenLayer(hiddenLayer2) outputLayer = layer.OutputLayer(2, net, neuron.SigmoidNeuron) net.setOutputLayer(outputLayer) print "Training the net" #for index in range(0, len(netInputVector)): # net.inputLayer.setActivationVector(netInputVector[index]) # net.perform() # error = net.outputLayer.error(netOutputVector[index]) # epoch = 1 # while error > 0.01: # net.backpropagate(netOutputVector[index]) # net.perform() # error = net.outputLayer.error(netOutputVector[index]) # epoch += 1 # print net # print "Training epochs: " + str(epoch)