栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

DenseNet学习知识点记录

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

DenseNet学习知识点记录

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

知识点一: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)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/920603.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号