LAION-AI / CLIP-based-NSFW-Detector

Other
299 stars 28 forks source link

Colab demo notebook raises exception #9

Open crclark opened 1 year ago

crclark commented 1 year ago
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[<ipython-input-2-969c26cf53fe>](https://localhost:8080/#) in <module>
     39     return loaded_model
     40 
---> 41 safety_model = load_safety_model()
     42 
     43 

2 frames
[<ipython-input-2-969c26cf53fe>](https://localhost:8080/#) in load_safety_model(clip_model)
     35             zip_ref.extractall(cache_folder)
     36 
---> 37     loaded_model = load_model(model_dir, custom_objects=ak.CUSTOM_OBJECTS)
     38 
     39     return loaded_model

[/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py](https://localhost:8080/#) in error_handler(*args, **kwargs)
     68             # To get the full stack trace, call:
     69             # `tf.debugging.disable_traceback_filtering()`
---> 70             raise e.with_traceback(filtered_tb) from None
     71         finally:
     72             del filtered_tb

[/usr/local/lib/python3.8/dist-packages/keras/saving/legacy/serialization.py](https://localhost:8080/#) in class_and_config_for_serialized_keras_object(config, module_objects, custom_objects, printable_module_name)
    383     )
    384     if cls is None:
--> 385         raise ValueError(
    386             f"Unknown {printable_module_name}: '{class_name}'. "
    387             "Please ensure you are using a `keras.utils.custom_object_scope` "

ValueError: Unknown optimizer: 'Custom>AdamWeightDecay'. Please ensure you are using a `keras.utils.custom_object_scope` and that this object is included in the scope. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.
PeterAdam2015 commented 1 year ago

Same Problems, seem keras can't recognize the customized layer defined in python scripts.

meigaoms commented 1 year ago

Same here. Could this be related to Keras version?

SingL3 commented 1 year ago

Same here, any solutions?

MSusik commented 1 year ago

Solution: Downgrade autokeras to 1.0.20

SingL3 commented 1 year ago

@MSusik Tried it already in colab demo.

ValueError                                Traceback (most recent call last)
[<ipython-input-3-969c26cf53fe>](https://localhost:8080/#) in <cell line: 41>()
     39     return loaded_model
     40 
---> 41 safety_model = load_safety_model()
     42 
     43 

3 frames
[/usr/local/lib/python3.9/dist-packages/autokeras/keras_layers.py](https://localhost:8080/#) in __init__(self, learning_rate, beta_1, beta_2, epsilon, amsgrad, weight_decay_rate, include_in_weight_decay, exclude_from_weight_decay, name, **kwargs)
    317         **kwargs
    318     ):
--> 319         super(AdamWeightDecay, self).__init__(
    320             learning_rate, beta_1, beta_2, epsilon, amsgrad, name, **kwargs
    321         )

ValueError: decay is deprecated in the new Keras optimizer, pleasecheck the docstring for valid arguments, or use the legacy optimizer, e.g., tf.keras.optimizers.legacy.AdamWeightDecay.
MSusik commented 1 year ago

Then you might want play with versions of other packages. For me it works well with tf 2.9

SingL3 commented 1 year ago
!pip install clip-anytorch autokeras==1.0.20 tensorflow==2.9

works.

HCA97 commented 1 year ago

Hi, had a similar problem as well, and installing autokeras==1.0.20 tensorflow==2.9 didn't solve my problem. So I converted the models to PyTorch following issue #7 now I can run all the NSFW detectors using PyTorch only.