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 when evaluating model #132

Open
hassenhamdi opened this issue May 9, 2024 · 4 comments
Open

Error when evaluating model #132

hassenhamdi opened this issue May 9, 2024 · 4 comments

Comments

@hassenhamdi
Copy link

when I try to load model I get this error

Exception encountered: Could not locate class 'Policy'. Make sure custom classes are decorated with `@keras.saving.register_keras_serializable()`. Full object config: {'class_name': 'Policy', 'config': {'name': 'mixed_float16'}}
@leondgarse
Copy link
Owner

Which model are you trying to use? Also your TF version?

@hassenhamdi
Copy link
Author

Hi , thanks for the response ,
Here is my specs :

Operating System: Manjaro Linux
KDE Plasma Version: 5.27.11
KDE Frameworks Version: 5.115.0
Qt Version: 5.15.12
Kernel Version: 6.6.26-1-MANJARO (64-bit)
Graphics Platform: X11
Processors: 12 × Intel® Core™ i7-10750H CPU @ 2.60GHz
Memory: 11,5 GiB of RAM
Graphics Processor: Mesa Intel® UHD Graphics
Manufacturer: HP
Product Name: HP Pavilion Gaming Laptop 15-dk1xxx
System Version: Type1ProductConfigId

I have tensorflow 2.15.0

The issue is with the models listed under model backbone most of them give me the policy error , deserilisation error , 'unrecognized keyword argument passed to "layer" and AttributeError: 'str' object has no attribute 'convert_input'

,the other ported works fine ,

I did try on google colab to verify the result and gave me the same result .
Additional I want to note that the tensorflow_addon in eval.py raise error even when the package is installed "ModuleNotFoundError: No module named 'keras.src.engine' " so I just deleted the import line as it not used anyway.

@leondgarse
Copy link
Owner

Just tested EfficientNetV2B0 and r100, and they work find under TF 2.15.0, but I can reproduce your error with TF 2.16.0.

  • May try if TF_USE_LEGACY_KERAS=1 python evals.py ....., or export TF_USE_LEGACY_KERAS=1 works for you.
  • Updated for checking TF 2.16.0 with keras 3.0 version. Many things just broken with TF newest version...
  • If that doesn't work either, try build basic_model following Training part in the table, and load_weights, like:
    from keras_cv_attention_models import efficientnet
    import models
    basic_model = efficientnet.EfficientNetV2B0(input_shape=(112, 112, 3), num_classes=0)
    basic_model = models.buildin_models(basic_model, dropout=0, emb_shape=512, output_layer='GDC', bn_epsilon=1e-4, bn_momentum=0.9, scale=True, use_bias=False)
    
    basic_model.load_weights('xxxx.h5')

@hassenhamdi
Copy link
Author

I still getting the same error with backbone model , they need their backbone python files implementation and then loading weights as you suggested .
I I tried this on my personal using tf 2.15.0 and keras 3.2.0 and the error still appear using your update evals.py file that contain the checks .
Thanks to God , The ported model still work and I am highly satisfied with its result , so it is not really an issue for me , any way I just wanted to bring your attention on the matter thanks for your work .

Palestine 🇵🇸 will be "Free" from the river to the sea :) .

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

2 participants