Hi, I am trying to cache a Keras model and keep getting an error. Here is the code:
@st.cache(allow_output_mutation=True) def add_model(): model = load_model('models/keras/model.h5') return model @st.cache(allow_output_mutation=True) def add_weights(model): model.load_weights('models/keras/weights.h5') return model st.sidebar.text('Loading data...') model = add_model() with open('models/keras/architecture.json') as f: model = model_from_json(f.read()) model = add_weights(model) st.sidebar.text('Loading Done!')
The page doesn’t seem to work any faster and I keep getting this error:
Cached function mutated its input arguments
When decorating a function with
@st.cache , the arguments should not be mutated inside the function body, as that breaks the caching mechanism. Please update the code of
add_weights to bypass the mutation.
See the Streamlit docs for more info.
I don’t see where anything could be changing inside the “add_weights” function. I’d appreciate any insight, thanks!