def test_maxpool2d_pads01(self): import pytest with pytest.raises(Exception) as e_info: node = onnx.helper.make_node('MaxPool', inputs=['x'], outputs=['y'], kernel_shape=[3, 3], pads=[0, 0, 1, 1]) x = np.random.randn(1, 3, 28, 28).astype(np.float32) x_shape = np.shape(x) kernel_shape = (3, 3) strides = (1, 1) pad_top = pad_left = 0 pad_bottom = pad_right = 1 pad_shape = [pad_top + pad_bottom, pad_left + pad_right] out_shape = pool_op_common.get_output_shape( 'VALID', np.add(x_shape[2:], pad_shape), kernel_shape, strides) padded = np.pad(x, ((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)), mode='constant', constant_values=np.nan) y = pool_op_common.pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, 'MAX') output = OnnxLoader.run_node(node, [x]) np.testing.assert_almost_equal(output["y"], y, decimal=5)
def test_maxpool1d(self): node = onnx.helper.make_node( 'MaxPool', inputs=['x'], outputs=['y'], kernel_shape=[2], ) x = np.random.randn(1, 3, 32).astype(np.float32) x_shape = np.array(np.shape(x)) kernel_shape = np.array([2]) strides = [1] out_shape = pool_op_common.get_output_shape('VALID', x_shape[2:], kernel_shape, strides) padded = x y = pool_op_common.pool(padded, x_shape, kernel_shape, strides, out_shape, [0], 'MAX') output = OnnxLoader.run_node(node, [x]) np.testing.assert_almost_equal(output["y"], y, decimal=5)