keras-cv
keras-cv copied to clipboard
bug: Cannot save model from model.save(PATH)
I trained the model with this tutorial. At the end, the WEIGHTS are saved, but I need to save the MODEL. When I save the MODEL I get the error:
ValueError: Model <keras_cv.models.object_detection.retina_net.retina_net.RetinaNet object at 0x00000287F451B6D0> cannot be saved either because the input shape is not available or because the forward pass of the model is not defined.To define a forward pass, please override Model.call(). To specify an input shape, either call build(input_shape)directly, or call the model on actual data usingModel(), Model.fit(), or Model.predict(). If you have a custom training step, please make sure to invoke the forward pass in train step through Model.call, i.e. model(inputs), as opposed to model.call().
Next, I plan to convert the MODEL to ONNX format and use it in OpenCV.
The error message is correct! Your model is not built yet.
To specify an input shape, either call build(input_shape) directly, or call the model on actual data using Model(), Model.fit(), or Model.predict().
@jbischof Could you take a look and tell me what I'm doing wrong?

The behavior of the save() method changes after a call to predict()

WARNING:absl:Found untraced functions such as retina_net_label_encoder_layer_call_fn, retina_net_label_encoder_layer_call_and_return_conditional_losses, anchor_generator_layer_call_fn, anchor_generator_layer_call_and_return_conditional_losses, multi_class_non_max_suppression_layer_call_fn while saving (showing 5 of 110). These functions will not be directly callable after loading.
Hi @slavazhulanov, I tried to run the colab tutorial and I was able to save my model. Could you post your colab here, so that I can take a full look at you code?
Hello @lb-97 I have attached a link here. The tutorial uses .save_weights() and my error is related to .save()
In callbacks, try to change save_weights_only=True to False. It should work then after rerunning the entire code. @slavazhulanov
@ID6109 it didn't change anything. You can try it yourself on the link to Google Colab
@slavazhulanov Try to save the model as model.save(CHECKPOINT_PATH, include_optimizer = None, save_traces = None)
Closing as stale -- it seems like KerasCV is WAI in this case
having the same issue
when i model.save as .h5/.keras i get:
ValueError: Unable to create dataset (name already exists)
when i model.save as .tf , it saves the model, but when loading it i get:
ValueError: `RetinaNet` does not accept a `loss` to `compile()`. Instead, please pass `box_loss` and `classification_loss`. `loss` will be ignored during training.
what is the problem? what is the correct way to save and load the model?
@Aillian can you send along a colab gist replicating your issue?