DenseNet学习知识点记录

知识点一:self.features = nn.Sequential(OrderedDict([])这里问什么要在nn.Sequential()中加入python中的一个有序字典呢?

看一下**nn.Sequential()**的源码,发现原来使用OrderedDict是nn.Sequential()的两种用法中的其中一种而已,该方法可以实现对与每个模块的key值进行重新命名。如过不使用OrderedDict的话,会按照加入到nn.Sequential()中每个模块的索引(如0,1,2,3…)等等来作为每一个模块的key(键)。自然通过两种方式生成的模型中的每个模块单独进行索引时使用的键也就不一样了。
参考连接

class Sequential(Module):
    r"""A sequential container.
    Modules will be added to it in the order they are passed in the constructor.
    Alternatively, an ordered dict of modules can also be passed in.

    To make it easier to understand, here is a small example::

        # Example of using Sequential
        model = nn.Sequential(
                  nn.Conv2d(1,20,5),
                  nn.ReLU(),
                  nn.Conv2d(20,64,5),
                  nn.ReLU()
                )

        # Example of using Sequential with OrderedDict
        model = nn.Sequential(OrderedDict([
                  ('conv1', nn.Conv2d(1,20,5)),
                  ('relu1', nn.ReLU()),
                  ('conv2', nn.Conv2d(20,64,5)),
                  ('relu2', nn.ReLU())
                ]))
    """

    @overload
    def __init__(self, *args: Module) -> None:
        ...

    @overload
    def __init__(self, arg: 'OrderedDict[str, Module]') -> None:
        ...

    def __init__(self, *args: Any):
        super(Sequential, self).__init__()
        if len(args) == 1 and isinstance(args[0], OrderedDict):
            for key, module in args[0].items():
                self.add_module(key, module)
        else:
            for idx, module in enumerate(args):
                self.add_module(str(idx), module)

知识点二:densenet网络模型大小及参数量都小于resnet,,但是训练的时间要更久呢?

该网络在参数和模型大小方面小于ResNet但在运行效率方面却不如ResNet,主要由于DenseNet网络把上一层的特征图与下一层的特征图在维度上进行累加,这样虽然提高了网络提取特征的能力但会导致内存访问成本随网络深度呈二次增长,进而导致计算开销和更多能耗。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值