I am assuming this is your code for testing the model whose parameters are saved in base_model.pth.
So I am guessing you want to run this:



 alameer:

for images, paths in tqdm(dataset):

    targets = torch.tensor([metadata['count'][os.path.split(path)[-1]] for path in paths]) # B
    targets = targets.float()

    # code to print training data to a csv file
    filename=CellsDataset(args.data_dir,transform=ToTensor(),return_filenames=True)
    output = model(images) # B x 1 x 9 x 9 (analogous to a heatmap)
    preds = output.sum(dim=[1,2,3]) # predicted cell counts (vector of length B)
    print(preds)
    paths_test = np.array([paths])
    names_preds = np.hstack(paths)
    print(names_preds)                
    df=pd.DataFrame({'Image_Name':names_preds, 'Target':targets.detach(), 'Prediction':preds.detach()})
    print(df) 
    # save image name, targets, and predictions
    df.to_csv(r'model.csv', index=False, mode='a')



With the parameters saved in this:



 alameer:

model_path = '/base_model.pth'


But you load your model parameters at the very end and do nothing with it:



 alameer:

model.load_state_dict(torch.load(model_path))


Try putting these two lines:



 alameer:

model.load_state_dict(torch.load(model_path))
model.eval()



After this line:



 alameer:

model = Convnet()


Also. I think you know this, but this would mean you are trying to load trained parameters into Convnet, to do so the parameters saved in /base_model.pth should have also been training on said Convnet