return model if __name__ == '__main__': input_size = 128 minibatch_size = 16 batch_size = 3200 checkpoint_path = 'checkpoints' if not os.path.exists(checkpoint_path): os.makedirs(checkpoint_path) model = build_model() model.load('road_model1-800000') # Train for i in range(num_iterations): image_data, label_data = \ generate_data.generate_batch( height=input_size, width=input_size, minibatch_size=batch_size) X = image_data Y = label_data[:,newaxis] model.fit({'input': X}, {'target': Y}, n_epoch=1, batch_size=minibatch_size, snapshot_epoch=True, show_metric=True, run_id='road_model1')
if __name__ == '__main__': input_size = 128 minibatch_size = 16 batch_size = 3200 checkpoint_path = 'checkpoints' if not os.path.exists(checkpoint_path): os.makedirs(checkpoint_path) model = build_model() model.load('road_model1-800000') # Train for i in range(num_iterations): image_data, label_data = \ generate_data.generate_batch( height=input_size, width=input_size, minibatch_size=batch_size) X = image_data Y = label_data[:, newaxis] model.fit({'input': X}, {'target': Y}, n_epoch=1, batch_size=minibatch_size, snapshot_epoch=True, show_metric=True, run_id='road_model1')
samples_val[i]['xq_padded'].flatten())) y_s = samples_val[i]['ys_padded'].flatten() y_q = samples_val[i]['yq_padded'].flatten() x_val[:len(x_b), i] = x_b y_val[:len(y_s), i] = y_s z_val[:len(y_q), i] = y_q # start training episode_start_time = time.time() for episode in range(1, args.num_episodes + 1): model.train() # generate batch x, y, z = generate_batch(args.batch_size, generate_episode_train, tabu_episodes) # update params model.zero_grad() output = model(x.cuda(), y.cuda(), src_mask=None, tgt_mask=None) loss = criterion(output.view(-1, ntoken), z.view(-1).cuda()) optimizer.zero_grad() loss.backward() optimizer.step() if episode % args.eval_interval == 0: model.eval() with torch.no_grad(): val_out = model(x_val.cuda(),