How i can extracte x_train and y_train from train_generator?

梦想与她 提交于 2020-04-30 11:42:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!