博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Pytorch-nn.Module-modules()
阅读量:7116 次
发布时间:2019-06-28

本文共 537 字,大约阅读时间需要 1 分钟。

测试代码:

import torch.nn as nn

class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.conv1 = nn.Conv2d(10, 20, 4)
        self.conv2 = nn.Conv2d(20, 40, 4)
model = Model()
for m in model.modules():
    print(m)

 

结果:

Model(  (conv1): Conv2d(10, 20, kernel_size=(4, 4), stride=(1, 1))  (conv2): Conv2d(20, 40, kernel_size=(4, 4), stride=(1, 1)))Conv2d(10, 20, kernel_size=(4, 4), stride=(1, 1))Conv2d(20, 40, kernel_size=(4, 4), stride=(1, 1))

结论:

 modules()返回一个包含 当前模型 所有模块的迭代器。

转载于:https://www.cnblogs.com/leebxo/p/10096686.html

你可能感兴趣的文章