self.batchnorm15(self.conv15(out)), negative_slope=0.1) out = F.leaky_relu( self.batchnorm16(self.conv16(out)), negative_slope=0.1) out = F.leaky_relu( self.batchnorm17(self.conv17(out)), negative_slope=0.1) out = F.leaky_relu( self.batchnorm18(self.conv18(out)), negative_slope=0.1) out = F.leaky_relu( self.batchnorm19(self.conv19(out)), negative_slope=0.1) out = F.leaky_relu( self.batchnorm20(self.conv20(out)), negative_slope=0.1) out = torch.cat([passthrough, out], 1) out = F.leaky_relu( self.batchnorm21(self.conv21(out)), negative_slope=0.1) out = self.conv22(out) return out model = Yolov2() model.eval() xb = torch.rand((1, 3, 224, 224)) yp = model(xb) export_onnx_with_validation( model, (xb, ), 'sample_yolov2', ['image'], ['pred'], verbose=True, training=False)
self.down3 = down(256, 512) self.down4 = down(512, 512) self.up1 = up(1024, 256) self.up2 = up(512, 128) self.up3 = up(256, 64) self.up4 = up(128, 64) self.outc = outconv(64, n_classes) def forward(self, x): x1 = self.inc(x) x2 = self.down1(x1) x3 = self.down2(x2) x4 = self.down3(x3) x5 = self.down4(x4) x = self.up1(x5, x4) x = self.up2(x, x3) x = self.up3(x, x2) x = self.up4(x, x1) x = self.outc(x) return F.sigmoid(x) model = UNet(3, 80) model.eval() xb = torch.rand((1, 3, 512, 512)) yp = model(xb) export_onnx_with_validation(model, [xb], 'sample_unet', ['image'], ['pred'], verbose=True, training=False)
def forward(self, x): y = x y = self.fc(y) return y model = Model() model.eval() xb = torch.rand((2, 3)) yp = model(xb) idx += 1 print('index: ', idx) export_onnx_with_validation( model, (xb, ), prefix + str(idx), ['x'], ['y'], verbose=True, training=False) ######## example: compare ######## class Model(nn.Module): def __init__(self): super(Model, self).__init__() def forward(self, x0, x1): x0 = x0.clamp(-1, 1) a = torch.max(x0, x1) == x1 b = x0 < x1 c = x0 > x1
h, c = self.lstm(h, (h2, c2)) return h, c model = Model() model.eval() xb = torch.rand((7, 6)) h1 = torch.zeros((7, 5)) h2 = torch.zeros((7, 4)) c2 = torch.zeros((7, 4)) yp = model(xb, h1, h2, c2) idx += 1 print('index: ', idx) export_onnx_with_validation(model, [xb, h1, h2, c2], prefix + str(idx), ['x', 'h1', 'h2', 'c2'], ['h', 'c'], verbose=True, training=False) ######## example: RNN ######## class Model(nn.Module): def __init__(self): super(Model, self).__init__() self.gru = nn.GRU(6, 5, 3) self.lstm = nn.LSTM(5, 4, 2) def forward(self, x, h1, h2, c2): y, h1 = self.gru(x, h1) y, (h2, c2) = self.lstm(y, (h2, c2))