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.

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.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))

def __getitem__(self,index):
    img_as_tensor = self.to_tensor(img_as_img)
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 =,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?