Я пытаюсь обучить CNN, где у меня есть 3 источника данных.Другими словами, у меня есть 3 папки с изображениями, и мне нужно взять 1 изображение из каждой папки на каждом этапе обучения .
Я сделал следующий генератор:
def generator_three_imgs(index, batch_size=1):
anchor_paths = [r'C:\Users\sinthes\Desktop\AI_anaconda\face_recognition\dataset\train\E\Anchor',
r'C:\Users\sinthes\Desktop\AI_anaconda\face_recognition\dataset\train\T\Anchor']
positive_paths = [r'C:\Users\sinthes\Desktop\AI_anaconda\face_recognition\dataset\train\E\Positive',
r'C:\Users\sinthes\Desktop\AI_anaconda\face_recognition\dataset\train\T\Positive']
negative_paths = [r'C:\Users\sinthes\Desktop\AI_anaconda\face_recognition\dataset\train\E\Negative',
r'C:\Users\sinthes\Desktop\AI_anaconda\face_recognition\dataset\train\T\Negative']
generator1 = ImageDataGenerator()
generator2 = ImageDataGenerator()
generator3 = ImageDataGenerator()
anchor_train_batches = generator1.flow_from_directory(anchor_paths[index], target_size=(224, 224), batch_size=batch_size)
positive_train_batches = generator2.flow_from_directory(positive_paths[index], target_size=(224, 224), batch_size=batch_size)
negative_train_batches = generator3.flow_from_directory(negative_paths[index], target_size=(224, 224), batch_size=batch_size)
while True:
anchor_imgs, anchor_labels = anchor_train_batches.next()
positive_imgs, positive_labels = positive_train_batches.next()
negative_imgs, negative_labels = negative_train_batches.next()
input_imgs = np.append(anchor_imgs, positive_imgs, axis=0)
input_imgs = np.append(input_imgs, negative_imgs, axis=0)
labels = np.append(anchor_labels, positive_labels, axis=0)
labels = np.append(labels, negative_labels, axis=0)
yield input_imgs, labels
Итак, input_imgs - это (3, 224, 224, 3) размерный массив NumPy.И метки - это массив меток;и в этом случае в массиве будет 3 метки.
Затем я попытаюсь обучить его следующим образом:
model.fit_generator(generator_three_imgs(0),
steps_per_epoch=23, epochs=1, verbose=2)
Но он не может тренироваться.Ноутбук Jupyter падает, выдавая следующее сообщение:
The kernel appears to have died. It will restart automatically.
Что мне здесь делать?Неправильно ли пытаться создать мини-пакет, который извлекает свои изображения из разных каталогов с помощью трех разных генераторов Keras?
Заранее спасибо!