loss_epoch[idx] += print_loss logs.append_train_loss([x / total_step for x in loss_epoch]) # validate by testing the CPC performance on the validation set if opt.validate: validation_loss = val_by_InfoNCELoss.val_by_InfoNCELoss(opt, model, test_loader) logs.append_val_loss(validation_loss) logs.create_log(model, epoch=epoch, optimizer=optimizer) if __name__ == "__main__": opt = arg_parser.parse_args() arg_parser.create_log_path(opt) # set random seeds torch.manual_seed(opt.seed) torch.cuda.manual_seed(opt.seed) np.random.seed(opt.seed) random.seed(opt.seed) # load model model, optimizer = load_audio_model.load_model_and_optimizer(opt) # initialize logger logs = logger.Logger(opt) # get datasets and dataloaders train_loader, train_dataset, test_loader, test_dataset = get_dataloader.get_libri_dataloaders(
# calculate accuracy total += num_samples_per_speaker correct += (svm_output == target).sum() speaker_idx += 1 accuracy = correct / total print("Testing Accuracy SVM: ", accuracy) return accuracy if __name__ == "__main__": opt = arg_parser.parse_args() arg_parser.create_log_path(opt, add_path_var="linear_model") opt.SVM_training_samples = 20 # Device configuration opt.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") # random seeds torch.manual_seed(opt.seed) torch.cuda.manual_seed(opt.seed) np.random.seed(opt.seed) # load pretrained model context_model, _ = load_audio_model.load_model_and_optimizer( opt, reload_model=True ) context_model.eval()