TypeError: 'NoneType' object is not callable
talhaanwarch opened this issue · 0 comments
talhaanwarch commented
Here the augmentation function.
def rand_augmentation():
aug=transforms.Compose([
transforms.RandomResizedCrop(248, scale=(0.08, 1.0), interpolation=Image.BICUBIC),
transforms.RandomHorizontalFlip(1),
transforms.RandomVerticalFlip(1),
transforms.RandomRotation(degrees=30),
transforms.ColorJitter(brightness=0.4,contrast=0.4,saturation=0.4),
transforms.RandomPerspective(distortion_scale=0.1),
transforms.RandomAffine(degrees=10),
transforms.ToTensor(),
transforms.RandomErasing(p=0.5),
transforms.Normalize((0.5, ), (0.5, )),
])
return aug.transforms.insert(0, RandAugment(4, 3))
Here is data loader
def load_data(df,batchsize=8):
data =SiameseNetworkDataset(df,image_D='2D',transform=(0,rand_augmentation()))
loader = DataLoader(data,shuffle=True,num_workers=0,batch_size=batchsize)
return loader
here is data loader
def __getitem__(self,index):
if self.transform[0]==2:
img0 = self.transform[1](image=np.array(img0))['image']
img1 = self.transform[1](image=np.array(img1))['image']
else:
img0=self.transform[1](img0)
img1=self.transform[1](img1)
return img0, img1 ,label
If I return aug
only instead of aug.transforms.insert(0, RandAugment(4, 3))
, there is no error.
Error
TypeError Traceback (most recent call last)
<timed exec> in <module>
D:\Datasets\Image dataset\Xray\SIAMESE-classifier\src\cross_vals.py in kfoldcv(model, data, epochs, n_splits, lr, batchsize, skip_tuning, aug)
70
71 #train on all train images
---> 72 model=train_dl(train_loader,epochs,model,"cuda",criterion,opt)
73 train_features,train_labels=get_features(train,model)
74 #now get embeddings of test data
D:\Datasets\Image dataset\Xray\SIAMESE-classifier\src\dl_training.py in train_dl(loader, epochs, model, device, criterion, opt)
120 model=model.to(device)
121 for _epoch in range(epochs):
--> 122 for batch in loader:
123 img1,img2,label=batch
124 img1_emb,img2_emb=model(img1.to(device)),model(img2.to(device))
C:\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py in __next__(self)
433 if self._sampler_iter is None:
434 self._reset()
--> 435 data = self._next_data()
436 self._num_yielded += 1
437 if self._dataset_kind == _DatasetKind.Iterable and \
C:\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py in _next_data(self)
473 def _next_data(self):
474 index = self._next_index() # may raise StopIteration
--> 475 data = self._dataset_fetcher.fetch(index) # may raise StopIteration
476 if self._pin_memory:
477 data = _utils.pin_memory.pin_memory(data)
C:\Anaconda3\lib\site-packages\torch\utils\data\_utils\fetch.py in fetch(self, possibly_batched_index)
42 def fetch(self, possibly_batched_index):
43 if self.auto_collation:
---> 44 data = [self.dataset[idx] for idx in possibly_batched_index]
45 else:
46 data = self.dataset[possibly_batched_index]
C:\Anaconda3\lib\site-packages\torch\utils\data\_utils\fetch.py in <listcomp>(.0)
42 def fetch(self, possibly_batched_index):
43 if self.auto_collation:
---> 44 data = [self.dataset[idx] for idx in possibly_batched_index]
45 else:
46 data = self.dataset[possibly_batched_index]
D:\Datasets\Image dataset\Xray\SIAMESE-classifier\src\dataloader.py in __getitem__(self, index)
49 img1 = self.transform[1](image=np.array(img1))['image']
50 else:
---> 51 img0=self.transform[1](img0)
52 img1=self.transform[1](img1)
53
TypeError: 'NoneType' object is not callable