Hy guys, I have a strange error and I don’t know why.
This is my code:
from torch.utils.data.dataset import Dataset
import pandas as pd
from PIL import Image
from os import path
import numpy as np
from torchvision import transforms


class Dataset(Dataset):

    def __init__(self, base_path, Intensitypath, csv_list):
        super(Dataset,self).__init__()


        self.base_path = base_path

        self.IntensityPath = Intensitypath

        self.csv_list=csv_list

        self.images = pd.read_csv(self.csv_list, names=['ID','IDIntensity', '#PUNTI2', 'DX', 'DZ','DA','u','v'])




    def __getitem__(self, index):

        ID, IDIntensity, PUNTI2, DX, DZ, DA, u, v = self.images.iloc[index]

        Rest_path = str(ID) + ".png"
        img = Image.open(path.join(self.base_path, Rest_path))

        transformations= transforms.Compose([transforms.Resize(256),
                                             transforms.CenterCrop(224),
                                             transforms.ToTensor(),  # conversione in tensore
                                             transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])])

        img = transformations(img)

        Rest_path2 = str(IDIntensity) + ".png"

        imgInt = Image.open(path.join(self.IntensityPath, Rest_path2))


        # restituiamo un dizionario contenente immagine, movimento ed orientamento
        return {'image': img,"image_intensity": imgInt,'Movement': np.array([DX, DZ, u, v], dtype='float')
    def __len__(self):
        return len(self.images)


In another module:



import torch
import torch.nn as nn
from torch.optim import Adam
import numpy as np
from dataset import Dataset
from torch.utils.data import DataLoader
from torchnet.meter import AverageValueMeter
from torchnet.logger import VisdomPlotLogger, VisdomSaver
import nets

def start_all():

  
    torch.set_num_threads(4)

    model = nets.final_model()



    #Define train dataset and loader
    train = Dataset('./Dataset/Input','./Dataset/ToRec','./Dataset/Train.csv')
    valid = Dataset('./Dataset/Input','./Dataset/ToRec','./Dataset/Validation.csv')

    train_loader = DataLoader(train, batch_size=64,num_workers=2)
    valid_loader = DataLoader(valid, batch_size=64,num_workers=2)


    model_trained= train(model, train_loader, valid_loader, exp_name="MultiHead", epochs=1000)


in main module I call the method start_all().
the error that my code give me is:
runfile(’/Users/giuseppepuglisi/Desktop/MultiHead/main.py’, wdir=’/Users/giuseppepuglisi/Desktop/MultiHead’)
Traceback (most recent call last):
File “/Users/giuseppepuglisi/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py”, line 3331, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File “”, line 1, in 
runfile(’/Users/giuseppepuglisi/Desktop/MultiHead/main.py’, wdir=’/Users/giuseppepuglisi/Desktop/MultiHead’)
File “/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py”, line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
File “/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py”, line 18, in execfile
exec(compile(contents+"\n", file, ‘exec’), glob, loc)
File “/Users/giuseppepuglisi/Desktop/MultiHead/main.py”, line 11, in 
train.start_all()
File “/Users/giuseppepuglisi/Desktop/MultiHead/train.py”, line 125, in start_all
model_trained= train(model, train_loader, valid_loader, exp_name=“MultiHead”, epochs=1000)
TypeError: ‘Dataset’ object is not callable
And I don’t know why