import paddle import math from x2paddle.op_mapper.onnx2paddle import onnx_custom_layer as x2paddle_nn class ONNXModel(paddle.nn.Layer): def __init__(self): super(ONNXModel, self).__init__() self.conv0 = paddle.nn.Conv2D(in_channels=3, out_channels=16, kernel_size=[3, 3], padding=1) self.conv1 = paddle.nn.Conv2D(in_channels=16, out_channels=32, kernel_size=[3, 3], stride=2, padding=1) self.conv2 = paddle.nn.Conv2D(in_channels=32, out_channels=64, kernel_size=[3, 3], stride=2, padding=1) self.conv3 = paddle.nn.Conv2D(in_channels=64, out_channels=64, kernel_size=[3, 3], padding=1) self.conv4 = paddle.nn.Conv2D(in_channels=64, out_channels=64, kernel_size=[3, 3], padding=1) self.conv5 = paddle.nn.Conv2D(in_channels=64, out_channels=64, kernel_size=[3, 3], padding=1) self.conv6 = paddle.nn.Conv2D(in_channels=64, out_channels=64, kernel_size=[3, 3], padding=1) self.conv7 = paddle.nn.Conv2D(in_channels=64, out_channels=64, kernel_size=[3, 3], padding=1) self.conv8 = paddle.nn.Conv2D(in_channels=64, out_channels=64, kernel_size=[3, 3], padding=1) self.conv9 = paddle.nn.Conv2D(in_channels=64, out_channels=64, kernel_size=[3, 3], padding=1) self.conv10 = paddle.nn.Conv2D(in_channels=64, out_channels=64, kernel_size=[3, 3], padding=1) self.conv11 = paddle.nn.Conv2D(in_channels=64, out_channels=64, kernel_size=[3, 3], padding=1) self.conv12 = paddle.nn.Conv2D(in_channels=64, out_channels=64, kernel_size=[3, 3], padding=1) self.conv13 = paddle.nn.Conv2D(in_channels=64, out_channels=64, kernel_size=[3, 3], padding=1) self.conv_trans0 = paddle.nn.Conv2DTranspose(in_channels=64, out_channels=32, kernel_size=[3, 3], stride=2, padding=1, output_padding=1, bias_attr=False) self.batchnorm0 = paddle.nn.BatchNorm(num_channels=32, momentum=0.8999999761581421, epsilon=9.999999747378752e-06, is_test=True) self.conv_trans1 = paddle.nn.Conv2DTranspose(in_channels=32, out_channels=16, kernel_size=[3, 3], stride=2, padding=1, output_padding=1, bias_attr=False) self.batchnorm1 = paddle.nn.BatchNorm(num_channels=16, momentum=0.8999999761581421, epsilon=9.999999747378752e-06, is_test=True) self.conv14 = paddle.nn.Conv2D(in_channels=16, out_channels=3, kernel_size=[3, 3], padding=1) self.sigmoid0 = paddle.nn.Sigmoid() def forward(self, x2paddle_input): x2paddle_169 = self.conv0(x2paddle_input) x2paddle_105 = paddle.clip(x=x2paddle_169, max=6.0, min=0.0) x2paddle_172 = self.conv1(x2paddle_105) x2paddle_108 = paddle.clip(x=x2paddle_172, max=6.0, min=0.0) x2paddle_175 = self.conv2(x2paddle_108) x2paddle_111 = paddle.clip(x=x2paddle_175, max=6.0, min=0.0) x2paddle_178 = self.conv3(x2paddle_111) x2paddle_114 = paddle.clip(x=x2paddle_178, max=6.0, min=0.0) x2paddle_181 = self.conv4(x2paddle_114) x2paddle_117 = paddle.clip(x=x2paddle_181, max=6.0, min=0.0) x2paddle_118 = paddle.add(x=x2paddle_111, y=x2paddle_117) x2paddle_119 = paddle.clip(x=x2paddle_118, max=6.0, min=0.0) x2paddle_184 = self.conv5(x2paddle_119) x2paddle_122 = paddle.clip(x=x2paddle_184, max=6.0, min=0.0) x2paddle_187 = self.conv6(x2paddle_122) x2paddle_125 = paddle.clip(x=x2paddle_187, max=6.0, min=0.0) x2paddle_126 = paddle.add(x=x2paddle_119, y=x2paddle_125) x2paddle_127 = paddle.clip(x=x2paddle_126, max=6.0, min=0.0) x2paddle_190 = self.conv7(x2paddle_127) x2paddle_130 = paddle.clip(x=x2paddle_190, max=6.0, min=0.0) x2paddle_193 = self.conv8(x2paddle_130) x2paddle_133 = paddle.clip(x=x2paddle_193, max=6.0, min=0.0) x2paddle_134 = paddle.add(x=x2paddle_127, y=x2paddle_133) x2paddle_135 = paddle.clip(x=x2paddle_134, max=6.0, min=0.0) x2paddle_196 = self.conv9(x2paddle_135) x2paddle_138 = paddle.clip(x=x2paddle_196, max=6.0, min=0.0) x2paddle_199 = self.conv10(x2paddle_138) x2paddle_141 = paddle.clip(x=x2paddle_199, max=6.0, min=0.0) x2paddle_142 = paddle.add(x=x2paddle_135, y=x2paddle_141) x2paddle_143 = paddle.clip(x=x2paddle_142, max=6.0, min=0.0) x2paddle_202 = self.conv11(x2paddle_143) x2paddle_146 = paddle.clip(x=x2paddle_202, max=6.0, min=0.0) x2paddle_205 = self.conv12(x2paddle_146) x2paddle_149 = paddle.clip(x=x2paddle_205, max=6.0, min=0.0) x2paddle_150 = paddle.add(x=x2paddle_143, y=x2paddle_149) x2paddle_151 = paddle.clip(x=x2paddle_150, max=6.0, min=0.0) x2paddle_152 = paddle.add(x=x2paddle_111, y=x2paddle_151) x2paddle_208 = self.conv13(x2paddle_152) x2paddle_155 = paddle.clip(x=x2paddle_208, max=6.0, min=0.0) x2paddle_156 = self.conv_trans0(x2paddle_155) x2paddle_157 = self.batchnorm0(x2paddle_156) x2paddle_158 = paddle.clip(x=x2paddle_157, max=6.0, min=0.0) x2paddle_159 = paddle.add(x=x2paddle_108, y=x2paddle_158) x2paddle_160 = self.conv_trans1(x2paddle_159) x2paddle_161 = self.batchnorm1(x2paddle_160) x2paddle_162 = paddle.clip(x=x2paddle_161, max=6.0, min=0.0) x2paddle_163 = paddle.add(x=x2paddle_105, y=x2paddle_162) x2paddle_211 = self.conv14(x2paddle_163) x2paddle_166 = paddle.clip(x=x2paddle_211, max=6.0, min=0.0) x2paddle_167 = paddle.add(x=x2paddle_input, y=x2paddle_166) x2paddle_output = self.sigmoid0(x2paddle_167) return x2paddle_output def main(x2paddle_input): # There are 1 inputs. # x2paddle_input: shape-[1, 3, 256, 256], type-float32. paddle.disable_static() params = paddle.load(r'/home/aistudio/work/pd_model/model.pdparams') model = ONNXModel() model.set_dict(params, use_structured_name=True) model.eval() out = model(x2paddle_input) return out