简体   繁体   中英

Keras: model.fit() and model.fit_generator() return history objects. How do I get Keras models?

I'm doing a guided RNN project. I'm using a textbook to guide me but I'm doing a lot of things on my own. I've encountered an issue from the fact that history, below, is not a Keras model but rather a history object.

from keras.models import Sequential
from keras import layers
from keras.optimizers import RMSprop
from keras.layers import LSTM

model = Sequential()
model.add(layers.Flatten(input_shape=(7,data.shape[-1])))
model.add(layers.Dense(32,activation='relu'))
model.add(layers.Dense(1))

val_steps = 99999//20
model.compile(optimizer=RMSprop(),loss='mae')
history = model.fit_generator(trainGen,
                             steps_per_epoch=250,
                             epochs=20,
                             validation_data=valGen,
                             validation_steps=val_steps,
                             use_multiprocessing=False)

The error occurs when I type the below due to the fact that history is a History object. Is there a way to extract a keras object? Thank you in advance.

predictions = history.predict(testData)

Sorry I can't comment yet. Why are you calling predict on the history and not the model itself?

predictions = model.predict(testData)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM