当前位置:网站首页>nn. Modulelist() and nn Sequential()

nn. Modulelist() and nn Sequential()

2022-06-10 00:52:00 msdhy

This article is a supplement to other blogs , It is recommended to refer to other blogs at the same time

Pytorch series 1: torch.nn.Sequential() Explain _xddwz The blog of -CSDN Blog _torch.nn.sequential

Pytorch Use nn.ModuleList() and nn.Sequential() Write a neural network model _ Pretending to be a bad Qianjun's blog -CSDN Blog

nn.ModuleList() Built components have no order , and nn.Sequential() Build in order .

nn.ModuleList() One of the advantages is stay forward when , The middle tier can have multiple inputs .

nn.Sequential() Run directly from top to bottom by default . In fact, you can also change the input in the middle layer , Take... Like a dictionary key value , But obviously not for Simple direct circulation .

nn.Modulelist()
...
def __init__(self, ...):
    self.op_num = 3
    self._op_trans = nn.ModuleList()
    self._op_trans.append(ISPMixedOp(C_out, C_out, width_mult_list=width_mult_list))
    for i in range(self.op_num-1):
        self._op_trans.append(ISPMixedOp(C_out, C_out, width_mult_list=width_mult_list))

def forward(self, x):
    output = self._op_trans[0](x, alphas, (ratio_fusion, ratio_out))
    for i in range(self.op_num-1):
        output = self._op_trans[i](output, alphas, (ratio_out, ratio_out))
    return output
...


nn.Sequential()
...
def __init__(self, ...):
    self.op_num = 3
    self._op_trans = nn.Sequential(OrderedDict([(str(i), ISPMixedOp(C_out, C_out, op_idx, stride=1, shift=shift)) for i in range(self.op_num)]))

def forward(self, x):
    output = self.op_trans(x)
...

原网站

版权声明
本文为[msdhy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206100022220853.html