class BasicBlock(nn.Module): def __init__(self, net_depth, dim, kernel_size=3, conv_layer=ConvLayer, norm_layer=nn.BatchNorm2d, gate_act=nn.Sigmoid): super().__init__() self.norm = norm_layer(dim) self.conv = conv_layer(net_depth, dim, kernel_size, gate_act) def forward(self, x): identity = x x = self.norm(x) x = self.conv(x) x = identity + x return x转化为Paddle框架写法
时间: 2023-03-10 15:43:59 浏览: 182
Python RuntimeError: thread.__init__() not called解决方法
class BasicBlock(fluid.dygraph.Layer):
def __init__(self, net_depth, dim, kernel_size=3, conv_layer=ConvLayer, norm_layer=nn.BatchNorm2d, gate_act=fluid.dygraph.nn.functional.sigmoid):
super(BasicBlock, self).__init__()
self.norm = norm_layer(dim)
self.conv = conv_layer(net_depth, dim, kernel_size, gate_act)
def forward(self, x):
identity = x
x = self.norm(x)
x = self.conv(x)
x = identity + x
return x
阅读全文