While i was creating dataloader using “CustomDatasetFromImages” class,
I got change in the dimesnion of my images from 3 to 4.
->data.shape
torch.Size([10, 4, 50, 50])
But how could this happend??
As my images r in the png format of dimension with “3”
Here is the code–
class CustomDatasetFromImages(Dataset):
def init(self,csv_path):
self.to_tensor=transform = transforms.Compose([
transforms.Resize(50),
transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
])
self.data_info=pd.read_csv(csv_path,header=None)
self.image_arr=np.asarray(self.data_info.iloc[:,0])
self.label_arr=np.asarray(self.data_info.iloc[:,1])
self.data_len=len(self.data_info.index)
def __getitem__(self,index):
single_image_name=self.image_arr[index]
img_as_img=Image.open(single_image_name)
#some_operation_arr=self.operation_arr[index]
img_as_tensor = self.to_tensor(img_as_img)
single_image_label=self.label_arr[index]
return(img_as_tensor,single_image_label)
def __len__(self):
return self.data_len
if name==“main”:
custom=CustomDatasetFromImages(r’/content/gdrive/My Drive/NishuOPENCV flower/flower_images/flower_labels.csv’)
data_loader = torch.utils.data.DataLoader(dataset=custom,batch_size=10,shuffle=False)