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

add的广播机制输出shape问题 #5673

Open
ljbulesky opened this issue Sep 3, 2024 · 2 comments
Open

add的广播机制输出shape问题 #5673

ljbulesky opened this issue Sep 3, 2024 · 2 comments

Comments

@ljbulesky
Copy link

当add两个输入是[197, 768] 和 [1, 197, 768]的时候(N,C,H,W),使用广播机制,输出是【197, 768, 768】
而我需要的正确结果是[1, 197, 768]

请教一下,是不是二维与三维的广播出现了问题,
能否将
B2 = B.reshape(1, B.w, B.h, opt.workspace_allocator);
修改为
B2 = B.reshape(B.w, B.h, 1, opt.workspace_allocator);

@nihui
非常感谢

@nihui
Copy link
Member

nihui commented Sep 3, 2024

https://github.com/Tencent/ncnn/wiki/binaryop-broadcasting

支持的广播规则并没有这种情况?

@ljbulesky
Copy link
Author

ljbulesky commented Sep 3, 2024

感谢解答,意思是不支持这种情况吗?但是这应该属于常见情况吧,我修改成B2 = B.reshape(B.w, B.h, 1, opt.workspace_allocator);输出shape就对了。
为啥不按这种做个判断啊?
if (outdims == 3 && A.dims == 1)
{
if (A.w == B.c)
A2 = A.reshape(1, 1, A.w);
else // if (A.w == B.w)
A2 = A.reshape(A.w, 1, 1);
}
@nihui

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