Batch shape coming out to be wrong when iterating through dataloader

While iterating through the dataloader,I noticed that for all samples,the shape of the image and y was coming out to be [16,256256] and [16,3] but at the end the output of the batch shape came out to be [12,256256] and [12,3].
Why was the batch size set to 12 and not 16.
Code is listed below

    print(len(dataset)) #449900
    for image,coord in dataset_loader:
        print("Batch of images has shape:",image.shape)
        print("Batch of coordinates has shape:",coord.shape)

Batch of images has shape: torch.Size([16, 65536])
Batch of coordinates has shape: torch.Size([16, 3])
Batch of images has shape: torch.Size([16, 65536])
Batch of coordinates has shape: torch.Size([16, 3])
Batch of images has shape: torch.Size([12, 65536])
Batch of coordinates has shape: torch.Size([12, 3])

My custom dataset is as follows

class NumbersDataset(Dataset):
    def __init__(self,paths,batch_size=16,shuffle=True):
        for img_path in img_list:
            for file in self.coord_files:


    def __len__(self):
        return len(

    def __getitem__(self, idx):
        if self.transforms is not None:
        return image.ravel(),coord
        #for i in range(len(self.coord_files)):
            #return self.image.ravel(),X_coord

The number of files in paths is 89980 and there are 4 images

The last batch is smaller, since you have 5623 full batches (5623 * 16 = 89968) and 12 samples at the end (89980 % 16 = 12). To drop the last batch you could use drop_last=True in the DataLoader.

that makes sense,thanks

@ptrblck I have another question while training the autoencoder on my dataset,at the end of the training ,the output came out to be in the following format

[ 70.6182,  70.8503,  70.6278,  ..., 243.5364, 330.0468,   5.6832]

But at evaluation stage,when I run the autoencoder on a single image and a random vector of 3x1,the autoencoder generates the following ouptut

tensor([[3.2402e+16, 3.4111e+16, 3.2839e+16,  ..., 4.4640e+16, 4.4089e+16,
         7.7656e+15]], device='cuda:0', dtype=torch.float64)

As you can see the values are not close to the ones obtained during training,any ideas why this is happening.

If calling model.eval() yields worse results on the same input data (or similar data), it could mean that e.g. the running stats of the batchnorm layers are off and you could change the momentum or check if you are dealing with data samples from different distributions.

hmm,i checked the data distribution ,its coming from the same set,plus during validation stage,as for momentum i will try to see.