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

加载预训练模型,动转静态图报错。 #204

Open
CPones opened this issue May 9, 2022 · 1 comment
Open

加载预训练模型,动转静态图报错。 #204

CPones opened this issue May 9, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@CPones
Copy link

CPones commented May 9, 2022

export_model.py

import paddle
from config import get_config
from cait import build_cait as build_model

# config files in ./configs/
config = get_config('./configs/cait_xxs24_224.yaml')
# build model
model = build_model(config)
# load pretrained weights
model_state_dict = paddle.load('./cait_xxs24_224.pdparams')
model.set_state_dict(model_state_dict)
# dynamic to static
input_spec = paddle.static.InputSpec([None, 3, 224, 224], 'float32', 'image')
model = paddle.jit.to_static(model, input_spec=[input_spec])
# save inferenc model
paddle.jit.save(model, "infer/cait_xxs24_224")

TypeError: In transformed code:

File "/home/aistudio/CaiT/cait.py", line 493, in forward
x = self.forward_features(x)
File "/home/aistudio/CaiT/cait.py", line 481, in forward_features
# Self-Attention blocks
File "/home/aistudio/CaiT/cait.py", line 373, in forward
x = self.attn(x)
File "/home/aistudio/CaiT/cait.py", line 228, in forward
    B, H, C = x.shape # H: num_patches
    qkv = self.qkv(x).chunk(3, axis=-1)
    q, k, v = map(self.transpose_multihead, qkv) #[B, num_heads, num_patches, single_head_dim]
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE

    q = q * self.scale

File "/home/aistudio/CaiT/cait.py", line 220, in transpose_multihead
new_shape = x.shape[:-1] + [self.num_heads, self.dim_head]

TypeError: can only concatenate tuple (not "list") to tuple
@xperzy xperzy self-assigned this May 9, 2022
@xperzy xperzy added the bug Something isn't working label May 9, 2022
@xperzy
Copy link
Collaborator

xperzy commented May 9, 2022

Thanks for the issue.
We are fixing this problem now and will update once finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants