0

From here I understand what shuffle, batch and repeat do. I'm working on Medical image data where each mini-batch has slices from one patient record. I'm looking for a way to shuffle within the minibatch while training. I cannot increase the buffer size because I don't want slices from different records to get mixed up. Could someone please explain how this can be done?

dataset = tf.data.Dataset.from_tensor_slices(tf.range(1, 20)) 
data = dataset.batch(5).shuffle(5).repeat(1)
for element in data.as_numpy_iterator(): 
  print(element)
Current Output : 
[ 6  7  8  9 10]
[1 2 3 4 5]
[11 12 13 14 15]
[16 17 18 19]
Expected Output : 
[ 6  8  9  7 10]
[3 4 1 5 2]
[15 12 11 14 13]
[16 17 19 20 17]

1 Answers1

0

I just realized, there is no need to shuffle within the mini-batch as shuffling within the minibatch doesn't contribute to improving training in any way. Appretiate if anyone has other views on this.