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