Sorry, if this question is very basic. I’m trying to print the image names at each iterations to a csv file whilst training the model. but I am getting the following error message:
filename=output.files AttributeError: ‘Tensor’ object has no attribute ‘files’
# main training loop
global_step = 0
best_test_error = 10000
#filename=CellsDataset(args.data_dir,transform=ToTensor(),return_filenames=True)
for epoch in range(50):
    print("Epoch %d" % epoch)
    model.train()
    for images, paths in tqdm(loader_train):
        images = images.to(device)
        targets = torch.tensor([metadata['count'][os.path.split(path)[-1]] for path in paths]) # B
        targets = targets.float().to(device)
        filename=CellsDataset(args.data_dir,transform=ToTensor(),return_filenames=True)
        #print(filename.files)

        output = model(images) # B x 1 x 9 x 9 (analogous to a heatmap)
        #print(output.filename)
        preds = output.sum(dim=[1,2,3]) # predicted cell counts (vector of length B)
        filename=output.files
        print(preds)
        with open('preds_base_model.csv','a') as fd:
            fd.write( ','.join(map(str, preds.detach().tolist())) + '\n')
            fd.write( ','.join(map(str, targets.detach().tolist())) + '\n')
            fd.write(( ','.join(map(str, filename.detach().tolist())) + '\n')