this code is not working on tensorflow 2.16.0+ version

58 Views Asked by At
checkpoint = ModelCheckpoint(
    './base.model',
    monitor='val_accuracy',
    verbose=1,
    save_best_only=True,
    mode='max',
    save_weights_only=False,
    save_frequency=1
)
earlystop = EarlyStopping(
    monitor='val_loss',
    min_delta=0.001,
    patience=30,
    verbose=1,
    mode='auto'
)

opt1 = tf.keras.optimizers.Adam()

callbacks = [checkpoint,earlystop]

this isn't working on tensorflow 2.16.1 but, working on 2.15.0 on google colab

how can i fix my code or how can i install tensorflow 2.15.0 ?

i tried pip install tensorflow=2.15.0 but, it's showing error

1

There are 1 best solutions below

0
mhenning On

The error in your comment says save_frequency is an unknown keyword for ModelCheckpoint. In the docs it shows that ModelCheckpoint expects save_freq as an argument. Also beware that if you set an integer for save_freq, it saves each x batches, not epochs. If you just want it to save every epoch, you can set

save_freq='epoch'

which is also the default. Why this woked in 2.15, I can not say, the docs for 2.15 also have save_freq in it. Maybe it was compatible with save_frequency in the background up to that point. It is better to use save_freq, as it is officially supported.

If you want to change a package version in colab, use

%pip install -U "tensorflow~=2.15.0"

% enables the pip command outside the python environment, -U upgrades (or in your case downgrades) existing versions and you need "" and either == or ~= for the version numbers. == for exact this version and ~= for, in this example "2.15.x", where x is the newest version.