Hi,
I’m getting this error message.
“ValueError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you’re on Streamlit Cloud, click on ‘Manage app’ in the lower right of your app).”
“WARNING:absl:Error in loading the saved optimizer state. As a result, your model is starting with a freshly initialized optimizer. 2024-03-23 02:25:35.418 Uncaught app exception”
Thank you for the extra info. So it seems the error is suggesting there is a problem with the optimizer’s configuration stored within the model1.h5. You could use try-except blocks around the model download code to get a better error message and also use caching to manage disk resources like so:
def download_model(url, file_path):
# Function to download the model file if it doesn't exist
if not os.path.isfile(file_path):
subprocess.run([f'curl --output {file_path} "{url}"'], shell=True)
@st.cache_resource
def load_model(model_path):
# Attempt to load model with error handling & caching
try:
model = tf.keras.models.load_model(model_path, compile=False)
return model
except Exception as e:
print(f"Error loading model {model_path}: {e}")
return None
# Download and load the models
download_model("https://media.githubusercontent.com/media/ShyamaleeT/glaucocare/main/sep_5.h5", "model.h5")
download_model("https://media.githubusercontent.com/media/ShyamaleeT/glaucocare/main/models/OD_Segmentation.h5", "models/model1.h5")
download_model("https://media.githubusercontent.com/media/ShyamaleeT/glaucocare/main/models/OC_Segmentation.h5", "models/model2.h5")
model = load_model("model.h5")
model1 = load_model("models/model1.h5")
model2 = load_model("models/model2.h5")
Hello @tonykip
Thank you for the reply. I added the above code exactly as it is. However, I am still encountering an error. Could you please take another look?
Thanks for the logs. So, the inputs parameter in the Model constructor is receiving a list of tensors, not just tensors. Ensure that you are passing just the tensor or a list of tensors directly, not a list within a list. Try changing this line:
I appreciate your help, but unfortunately, that solution doesn’t resolve the last error in the logs. However, I’m getting the same error, WARNING:absl:Compiled the loaded model, but the compiled metrics have yet to be built. model.compile_metrics will be empty until you train or evaluate the model. WARNING:absl:Error in loading the saved optimizer state. As a result, your model is starting with a freshly initialized optimizer.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.