Change In dimension(CNN) using Dataloader

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)

Usually you’ll get 4 channels, if PIL detects an alpha channel. You could slice the tensor or convert your image using img_as_img = img_as_img.convert('RGB').

Got it.Thanks
But what is alpha channel?

And one more thing how we can create dataloader for simpler data in stored csv file.

The alpha channel is usually used to create transparency as descibed here.

Usually you would implement your custom Dataset, set the path to the .csv data in its __init__, and load the samples in __getitem__. Basically what you’ve done in your first example. Do you have any trouble with your code or am I misunderstanding the question?