Pytorch: Dataloader shuffle=False producing same batches
class DataSet(torch.utils.data.Dataset):
    def __init__(self,dataframe,n_classes=3,w=384,h=384,apply_aug=False):
        self.data=dataframe
        self.n_classes=n_classes
        self.apply_aug=apply_aug
        self.w=w
        self.h=h
        self.transform=A.Compose([A.Rotate(limit=30,p=0.8),
          A.HorizontalFlip(),
          A.CoarseDropout(max_height=0.1,max_width=0.1,p=1.0),
          A.ShiftScaleRotate(shift_limit=0.09,scale_limit=0.2,rotate_limit=0)
          ])
        
    def __len__(self):
        return self.data.shape[0]
    
    def __getitem__(self,idx):
        IMG=np.zeros((1,self.w,self.h),dtype=np.float32)
        MASK=np.zeros((self.n_classes,self.w,self.h),dtype=np.float32)
        path=self.data.iloc[idx][&quot;image_path&quot;]
        encoded_list=self.data.iloc[idx][&quot;segmentation&quot;]
        width=int(self.data.iloc[idx][&quot;width&quot;][0])
        heigth=int(self.data.iloc[idx][&quot;heigth&quot;][0])
        class_list=self.data.iloc[idx][&quot;class&quot;]
        img=implt.imread(path)
        print(f&quot;idx is {idx}&quot;)
        IMG[:,:width,:heigth]=img
        for class_idx,c in enumerate(class_list):
            if str(encoded_list[class_idx])==&quot;nan&quot;:
                mask=np.zeros((1,width,heigth))
            else:
                mask=RLE_TO_MASK(encoded_list[class_idx],width,heigth)
            MASK[c,:width,:heigth]=mask[0]
        if self.apply_aug:
            transformed=self.transform(image=IMG,mask=MASK)
            IMG,MASK=transformed['image'],transformed['mask']
        IMG=IMG/255.0
        return IMG,MASK

Above is the dataset function created. It outputs the images and masks.
When I change shuffle=True for data loader, it's working fine but when I change shuffle=False. For the next batch the data loader providing the same batch which is produced before.
dataloader=torch.utils.data.DataLoader(DataSet(df,apply_aug=True),batch_size=BATCH_SIZE,shuffle=False)
for i in range(2):
    images,masks=next(iter(dataloader))
    print()
print(images.shape,masks.shape)

idx is 0
idx is 1
idx is 2
idx is 3
idx is 4
idx is 5
idx is 6
idx is 7
idx is 8
idx is 9
idx is 10
idx is 11
idx is 12
idx is 13
idx is 14
idx is 15
idx is 16
idx is 17
idx is 18
idx is 19
idx is 20
idx is 21
idx is 22
idx is 23
idx is 24
idx is 25
idx is 26
idx is 27
idx is 28
idx is 29
idx is 30
idx is 31
idx is 0
idx is 1
idx is 2
idx is 3
idx is 4
idx is 5
idx is 6
idx is 7
idx is 8
idx is 9
idx is 10
idx is 11
idx is 12
idx is 13
idx is 14
idx is 15
idx is 16
idx is 17
idx is 18
idx is 19
idx is 20
idx is 21
idx is 22
idx is 23
idx is 24
idx is 25
idx is 26
idx is 27
idx is 28
idx is 29
idx is 30
idx is 31
torch.Size([32, 1, 384, 384]) torch.Size([32, 3, 384, 384])
When shuffle=True
for i in range(2):
    images,masks=next(iter(dataloader))
    print()
print(images.shape,masks.shape)
idx is 25498
idx is 15357
idx is 11275
idx is 36247
idx is 33223
idx is 8566
idx is 14229
idx is 23999
idx is 28883
idx is 8847
idx is 35485
idx is 36647
idx is 22422
idx is 3693
idx is 32525
idx is 19464
idx is 22187
idx is 38244
idx is 7795
idx is 3690
idx is 7461
idx is 36806
idx is 22455
idx is 6817
idx is 8789
idx is 37809
idx is 33157
idx is 22828
idx is 35858
idx is 38320
idx is 2684
idx is 29708

idx is 38240
idx is 28020
idx is 10356
idx is 20215
idx is 18561
idx is 30083
idx is 30997
idx is 14020
idx is 20896
idx is 25551
idx is 2735
idx is 19138
idx is 23026
idx is 30677
idx is 26664
idx is 2731
idx is 14150
idx is 16735
idx is 28621
idx is 18268
idx is 11793
idx is 35654
idx is 4470
idx is 11312
idx is 37349
idx is 27501
idx is 5389
idx is 34019
idx is 24120
idx is 38311
idx is 14880
idx is 9533

torch.Size([32, 1, 384, 384]) torch.Size([32, 3, 384, 384])


You use iterator incorrectly:
next(iter(dataloader))

Every step you create a new iterator and take the first element (hence it's always the same because the iterator is actually the same). Instead you should create the iterator before for-loop  and call next() in every step.
But why not simply iterate over your dataloader this way:
for images,masks in dataloader:
   # do sth with data

