首页 Paddle框架 帖子详情
dygraph.load_persistables的参数数量和model.state_dict()数量不一致
收藏
快速回复
Paddle框架 问答深度学习 669 1
dygraph.load_persistables的参数数量和model.state_dict()数量不一致
收藏
快速回复
Paddle框架 问答深度学习 669 1

dygraph.load_persistables的参数数量

model.state_dict()的数量不一致

图片

问题描述:按理说数量应该是一致的,打印state.dict,发现没有conv的参数,只有bn的参数。conv和BN都在一个类里面。


class ConvBN(fluid.dygraph.Layer):

    def __init__(self,
                 name_scope,
                 num_filters,
                 filter_size=3,
                 stride=1,
                 dilation=1,
                 act=None,
                 dtype='float32',
                 bias_attr=False):
        super(ConvBN, self).__init__(name_scope)

        if dilation != 1:
            padding = dilation
        else:
            padding = (filter_size - 1) // 2

        self._conv = fluid.dygraph.Conv2D(name_scope,
                                          num_filters=num_filters,
                                          filter_size=filter_size,
                                          stride=stride,
                                          padding=padding,
                                          dilation=dilation,
                                          act=None,
                                          dtype=dtype,
                                          bias_attr=bias_attr if bias_attr is False else fluid.ParamAttr(
                                              name='bias'),
                                          param_attr=fluid.ParamAttr(
                                              name='weight')
                                          )
        self._bn = fluid.dygraph.BatchNorm(name_scope,
                                           num_channels=num_filters,
                                           act=act,
                                           dtype=dtype,
                                           momentum=0.9,
                                           epsilon=1e-5,
                                           bias_attr=fluid.ParamAttr(
                                               name='bias'),
                                           param_attr=fluid.ParamAttr(
                                               name='weight'),
                                           moving_mean_name='running_mean',
                                           moving_variance_name='running_var'
                                           )

    def forward(self, inputs):
        x = self._conv(inputs)
        x = self._bn(x)
        return x

0
收藏
回复
全部评论(1)
时间顺序
AIStudio792182
#2 回复于2019-11

初始化在前向计算

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