I am trying to train a neural network in keras which requires me to train the model in batches. I want to use a batch size of 3 images and there are a total of 20 images.
I want to randomly choose 3 unique image IDs from a list of 20 image IDs in one batch. This process will be re-iterated for the entire epoch.
import numpy as np
image_list = [1,2,3,4,5,6,7,8,9,,10,11,12,13,14,15,16,17,18,19,20]
epoch = 10
for ep in range(epoch):
while(some_condition):
train_id = np.random.choice(image_list,3,return=False)
# data loading code
# feature extraction code
# model training
image_list is the list of 20 unique image IDs. In every epoch, train_id will randomly choose 3 unique IDs as long as some_condition is True. I get an error in train_id ('Sample size is greater than Population Size') when I randomly choose 3 values when there are only 2 unique values left in image_list.
I tried to find any replacement of np.random.choice for this error but couldn't find any.
Aucun commentaire:
Enregistrer un commentaire