问题
In my CNN model I want to extract X_train and y_train from train_generator. I want to use ensemble learning, bagging and boosting to evaluate the model. the main challenge is how i can extract X_train and y_train from train_generator using python language.
history=model.fit_generator(train_generator,
steps_per_epoch=num_of_train_samples // batch_size,
epochs=10, validation_data=validation_generator,
validation_steps=num_of_val_samples // batch_size,
callbacks=callbacks)
回答1:
Well, first of all you didn't write the piece of code declaring this train_generator.
Since it seems to be a generator in the keras way, you should be accessing X_train and y_train by looping through train_generator.
This mean that train_generator[0] will give you the first batch of pairs of X_train/y_train.
x_train = []
y_train = []
for x, y in train_generator:
x_train.append(x)
y_train.append(y)
来源:https://stackoverflow.com/questions/59682664/how-i-can-extracte-x-train-and-y-train-from-train-generator