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

Unknow error #2

Open
eftekhar-hossain opened this issue Jan 13, 2022 · 3 comments
Open

Unknow error #2

eftekhar-hossain opened this issue Jan 13, 2022 · 3 comments

Comments

@eftekhar-hossain
Copy link

Hello
When I add the ChannelAttention2D layer it trains correctly. However when I try to load the model it through an exception that -

Unknown layer: ChannelAttention2D.

If you provide a full keras notebook then it will be very helpful for us.

@vinayak19th
Copy link
Owner

Yeah the issue would be custom object loading in tensorflow. You'll have to load the model like this

from visual_attention import PixelAttention2D , ChannelAttention2D
loaded_model = tf.keras.models.load_model('/tmp/model',custom_objects={"ChannelAttention2D":ChannelAttention2D})

Lemme know if that fixes the issue

@rubenfonnegra
Copy link

rubenfonnegra commented Feb 24, 2022

Dear Vinayak
I'm having a similar issue when trying to load a saved model. I'm loading it as follows
custom_obj = {"PixelAttention2D":PixelAttention2D}
model = tensorflow.keras.load_model('model.h5', custom_objects = custom_obj)

However, I'm obtaining the following error:
File "/home/user/venvs/venv/lib/python3.8/site-packages/keras/engine/base_layer.py", line 784, in from_config
return cls(**config)
TypeError: __init__() missing 1 required positional argument: 'nf'
I think it's related to the input parameter requiered to use the PixelAttention2D layer, despite I haven't figured out how to fix it. Hope you could help.
Regards!

@mustofahisyam
Copy link

mustofahisyam commented Aug 26, 2023

Dear Vinayak I'm having a similar issue when trying to load a saved model. I'm loading it as follows custom_obj = {"PixelAttention2D":PixelAttention2D} model = tensorflow.keras.load_model('model.h5', custom_objects = custom_obj)

However, I'm obtaining the following error: File "/home/user/venvs/venv/lib/python3.8/site-packages/keras/engine/base_layer.py", line 784, in from_config return cls(**config) TypeError: __init__() missing 1 required positional argument: 'nf' I think it's related to the input parameter requiered to use the PixelAttention2D layer, despite I haven't figured out how to fix it. Hope you could help. Regards!

I'm having the same issue. What i did was modify the init function and give the nf argument a default value which is the value of the CNN filter number i used.
def __init__(self, nf=32, **kwargs):

and comment or remove this line:
# config.update({"Att_filters": self.nf})

And it worked.

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

4 participants