def inputTest(): inputM = ioex.InputManager() trainingData = inputM.getMnistTrainingData() print(trainingData.images.shape) print(trainingData.answers.shape) # trainingData.shuffle() sample = trainingData.getImageBatch(3) print(sample) print(trainingData.images.shape) print(trainingData.answers.shape) idx = inputM.selectNumber() sample = trainingData.getSingleData(idx) print("answer: " + str(sample.answer)) print(sample.getSize()) print("show picture?") selected = inputM.selectYesOrNo() if selected: plt.imshow(sample.image, cmap=cm.gray) plt.show() return sample
def dataTest(): inputM = ioex.InputManager() trainingData = inputM.getMnistTrainingData() print("\ngetImageBatch") for i in range(1, 11): #計測スタート start = time.time() batch = trainingData.getImageBatch(50 * i) #print(batch) #print(batch.shape) #計測終了 elapsed_time = time.time() - start print(50 * i, end=": ") print("elapsed_time:{0}".format(elapsed_time) + "[sec]") print("\ngetAnswerVectorBatch") for i in range(1, 11): #計測スタート start = time.time() batch = trainingData.getAnswerVecotrBatch(50 * i) #計測終了 elapsed_time = time.time() - start print(50 * i, end=": ") print("elapsed_time:{0}".format(elapsed_time) + "[sec]") print("\nshaffle") #計測スタート start = time.time() trainingData.shuffle() #計測終了 elapsed_time = time.time() - start print("elapsed_time:{0}".format(elapsed_time) + "[sec]")
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)