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

Inadequate Validation for 'scale' Parameter in Model APIs. #64034

Open
Zoeeeeey opened this issue May 4, 2024 · 1 comment
Open

Inadequate Validation for 'scale' Parameter in Model APIs. #64034

Zoeeeeey opened this issue May 4, 2024 · 1 comment
Assignees

Comments

@Zoeeeeey
Copy link

Zoeeeeey commented May 4, 2024

bug描述 Describe the Bug

在一些提供构建模型的API中,设计了参数scale作为调整模型通道数的放缩因子。

因此,scale应该是一个非负数才使得放缩有意义。

但部分scale缺少参数验证,当输入负值时,程序仍然能够运行、输出。

这些API包括:

paddle.vision.models.MobileNetV2
paddle.vision.models.MobileNetV3Large
paddle.vision.models.MobileNetV3Small
paddle.vision.models.mobilenet_v2
paddle.vision.models.mobilenet_v3_large
paddle.vision.models.mobilenet_v3_small

以下简单的代码可以复现上述问题。
In MobileNetV3Large:

import paddle
from paddle.vision.models import MobileNetV3Large

# Build model
model = MobileNetV3Large(scale=-2.0)
x = paddle.rand([1, 3, 224, 224])
out = model(x)

print(out.shape)

Got:

[1, 1000]

Expected

# In `MobileNetV1`:
AssertionError: Expected every dim's size to be larger than 0, but the size of the 0-th dim is -64

# In `ShuffleNetV2`:
NotImplementedError: This scale size:[-2.0] is not implemented!

其他补充信息 Additional Supplementary Information

No response

@dyning
Copy link
Contributor

dyning commented May 7, 2024

对于一个具体模型,scale与网络结构非常相关,是有固定取值范围的,任意的scale,即使大于0,也可能导致网络不通。具体模型合适的scale范围,可以参看https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/docs/zh_CN/models/ImageNet1k/model_list.md 模型库中的模型名称,比如mobilenetv2的系列模型有6个,MobileNetV2_x0_25、MobileNetV2_x0_5、MobileNetV2_x0_75、MobileNetV2、MobileNetV2_x1_5、MobileNetV2_x2_0,则对应的scale取值为0.25,0.5,0.75,1.0,1.5,2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants