all_prediction = np.zeros((len(test_dataset), num_classes))
for i, weight in enumerate(weight_list):
for _ in range(tta): model = ... model.cuda() model.load_state_dict(torch.load(weights_path / weight)) model.eval() prediction = np.zeros((len(test_dataset), num_classes)) # num_classes=196 with torch.no_grad(): for i, images in enumerate(test_loader): images = images.cuda() preds = model(images).detach() prediction[i * batch_size: (i+1) * batch_size] = preds.cpu().numpy() all_prediction = all_prediction + prediction
all_prediction /= total_num_models
as you can see in my code. I’m calling model and weight in the for loop.
Do I have to call model everytime I load my weight? or could I just load model once and override weight?