justRandomLearner
justRandomLearner

Reputation: 316

How to add descriptions to keras model and load it from saved model?

I train and save CNN keras model as it follows:

callback = EarlyStopping(monitor=monitor, mode='auto', patience=patience)
mc = ModelCheckpoint('Models/CNN.h5', monitor=monitor, verbose=1, save_best_only=True)

history = model.fit(
    train_ds,
    validation_data=val_ds,
    epochs=EPOCHS,
    callbacks=[callback, mc]
)

Once training is completed, I would like to add a description to the saved model similar to "This model trained with 1000 dogs/cats images". Then, when I load the model, I would like to load this description somehow like that:

model = load_model(Models/CNN.h5)
print(model.description())
"This model trained with 1000 dogs/cats images"

Is it possible? if yes, how?

Upvotes: 0

Views: 84

Answers (1)

dusty_keyboard
dusty_keyboard

Reputation: 61

A work around could be to use the model name feature.

model = tf.keras.models.Sequential([tf.keras.layers.Dense(10,activation='relu',input_shape=(100,))],name='This model trained with 1000 dogs/cats images')

I think the limit on the name string is 1024 characters...

Upvotes: 0

Related Questions