tensorflow/decision-forests

Save and load model with tunning in automatic_tuning_colab.ipynb

5xcor opened this issue · 4 comments

5xcor commented

Hey,

I tried the example:
automatic_tuning_colab.ipynb

and if I put at the end
tuned_model.save('Linear_test') #,save_format='tf'

I got the following error.

WARNING:tensorflow:Model'sinit()arguments contain non-serializable objects. Please implement aget_config()method in the subclassed Model for proper saving and loading. Defaulting to empty config. WARNING:tensorflow:Model'sinit()arguments contain non-serializable objects. Please implement aget_config()method in the subclassed Model for proper saving and loading. Defaulting to empty config. WARNING:tensorflow:Model'sinit()arguments contain non-serializable objects. Please implement aget_config()method in the subclassed Model for proper saving and loading. Defaulting to empty config. WARNING:tensorflow:Model'sinit()arguments contain non-serializable objects. Please implement aget_config()method in the subclassed Model for proper saving and loading. Defaulting to empty config. INFO:tensorflow:Assets written to: Linear_test/assets INFO:tensorflow:Assets written to: Linear_test/assets WARNING:tensorflow:Model'sinit()arguments contain non-serializable objects. Please implement aget_config()method in the subclassed Model for proper saving and loading. Defaulting to empty config. WARNING:tensorflow:Model'sinit()arguments contain non-serializable objects. Please implement aget_config()method in the subclassed Model for proper saving and loading. Defaulting to empty config. WARNING:tensorflow:Model'sinit()arguments contain non-serializable objects. Please implement aget_config()method in the subclassed Model for proper saving and loading. Defaulting to empty config. WARNING:tensorflow:Model'sinit()arguments contain non-serializable objects. Please implement aget_config()method in the subclassed Model for proper saving and loading. Defaulting to empty config.

I tried to solve it but my knowledge is not enough. After a week of trying I give up. Does anyone know a smarter way to add auto-tuning to the Save and Load the Model?

rstz commented

Hi,
thank you for reporting this issue. I haven't been able to reproduce it immediately, could you please clarify what you are trying to achieve?

For me, adding the following code at the end of the tutorial returns True, i.e., the tuned model can be saved and loaded back, with the same predictions given by the saved an the loaded model.

tuned_model.save('/tmp/tuned_model') #,save_format='tf'

# Load
loaded_tuned_model = tf.keras.models.load_model('/tmp/tuned_model')

# Run predictions
tuned_model_pred = tuned_model.predict(test_ds)
loaded_tuned_model_pred = loaded.predict(test_ds)
# Check if the predictions are the same
assert(tuned_model_pred == loaded_tuned_model_pred).all())

The Tensorflow warnings are not consequential AFAICT.

As all TF-DF models, the loaded models behave differently from the original models (see known issues for details)

5xcor commented

I opened the example on COLAB and went step by step. no editing.
Snímek obrazovky 2023-09-11 v 7 41 11
I added up to line 14. the same error again :(

https://colab.research.google.com/drive/1hnFOfu0VQssR2q28TT4_FpPUrsRZBAdS?usp=sharing

rstz commented

Hi, in your screenshot, I'm seeing some warnings but no errors . In fact, both cells completed successfully. The warnings do not impact the main usability of the model as far as I can tell. Is there any issue other than the warnings printing on screen?

rstz commented

Closing this, feel free to reopen if there is additional information.