with open('xtrain_gray.npy', mode="rb") as f: xtrain = np.load(f) with open('ytrain_gray.npy', mode="rb") as f: ytrain = np.load(f) idxs = np.arange(len(xtrain)) # -> array([0, 1, ..., 9999]) np.random.shuffle(idxs) x_train = [] y_train = [] for i in idxs: x_train.append(xtrain[i]) y_train.append(ytrain[i]) x_train = np.array(x_train) y_train = np.array(y_train) model = Model2.Model() lr = 0.01 mn = 0.9 wd = 5e-04 optimization = Adam(model.parameters, learning_rate=lr) batch_size = 1000 idxs = np.arange(len(xtrain)) # -> array([0, 1, ..., 9999]) np.random.shuffle(idxs) for batch_cnt in range(0, len(xtrain) // batch_size): batch_indices = idxs[batch_cnt * batch_size: (batch_cnt + 1) * batch_size] batch = xtrain[batch_indices] # random batch of our training data # compute the predictions for this batch by calling on model
def main(): try: global args global canvas global settings controller = None filemerge = None view = None model = None settings.initialize_prefs(canvas.max_colors()) # Only POSIX systems are supported at this point fileops = FileOpsPOSIX.FileOpsPOSIX() if len(args) == 2: left = args[0] right = args[1] left = os.path.realpath(left) right = os.path.realpath(right) # Instantiate the classes and link them together. model = Model2.Model(fileops, left, right) view = View2.View(canvas, model, settings) else: # len(args) == 3 left = args[0] middle = args[1] right = args[2] left = os.path.realpath(left) middle = os.path.realpath(middle) right = os.path.realpath(right) # Instantiate the classes and link them together. model = Model3.Model(fileops, left, middle, right) view = View3.View(canvas, model, settings) requested_filemerge = settings.get_value('file_merge_program') # print('file_merge_program:', requested_filemerge) if requested_filemerge == 'vim': filemerge = FileMergeVim.FileMergeVim() else: filemerge = FileMergeEmacs.FileMergeEmacs() controller = Controller.Controller(model, view, canvas, filemerge) # Start the model. It will enumerate and then start comparing. model.start_enumerate() # Main event loop while not controller.need_to_quit: if canvas.need_to_resize: view.resize() model.render_again = False view.render() if ((model.state() == Model2.STATE_NORMAL or model.state() == Model3.STATE_NORMAL) and not model.render_again and not canvas.need_to_resize): input = canvas.get_input(0) # wait indefinitely else: input = canvas.get_input(1) # timeout in 1/10 second controller.process_input(input) finally: # print("quitting") if controller is not None: controller.destroy() if filemerge is not None: filemerge.destroy() if view is not None: view.destroy() if model is not None: model.destroy()