Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error saving the model in Section 8 #545

Open
ivanthecrazy opened this issue Apr 28, 2023 · 6 comments
Open

Error saving the model in Section 8 #545

ivanthecrazy opened this issue Apr 28, 2023 · 6 comments

Comments

@ivanthecrazy
Copy link

Section 8, video 189.
I'm getting this error when saving the model:

model.save("drive/MyDrive/101_food_classes_10_percent_saved_big_dog_model")
WARNING:absl:Found untraced functions such as _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op while saving (showing 5 of 81). These functions will not be directly callable after loading.
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
[<ipython-input-17-7b06e6431aba>](https://localhost:8080/#) in <cell line: 1>()
----> 1 model.save("drive/MyDrive/101_food_classes_10_percent_saved_big_dog_model")

2 frames
[/usr/lib/python3.10/json/encoder.py](https://localhost:8080/#) in iterencode(self, o, _one_shot)
    255                 self.key_separator, self.item_separator, self.sort_keys,
    256                 self.skipkeys, _one_shot)
--> 257         return _iterencode(o, 0)
    258 
    259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,

TypeError: Unable to serialize [2.0896919 2.1128857 2.1081853] to JSON. Unrecognized type <class 'tensorflow.python.framework.ops.EagerTensor'>.

I found out that tf downgrade to 2.9 should do the job, but I'm unable to install 2.9 on colab.

@ostadnavid
Copy link

ostadnavid commented Apr 29, 2023

I think this is because your model includes custom layers or functions that are not tracked by Keras.
try saving with h5 format:

model.save("saved_model", save_format='tf')

or you can save weight and biases and then import them

model.save_weights("model_weights.h5")

model.load_weights("model_weights.h5")

@ivanthecrazy
Copy link
Author

@ostadnavid I already opened another issue with saving weights and biases :)

@mrdbourke
Copy link
Owner

mrdbourke commented May 12, 2023

Hi Ivan, can you link to the notebook you're working with here?

I'm currently working through trying to find a fix.

Seems to be older versions of TensorFlow working (e.g. 2.9.0) but later versions are causing errors with tf.keras.applications.efficientnet models.

I see you posted here as well: #544 (more info here)

Thank you for that, will try to sort both of these out.

@m-gopichand
Copy link
Contributor

Hi @ivanthecrazy , this may help , The problem is with the models rescaling layer.
At the top:
IMAGENET_STDDEV_RGB = [0.229, 0.224, 0.225]
IMAGENET_STDDEV_RGB = [1/math.sqrt(i) for i in IMAGENET_STDDEV_RGB]

Then on build just do:
x = layers.Rescaling(IMAGENET_STDDEV_RGB)(x)

@Onturk89
Copy link

!pip install tensorflow==2.9
pip install --force-reinstall -v protobuf==3.20.3

from tensorflow.keras import mixed_precision
mixed_precision.set_global_policy(policy="float32") # set global policy to mixed precision

@ivanthecrazy
Copy link
Author

Thank you guys, with correct downgrade it seems to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants