segmenteverygrain icon indicating copy to clipboard operation
segmenteverygrain copied to clipboard

ValueError: You are trying to restore a checkpoint from a legacy Keras optimizer into a v2.11+ Optimizer, which can cause errors.

Open catkinson2022 opened this issue 2 years ago • 4 comments

I get the following error code while using code in google collab:

ValueError: You are trying to restore a checkpoint from a legacy Keras optimizer into a v2.11+ Optimizer, which can cause errors. Please update the optimizer referenced in your code to be an instance of tf.keras.optimizers.legacy.Optimizer, e.g.: tf.keras.optimizers.legacy.Adam.

Tried both instances with no solution to the problem.

The code used is shown below:

import pandas as pd import numpy as np import matplotlib.pyplot as plt import cv2 from skimage import measure from tensorflow.keras.optimizers.legacy import Adam from tensorflow.keras.preprocessing.image import load_img from importlib import reload import segmenteverygrain as seg from tqdm import trange

import tensorflow as tf model = seg.Unet() model.compile(optimizer= "Adam", loss=seg.weighted_crossentropy, metrics=["accuracy"]) model.load_weights('./checkpoints/seg_model')

The very last line "model.load_weights" is where the error is and not sure how to approach it.

catkinson2022 avatar Aug 30 '23 19:08 catkinson2022

I am facing same issue.

KeshavSingh29 avatar Jan 24 '24 08:01 KeshavSingh29

I am also getting this error and do not know how to solve it. If you figured out, can you please share with solution?

farzona05 avatar Feb 21 '24 15:02 farzona05

I am also getting this error and do not know how to solve it. If you figured out, can you please share with solution?

I guess this may be due to different versions of TensorFlow, but it seems that the author did not provide the TensorFlow version

lonelywanderer8 avatar Mar 22 '24 09:03 lonelywanderer8

Hi all, sorry for the slow response on this. I have uploaded an environment file that works for me on both Mac and Windows machines.

zsylvester avatar Mar 22 '24 11:03 zsylvester