loss_epoch[idx] += print_loss loss_updates[idx] += 1 for component_index in range(num_patches): if opt.validate: validation_loss = validate(opt, models[component_index], test_loader) #test_loader corresponds to validation set here logs.append_val_loss(validation_loss) logs.append_train_loss([x / loss_updates[idx] for idx, x in enumerate(loss_epoch)]) logs.create_log(models[component_index], epoch=epoch, optimizer=optimizers[component_index], component_idx=component_index) if __name__ == "__main__": opt = arg_parser.parse_args() arg_parser.create_log_path(opt) opt.training_dataset = "unlabeled" # random seeds torch.manual_seed(opt.seed) torch.cuda.manual_seed(opt.seed) np.random.seed(opt.seed) if opt.device.type != "cpu": torch.backends.cudnn.benchmark = True num_patches = opt.grid_dims * opt.grid_dims # load model models, optimizers = [None for i in range(num_patches)], [None for i in range(num_patches)] for i in range(num_patches):
"Step [{}/{}], Time (s): {:.1f}, Acc1: {:.4f}, Acc5: {:.4f}, Loss: {:.4f}" .format(step, total_step, time.time() - starttime, acc1, acc5, sample_loss)) starttime = time.time() print("Testing Accuracy: ", epoch_acc1 / total_step) return epoch_acc1 / total_step, epoch_acc5 / total_step, loss_epoch / total_step if __name__ == "__main__": opt = arg_parser.parse_args() add_path_var = "linear_model" arg_parser.create_log_path(opt, add_path_var=add_path_var) opt.training_dataset = "train" # random seeds torch.manual_seed(opt.seed) torch.cuda.manual_seed(opt.seed) np.random.seed(opt.seed) # load pretrained model context_model, _ = load_vision_model.load_model_and_optimizer( opt, reload_model=True, calc_loss=False) context_model.module.switch_calc_loss(False) ## model_type=2 is supervised model which trains entire architecture; otherwise just extract features if opt.model_type != 2: context_model.eval()