Я создал генератор данных в python / Keras для добавления имен файлов и меток в batchesize = 5.Он получает одинаковые имена файлов и меток на каждой итерации.Я хотел бы получить новые (последующие) имена файлов и метки на каждой итерации.
Я просмотрел несколько примеров и прочитал документы, но не могу понять это.
def datagenerator(imgfns, imglabels, batchsize, mode="train"):
while True:
images = []
labels = []
cnt=0
while len(images) < batchsize:
images.append(imgfns[cnt])
labels.append(imglabels[cnt])
cnt=cnt+1
#for ii in range(batchsize):
# #img = np.load(imgfns[ii])
# #images.append(img)
# images.append(imgfns[ii])
# labels.append(imglabels[ii])
#for image, label in zip(imgfns, imglabels):
# #img = np.load(image)
# #images.append(img)
# images.append(image)
# labels.append(label)
print(images)
print(labels)
print('********** cnt = ', cnt)
yield images, labels
train_gen = datagenerator(train_uxo_scrap, train_uxo_scrap_labels, batchsize=BS)
valid_gen = datagenerator(test_uxo_scrap, test_uxo_scrap_labels, batchsize=BS)
# train the network
H = model.fit_generator(
train_gen,
steps_per_epoch=NUM_TRAIN_IMAGES // BS,
validation_data=valid_gen,
validation_steps=NUM_TEST_IMAGES // BS,
epochs=NUM_EPOCHS)
Вот пример результатов, которые я получаю.Вы можете видеть, что каждый раз, когда он проходит через генератор, он выбирает одни и те же данные.Первая строка после «Epoch 1/10», имеет 5 имен файлов.Следующая строка имеет 5 меток (соответствует batchsize = 5).Например, вы можете видеть в каждом выводе для первого имени файла «... 508.npy» и т. Д. И метки одинаковы для каждой итерации.
Epoch 1/10
['C:\\Users\\jfhauris\\Documents\\xtemp\\ML GEO\\MLGeoCode\\FormattedDataStore\\uxo_48-81\\JBCC_Norm_Formatted_48-81_#508.npy', 'C:\\Users\\jfhauris\\Documents\\xtemp\\ML GEO\\MLGeoCode\\FormattedDataStore\\scrap_48-81\\JBCC_Norm_Formatted_48-81_#1218.npy', 'C:\\Users\\jfhauris\\Documents\\xtemp\\ML GEO\\MLGeoCode\\FormattedDataStore\\scrap_48-81\\JBCC_Norm_Formatted_48-81_#71.npy', 'C:\\Users\\jfhauris\\Documents\\xtemp\\ML GEO\\MLGeoCode\\FormattedDataStore\\scrap_48-81\\JBCC_Norm_Formatted_48-81_#551.npy', 'C:\\Users\\jfhauris\\Documents\\xtemp\\ML GEO\\MLGeoCode\\FormattedDataStore\\uxo_48-81\\JBCC_Norm_Formatted_48-81_#843.npy']
[1, 0, 0, 0, 1]
********** cnt = 5
['C:\\Users\\jfhauris\\Documents\\xtemp\\ML GEO\\MLGeoCode\\FormattedDataStore\\uxo_48-81\\JBCC_Norm_Formatted_48-81_#508.npy', 'C:\\Users\\jfhauris\\Documents\\xtemp\\ML GEO\\MLGeoCode\\FormattedDataStore\\scrap_48-81\\JBCC_Norm_Formatted_48-81_#1218.npy', 'C:\\Users\\jfhauris\\Documents\\xtemp\\ML GEO\\MLGeoCode\\FormattedDataStore\\scrap_48-81\\JBCC_Norm_Formatted_48-81_#71.npy', 'C:\\Users\\jfhauris\\Documents\\xtemp\\ML GEO\\MLGeoCode\\FormattedDataStore\\scrap_48-81\\JBCC_Norm_Formatted_48-81_#551.npy', 'C:\\Users\\jfhauris\\Documents\\xtemp\\ML GEO\\MLGeoCode\\FormattedDataStore\\uxo_48-81\\JBCC_Norm_Formatted_48-81_#843.npy']
[1, 0, 0, 0, 1]
********** cnt = 5
['C:\\Users\\jfhauris\\Documents\\xtemp\\ML GEO\\MLGeoCode\\FormattedDataStore\\uxo_48-81\\JBCC_Norm_Formatted_48-81_#508.npy', 'C:\\Users\\jfhauris\\Documents\\xtemp\\ML GEO\\MLGeoCode\\FormattedDataStore\\scrap_48-81\\JBCC_Norm_Formatted_48-81_#1218.npy', 'C:\\Users\\jfhauris\\Documents\\xtemp\\ML GEO\\MLGeoCode\\FormattedDataStore\\scrap_48-81\\JBCC_Norm_Formatted_48-81_#71.npy', 'C:\\Users\\jfhauris\\Documents\\xtemp\\ML GEO\\MLGeoCode\\FormattedDataStore\\scrap_48-81\\JBCC_Norm_Formatted_48-81_#551.npy', 'C:\\Users\\jfhauris\\Documents\\xtemp\\ML GEO\\MLGeoCode\\FormattedDataStore\\uxo_48-81\\JBCC_Norm_Formatted_48-81_#843.npy']
[1, 0, 0, 0, 1]
********** cnt = 5