TypeError: 'int' object is not callable when loading images

Hi All-

I’ve looked at the posted articles on this topic and have tried these things. I am not able to get past this error. Here is the error:

File “/image_aug/mydatasets.py”, line 160, in load_chestxray_dataset
dataset = TensorDataset(data, target)
File “/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataset.py”, line 36, in init
assert all(tensors[0].size(0) == tensor.size(0) for tensor in tensors)
File “/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataset.py”, line 36, in
assert all(tensors[0].size(0) == tensor.size(0) for tensor in tensors)
TypeError: ‘int’ object is not callable

Here is the relevant code snippet:

filename is a list of image names to load. target is a list of labels

X_data = [ ]
for myFile in filename:
image = cv2.imread(’./download_imgs/’+myFile, cv2.IMREAD_GRAYSCALE)
image = (image.astype(np.float32, copy=False))/255

image_data_final = torch.from_numpy(np.stack((X_data)))
target_final = torch.tensor(target, dtype=torch.int64)
data_final = torch.tensor(image_data_final, dtype=torch.float32)

dataset=TensorDataset(data, target)

I am not sure what is not working about this? Do the images need further transformation? Should they not be appended to a list, and use some other structure? Also, the list of labels and the list of images are the same size because they are both pulled as different cols from the same Pandas dataframe. Thanks for the help here!!

Try passing target_final instead of target to TensorDataset.

1 Like

Yes, this has fixed the issue. I somehow missed this after too many copy-pastes. Thank you very much for your help!