Returns Nonetype

Hello, Created custom dataset that crops faces from images.

This is my getitem function which is working great.

def getitem(self,index):
images=glob.glob(self.path1)
img_path=os.path.join(self.path1,self.df.iloc[index,2][0].split(‘/’,1)[1])
image=cv.imread(img_path,cv.IMREAD_GRAYSCALE)
y_label=torch.tensor(int(self.df.iloc[index,3]))
try:
image=cv.resize(image,(80,80))
image=torch.tensor(image)
except:
pass

Then splitting dataset into train_set, test_set and creating Dataloaders.

train_set,test_set=torch.utils.data.random_split(dataset,[49862,len(dataset) -49862])
train_loader=DataLoader(train_set,batch_size=10,shuffle=True)
test_loader=DataLoader(test_set,batch_size=10,shuffle=False)

And When i iterate through train_loader it gives me an error.

  for b,(X_train,y_train) in enumerate(train_loader):

AttributeError: ‘NoneType’ object has no attribute ‘float’

But when i iterate through train_set, it works perfectly.

Any help??

I guess the pass statement might create the issue.
In the case the cv.resize or torch.tensor operation is failing for any reason, you would pass this sample and might return None without raising any error (and thus the DataLoader will fail).
Could you raise a RuntimeError with a proper error message and check, why one of these two operations is failing?

Yes, the problem was that pass returned None, so instead of pass i just created np.ones of size 32,32 and that solved.