Paddle paddle.vision.models.VGG()使用出错

zte4gxcn  于 2022-10-20  发布在  其他
关注(0)|答案(2)|浏览(191)
  • 版本、环境信息:

   1)PaddlePaddle版本:2.0rc
   2)环境:AI Studio高级版

paddle.vision.models.VGG() 的参数 num_classes 介绍写道:最后一个全连接层输出的维度。如果该值小于0,则不定义最后一个全连接层。默认值:1000。但是测试的时候发现如果该值小于等于0,都会报错


##### 示例代码 #####

import paddle
from paddle.vision.models import VGG
from paddle.vision.models.vgg import make_layers

vgg11_cfg = [64, 'M', 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M']

features = make_layers(vgg11_cfg)

vgg11 = VGG(features, num_classes=0)

x = paddle.rand([1, 3, 224, 224])
out = vgg11(x)

print(out.shape)

##### 错误信息  #####

---------------------------------------------------------------------------EnforceNotMet                             Traceback (most recent call last)<ipython-input-69-4ae249ce9371> in <module>
     10 
     11 x = paddle.rand([1, 3, 224, 224])
---> 12 out = vgg11(x)
     13 
     14 print(out.shape)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py in __call__(self, *inputs,**kwargs)
    827 
    828         with param_guard(self._parameters), param_guard(self._buffers):
--> 829             outputs = self.forward(*inputs,**kwargs)
    830 
    831         for forward_post_hook in self._forward_post_hooks.values():
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/vision/models/vgg.py in forward(self, x)
     72         x = self.avgpool(x)
     73         x = paddle.flatten(x, 1)
---> 74         x = self.classifier(x)
     75         return x
     76 
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py in __call__(self, *inputs,**kwargs)
    827 
    828         with param_guard(self._parameters), param_guard(self._buffers):
--> 829             outputs = self.forward(*inputs,**kwargs)
    830 
    831         for forward_post_hook in self._forward_post_hooks.values():
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/container.py in forward(self, input)
     84     def forward(self, input):
     85         for layer in self._sub_layers.values():
---> 86             input = layer(input)
     87         return input
     88 
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py in __call__(self, *inputs,**kwargs)
    827 
    828         with param_guard(self._parameters), param_guard(self._buffers):
--> 829             outputs = self.forward(*inputs,**kwargs)
    830 
    831         for forward_post_hook in self._forward_post_hooks.values():
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/nn/layer/common.py in forward(self, input)
    137     def forward(self, input):
    138         out = F.linear(
--> 139             x=input, weight=self.weight, bias=self.bias, name=self.name)
    140         return out
    141 
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/nn/functional/common.py in linear(x, weight, bias, name)
   1454         pre_bias = _varbase_creator(dtype=x.dtype)
   1455         core.ops.matmul(x, weight, pre_bias, 'transpose_X', False,
-> 1456                         'transpose_Y', False, "alpha", 1)
   1457         return dygraph_utils._append_bias_in_dygraph(
   1458             pre_bias, bias, axis=len(x.shape) - 1)
EnforceNotMet: 
----------------------
Error Message Summary:
----------------------
ExternalError:  Cublas error, CUBLAS_STATUS_INVALID_VALUE  (at /paddle/paddle/fluid/operators/math/blas_impl.cu.h:34)
  [operator < matmul > error]

还有一点想说的是,文档的描述和API内置文档的描述不一样。比如文档写的是 ”如果该值小于0,则不定义最后一个全连接层。“ ,但help()函数里面的描述是 ”If num_classes <=0, last fc layer will not be defined.“

vq8itlhq

vq8itlhq1#

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看 官网API文档常见问题历史IssueAI社区 来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

omhiaaxx

omhiaaxx2#

2.0rc版本的文档写着推荐别名:paddle.fill_constant,调用的时候AttributeError: module 'paddle' has no attribute 'fill_constant'

这么把文档放在版本前面的方法好像不太妥当吧???

相关问题