FineTuning with Reset, "set" is not callable


(Giulia Castagnolo) #1

Can anyone help me?
I have a problem with my code.

–This is part of my code

path_dataset_train="/media/imagenet/Data/CLS-LOC/train"
path_dataset_val="/media/imagenet/Data/CLS-LOC/val2"
mean = [0.5, 0.5, 0.5]
std = [0.5, 0.5, 0.5]
#definisco trasformazioni per DataAumentation

transforms_train = {
T.Compose([
T.RandomCrop(224),
T.RandomHorizontalFlip(),
myTrasform(0.3,0.3,0.4,0.3,random.randint(0, 6) ),
T.ToTensor(),
T.Normalize(mean,std)

]), 

}
transforms_val = {
T.Compose([
T.Resize(256),
T.RandomCrop(224),
T.RandomHorizontalFlip(),
myTrasform(0.3,0.3,0.4,0.3,random.randint(0, 6) ),
T.ToTensor(),
T.Normalize(mean, std)

]),

}

Istanzia dataset con trasformazioni

dataset_train = torch.utils.data.DataLoader(
datasets.ImageFolder(path_dataset_train,transform=transforms_train),
batch_size=64,
shuffle=True, num_workers=4)

dataset_val = torch.utils.data.DataLoader(
datasets.ImageFolder(path_dataset_val,transform=transforms_val),
batch_size=64,
shuffle=True, num_workers=4)

-----Second part
def train_model(dataset_train,dataset_validate,model,criterion,optimizer,scheduler):

best_model=copy.deepcopy(model.state_dict())
#model.load_state_dict(best_model)

scheduler.step()

for epoch in range(1,N_EPOCHS+1):
    model.train(True) 
    
    for inputs,targets in dataset_train:

        print("Train mode")
        if use_cuda:
            inputs,targets = inputs.cuda(), targets.cuda()

When I try the code, I have this error:
TypeError: Traceback (most recent call last):
File “/opt/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py”, line 42, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File “/opt/anaconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py”, line 42, in
samples = collate_fn([dataset[i] for i in batch_indices])
File “/opt/anaconda3/lib/python3.6/site-packages/torchvision-0.2.0-py3.6.egg/torchvision/datasets/folder.py”, line 124, in getitem
img = self.transform(img)
TypeError: ‘set’ object is not callable

Please help me


(Simon Wang) #2

you defined these as sets


(Giulia Castagnolo) #3

I don’t understand. How Can change It?


#4

Remove the curly braces:

transforms_train = T.Compose([
    T.RandomCrop(224),
    T.RandomHorizontalFlip(),
    myTrasform(0.3,0.3,0.4,0.3,random.randint(0, 6) ),
    T.ToTensor(),
    T.Normalize(mean,std)
])

transforms_val = T.Compose([
    T.Resize(256),
    T.RandomCrop(224),
    T.RandomHorizontalFlip(),
    myTrasform(0.3,0.3,0.4,0.3,random.randint(0, 6) ),
    T.ToTensor(),
    T.Normalize(mean, std)
])

(Giulia Castagnolo) #5

Thanks you for help.