def __loadNetwork(self): file = filedialog.askopenfile(title='Select neural network', filetypes=(('neural network files', '*.nn'), )) if file is None: return with open(file.name, 'rb') as f: nLayers = unpack('B', f.read(1))[0] neuronsPerLayer = unpack('{}H'.format(nLayers), f.read(2 * nLayers)) if neuronsPerLayer[0] != 784 or neuronsPerLayer[3] != 10: messagebox.showerror( 'Error', 'Neural network has wrong number\nof input (784) or output (10) nodes' ) return self.network = nn.network() self.network.setStructure(neuronsPerLayer) for i in range(len(neuronsPerLayer) - 1): weights = np.array( unpack( '<{}f'.format(neuronsPerLayer[i] * neuronsPerLayer[i + 1]), f.read(4 * neuronsPerLayer[i] * neuronsPerLayer[i + 1]))).reshape( (neuronsPerLayer[i + 1], neuronsPerLayer[i])) self.network.setConnectionWeights(i + 1, weights) biases = np.array( unpack('<{}f'.format(neuronsPerLayer[i + 1]), f.read(4 * neuronsPerLayer[i + 1]))) self.network.setNeuronBias(i + 1, range(neuronsPerLayer[i + 1]), biases) self.__drawNetwork()
def __init__(self): self.network = nn.network() self.__mnistLoaded = False self.__miniBatchSize = [] self.__inputSize = [] self.__learningRate = [] self.__nIterations = []
def __init__(self): self.__network = nn.network() self.__trainingLoaded = False self.__validationLoaded = False self.__miniBatchSize = [] self.__inputSize = [] self.__learningRate = [] self.__nEpochs = [] self.__regularisationConst = []
def __init__(self, master): self.master = master master.title('MNIST Neural Network Test Interface') # drawing canvas area pxSize = 15 self.pixelSize = pxSize self.drawingCanvas = tk.Canvas(width=pxSize * 28, height=pxSize * 28, bg='#000044') self.drawingCanvas.grid(row=0, column=0) self.drawingCanvas.bind('<B1-Motion>', self.__paintOnCanvas) self.drawingCanvas.bind('<Button-1>', self.__paintOnCanvas) self.__addDrawingBackground() self.processDrawingButton = tk.Button(text='Process Digit', command=self.__procDrawing) self.processDrawingButton.grid(row=2) self.clearButton = tk.Button(text='Clear', command=self.__clearDrawingCanvas) self.clearButton.grid(row=1) # pixel canvas area self.pixelCanvas = tk.Canvas(width=pxSize * 28, height=pxSize * 28, bg='#440000') self.pixelCanvas.grid(row=0, column=1, columnspan=2) tk.Label(text='MNIST test index: ').grid(row=1, column=1, sticky='E') self.testIndex = tk.Spinbox(from_=0, to=9999, command=self.__loadMNIST, width=10) self.testIndex.grid(row=1, column=2, sticky='W') self.testIndex.bind('<Return>', self.__loadMNIST) self.mnistLabelVar = tk.StringVar() self.mnistLabelVar.set('Label: #') self.mnistLabel = tk.Label(textvariable=self.mnistLabelVar) self.mnistLabel.grid(row=2, column=1, columnspan=2) # neural network area self.nnCanvas = tk.Canvas(width=pxSize * 43, height=pxSize * 28) self.nnCanvas.grid(row=0, column=3) self.nnCanvas.bind('<Button-1>', self.__highlightNode) self.loadNNbutton = tk.Button(text='Load Neural Network', command=self.__loadNetwork) self.loadNNbutton.grid(row=1, column=3) self.network = nn.network() self.truthResult = 'drawn'