<filename>models/pt_pool_2d.py
import torch
import numpy as np


ip_tensor_8x8 =  np.array([[-0.8520309,-0.8490718, 1.129514,-1.3910682,-1.3713549,-1.2450725,-0.64018744,    -0.58683217],
                           [0.61351526,-0.7573147,-1.0944875,-1.3194267,-1.0564152,-1.0523492,-0.8647979,    -0.5105319],
                           [-1.0064573,-0.96857584,-1.049313,-1.1837159,-1.421839,-1.3091717,-1.4398289,     -1.1118798],
                           [-1.2060001,-0.9072193,-0.93204916,-0.9201482,-1.0511543,-0.8700992,-1.0922338,   -1.2065634],
                           [-0.9080574,-1.2397976,-1.0792112,-1.1603603,-1.4759526,-1.6273732,-1.7018712,    -1.2549796],
                           [-0.9400331,-1.2271551,-1.0533371,-1.7574923,-1.4672713,-1.449718,-0.89420605,    -0.7849926],
                           [-0.75937706,-1.0642793,-1.3776617,-1.3407046,-0.70763135,-0.8301665,-0.9863248,  -0.8487809],
                           [-0.45886853,-0.6476302,-0.7841558,-1.0839088,-0.94306296,-0.99122596,-0.7741117, -0.7921684]])

ip_tensor_7x7 =  np.array([[-0.8520309,-0.8490718,1.129514,-1.3910682,-1.3713549,-1.2450725,-0.64018744,    ],
                           [0.61351526,-0.7573147,-1.0944875,-1.3194267,-1.0564152,-1.0523492,-0.8647979,    ],
                           [-1.0064573,-0.96857584,-1.049313,-1.1837159,-1.421839,-1.3091717,-1.4398289,     ],
                           [-1.2060001,-0.9072193,-0.93204916,-0.9201482,-1.0511543,-0.8700992,-1.0922338,   ],
                           [-0.9080574,-1.2397976,-1.0792112,-1.1603603,-1.4759526,-1.6273732,-1.7018712,    ],
                           [-0.9400331,-1.2271551,-1.0533371,-1.7574923,-1.4672713,-1.449718,-0.89420605,    ],
                           [-0.75937706,-1.0642793,-1.3776617,-1.3407046,-0.70763135,-0.8301665,-0.9863248,  ]])

ip_tensor = ip_tensor_7x7

class TestModel(torch.nn.Module):
    def __init__(self,):
        super().__init__()


    def forward(self, x):
        x = torch.max_pool2d(x,kernel_size=3, stride=2, padding=(1,1),ceil_mode=True)
        return x

model = TestModel()


ip_tensor_np = np.expand_dims(np.expand_dims(ip_tensor,0),0)
ip_tensor = torch.from_numpy(ip_tensor_np)

output = model(ip_tensor)

print(np.squeeze(ip_tensor.numpy()))
print(np.squeeze(output.numpy()))

torch.onnx.export(model, ip_tensor, 'maxpool.onnx', verbose=True,opset_version=11)

import onnxruntime as rt
so = rt.SessionOptions()
sess = rt.InferenceSession('maxpool.onnx' ,sess_options=so)
input_details = sess.get_inputs()
ort_output = sess.run(None, {input_details[0].name: ip_tensor_np})
print(ort_output[0])
