首页 PaddleHub 帖子详情
PaddleHub加载迁移学习模型失败
收藏
快速回复
PaddleHub 问答迁移学习 816 5
PaddleHub加载迁移学习模型失败
收藏
快速回复
PaddleHub 问答迁移学习 816 5

PaddleHub加载迁移学习模型失败

import paddle
import paddlehub as hub

if __name__ == '__main__':

    model = hub.Module(name='resnet50_vd_imagenet_ssld', label_list=fishclass, load_checkpoint='img_classification_ckpt/')
    result = model.predict(['00001.png']) #data/Fish_Dataset/Fish_Dataset/Black Sea Sprat/
    print(result)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/tmp/ipykernel_139/3483781583.py in 
      4 if __name__ == '__main__':
      5 
----> 6     model = hub.Module(name='resnet50_vd_imagenet_ssld', label_list=fishclass, load_checkpoint='img_classification_ckpt/')
      7     result = model.predict(['00001.png']) #data/Fish_Dataset/Fish_Dataset/Black Sea Sprat/
      8     print(result)

/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/module/module.py in __new__(cls, name, directory, version, source, update, branch, **kwargs)
    170             if name:
    171                 module = cls.init_with_name(
--> 172                     name=name, version=version, source=source, update=update, branch=branch, **kwargs)
    173                 CacheUpdater("update_cache", module=name, version=version).start()
    174             elif directory:

/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/module/module.py in init_with_name(cls, name, version, source, update, branch, **kwargs)
    279 
    280         user_module_cls.directory = directory
--> 281         return user_module_cls(**kwargs)
    282 
    283     @classmethod

~/.paddlehub/modules/resnet50_vd_imagenet_ssld/module.py in __init__(self, label_list, load_checkpoint)
    203         num_filters = [64, 128, 256, 512]
    204 
--> 205         self.conv1_1 = ConvBNLayer(num_channels=3, num_filters=32, filter_size=3, stride=2, act='relu', name="conv1_1")
    206         self.conv1_2 = ConvBNLayer(num_channels=32, num_filters=32, filter_size=3, stride=1, act='relu', name="conv1_2")
    207         self.conv1_3 = ConvBNLayer(num_channels=32, num_filters=64, filter_size=3, stride=1, act='relu', name="conv1_3")

~/.paddlehub/modules/resnet50_vd_imagenet_ssld/module.py in __init__(self, num_channels, num_filters, filter_size, stride, groups, is_vd_mode, act, name)
     55             groups=groups,
     56             weight_attr=ParamAttr(name=name + "_weights"),
---> 57             bias_attr=False)
     58         if name == "conv1":
     59             bn_name = "bn_" + name

/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/nn/layer/conv.py in __init__(self, in_channels, out_channels, kernel_size, stride, padding, dilation, groups, padding_mode, weight_attr, bias_attr, data_format)
    654             weight_attr=weight_attr,
    655             bias_attr=bias_attr,
--> 656             data_format=data_format)
    657 
    658     def forward(self, x):

/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/nn/layer/conv.py in __init__(self, in_channels, out_channels, kernel_size, transposed, dims, stride, padding, padding_mode, output_padding, dilation, groups, weight_attr, bias_attr, data_format)
    133             shape=filter_shape,
    134             attr=self._param_attr,
--> 135             default_initializer=_get_default_param_initializer())
    136         self.bias = self.create_parameter(
    137             attr=self._bias_attr, shape=[self._out_channels], is_bias=True)

/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py in create_parameter(self, shape, attr, dtype, is_bias, default_initializer)
    422             temp_attr = None
    423         return self._helper.create_parameter(temp_attr, shape, dtype, is_bias,
--> 424                                              default_initializer)
    425 
    426     @deprecated(

/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layer_helper_base.py in create_parameter(self, attr, shape, dtype, is_bias, default_initializer, stop_gradient, type)
    370                     "In dygraph mode, the name of parameter can't be same."
    371                     "Please check the parameter attr value passed to self.create_parameter or "
--> 372                     "constructor of dygraph Layers".format(attr.name))
    373             return self.main_program.global_block().create_parameter(
    374                 dtype=dtype,

ValueError: parameter name [conv1_1_weights] have be been used. In dygraph mode, the name of parameter can't be same.Please check the parameter attr value passed to self.create_parameter or constructor of dygraph Layers

搞不定啊。

0
收藏
回复
全部评论(5)
时间顺序
JavaRoom
#2 回复于2021-12

环境:

paddlefsl 1.0.0
paddlehub 2.0.4
paddlenlp 2.1.1
paddlepaddle-gpu 2.2.0.post101
tb-paddle 0.3.6

0
回复
DeepGeGe
#3 回复于2021-12

参数名字冲突了,可以手动的去源码里面把名字修改一下:

self.conv1_1 = ConvBNLayer(num_channels=3, num_filters=32, filter_size=3, stride=2, act='relu', name="conv1_1")

0
回复
JavaRoom
#4 回复于2021-12
参数名字冲突了,可以手动的去源码里面把名字修改一下: self.conv1_1 = ConvBNLayer(num_channels=3, num_filters=32, filter_size=3, stride=2, act='relu', name="conv1_1")
展开

改train.py吗?不知道改成啥

0
回复
JavaRoom
#5 回复于2021-12
参数名字冲突了,可以手动的去源码里面把名字修改一下: self.conv1_1 = ConvBNLayer(num_channels=3, num_filters=32, filter_size=3, stride=2, act='relu', name="conv1_1")
展开

不知道改哪儿啊

0
回复
DeepGeGe
#6 回复于2021-12
不知道改哪儿啊

什么名字冲突改什么呀,报错的那一行,模型手动给某一个参数添加了名字,将响应的换一个别的额不冲突的名字。

0
回复
需求/bug反馈?一键提issue告诉我们
发现bug?如果您知道修复办法,欢迎提pr直接参与建设飞桨~
在@后输入用户全名并按空格结束,可艾特全站任一用户