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

   dataset=NumbersDataset(paths,batch_size=16,shuffle=True)
    print(len(dataset)) #449900
    dataset_loader=DataLoader(dataset,batch_size=16,shuffle=True,num_workers=4)
    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):
        self.img_dir='blender_files/Model_0/images'
        self.coord_files=paths
        self.batch_size=batch_size
        self.shuffle=shuffle
        self.transforms=None
        self.image_shape=(256,256)
        self.data=[]
        img_list=glob.glob("blender_files/Model_0/images/*")
        for img_path in img_list:
            for file in self.coord_files:
                self.data.append([img_path,file])

        
        
        
        

    def __len__(self):
        self.num_batches=int(np.floor(len(self.coord_files)/self.batch_size))
        return len(self.data)

    def __getitem__(self, idx):
        
        if self.transforms is not None:
            self.image=self.transform(self.image)
         
        img_path,coord_path=self.data[idx]
        image=cv2.imread(img_path,0)
        image=cv2.resize(image,self.image_shape)
        coord=np.load(coord_path)
        return image.ravel(),coord
        #for i in range(len(self.coord_files)):
            #X_coord=np.load(coord_files[i])
            #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.