4
4
import torch .nn .init as init
5
5
import torch .nn as nn
6
6
import torch .nn .functional as F
7
+ import paddle # version 2.1.1
7
8
import numpy as np
8
9
import os .path
9
10
import onnx
@@ -1356,3 +1357,26 @@ def forward(self, x):
1356
1357
x = Variable (torch .randn ([2 , 3 ]))
1357
1358
model = NormalizeFusion ()
1358
1359
save_data_and_model ("normalize_fusion" , x , model )
1360
+
1361
+ #paddle2onnx model
1362
+ class Resize_HumanSeg (paddle .nn .Layer ):
1363
+ def __init__ (self , ):
1364
+ super (Resize_HumanSeg , self ).__init__ ()
1365
+
1366
+ def forward (self , x0 ):
1367
+ x1 = paddle .nn .functional .interpolate (x0 ,size = [6 ,8 ],mode = 'bilinear' ,align_corners = False )
1368
+ return x1
1369
+
1370
+ def save_data_and_paddle_model (model , name , input_data ):
1371
+ model .eval ()
1372
+ np .save (os .path .join ("data" , "input_" + name + ".npy" ), input_data .numpy ())
1373
+ output = model (input_data )
1374
+ np .save (os .path .join ("data" , "output_" + name + ".npy" ), output .numpy ())
1375
+ inputs = [paddle .static .InputSpec (shape = input_data .shape , dtype = "float32" )]
1376
+ paddle .onnx .export (model , "models/" + name ,
1377
+ input_spec = inputs ,
1378
+ opset_version = 11 )
1379
+
1380
+ input_shape = [1 , 2 , 3 , 4 ]
1381
+ x = paddle .rand (input_shape , dtype = "float32" )
1382
+ save_data_and_paddle_model (Resize_HumanSeg (), "resize_humanseg" , x )
0 commit comments