def test_and(self): a = np.zeros((1, 2, 3, 3), dtype=np.float32) b = np.zeros((3), dtype=np.float32) node = onnx.helper.make_node( 'And', inputs=['a', 'b'], outputs=['y'] ) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Input')('a', list(a.shape), dtype='float32') bX = xlf.get_xop_factory_func('Constant')('b', b) xmap = {'a': aX, 'b': bX} params = {} Xs = ol3.and_op(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'AnyOp' in X.type assert X.shapes.tolist() == [-1, 2, 3, 3]
def test_tile(self): a = np.zeros((1, 2, 3, 3), dtype=np.float32) repeats = np.array([1, 3, 2, 2]) node = onnx.helper.make_node( 'Tile', inputs=['a', 'repeats'], outputs=['y'] ) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Input')('a', list(a.shape)) rX = xlf.get_xop_factory_func('Constant')('repeats', repeats) xmap = {'a': aX, 'repeats': rX} params = {} Xs = ol3.tile(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'AnyOp' in X.type assert X.shapes.tolist() == [-1, 6, 6, 6]
def test_qlinear_matmul(self): a = np.array([[1, 2]]).astype(np.float32) # 1 x 2 b = np.transpose(np.array([ [1, 2], [3, 4], [5, 6]]).astype(np.float32)) # 2 x 3 node = onnx.helper.make_node( 'QLinearMatMul', inputs=['a', 'a_scale', 'a_zero', 'b', 'b_scale', 'b_zero', 'y_scale', 'y_zero'], outputs=['y'] ) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Input')('a', list(a.shape), dtype='float32') bX = xlf.get_xop_factory_func('Constant')('b', b, onnx_id='b') xmap = {'a': aX, 'b': bX} params = {} Xs = ol1b.qlinear_matmul(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'AnyOp' in X.type assert X.shapes.tolist() == [-1, 3]
def test_top_k(self): a = np.zeros((1, 4, 3, 3)) k = np.array([2]) node = onnx.helper.make_node('TopK', inputs=['a', 'k'], outputs=['y'], axis=1) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Input')('a', list(a.shape)) kX = xlf.get_xop_factory_func('Constant')('k', k) xmap = {'a': aX, 'k': kX} params = {} Xs = ol0.topk(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'AnyOp' in X.type assert X.shapes.tolist() == [-1, 2, 3, 3]
def test_one_hot(self): a = np.zeros((1, 3), dtype=np.float32) d = np.array([10]) node = onnx.helper.make_node( 'OneHot', inputs=['a', 'd'], outputs=['y'], reduction='none' ) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Input')('a', list(a.shape)) dX = xlf.get_xop_factory_func('Constant')('d', d) xmap = {'a': aX, 'd': dX} params = {} Xs = ol3.one_hot(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'AnyOp' in X.type assert X.shapes.tolist() == [-1, 3, 10]
def test_max_roi_pool_node(self): x = np.array([[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]]).astype(np.float32) a = np.array([[0, 0, 1, 0, 1], [0, 1, 2, 1, 2]]) node = onnx.helper.make_node('MaxRoiPool', inputs=['x', 'a'], outputs=['y'], pooled_shape=[2, 2]) wrapped_node = NodeWrapper(node) iX = xlf.get_xop_factory_func('Input')('x', list(x.shape), dtype='float32') aX = xlf.get_xop_factory_func('Constant')('a', a) xmap = {'x': iX, 'a': aX} params = {} Xs = ol2c.max_roi_pool(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'AnyOp' in X.type assert X.shapes.tolist() == [2, 1, 2, 2]
def test_pad(self): x = np.array([[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]]).astype(np.float32) p = np.array([0, 0, 1, 1, 0, 0, 2, 3]) pv = np.array([0]) node = onnx.helper.make_node('Pad', inputs=['x', 'p', 'pv'], outputs=['y']) wrapped_node = NodeWrapper(node) iX = xlf.get_xop_factory_func('Input')('x', list(x.shape), dtype='float32') pX = xlf.get_xop_factory_func('Constant')('p', p) pvX = xlf.get_xop_factory_func('Constant')('pv', pv) xmap = {'x': iX, 'p': pX, 'pv': pvX} params = {} Xs = ol2c.pad(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'Pad' in X.type assert X.shapes.tolist() == [-1, 1, 6, 7]
def test_resize(self): a = np.zeros((1, 2, 3, 3), dtype=np.float32) roi = np.array([0, 0, 0, 0, 1, 1, 0.5, 0.5]) scales = np.array([1, 1, 2, 3]) node = onnx.helper.make_node('Resize', inputs=['a', 'roi', 'scales'], outputs=['y']) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Input')('a', list(a.shape), dtype='float32') rX = xlf.get_xop_factory_func('Constant')('roi', roi) sX = xlf.get_xop_factory_func('Constant')('scales', scales) xmap = {'a': aX, 'roi': rX, 'scales': sX} params = {} Xs = ol4.resize(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'AnyOp' in X.type assert X.shapes.tolist() == [-1, 2, 3, 4]
def test_roi_align(self): a = np.zeros((1, 2, 3, 3), dtype=np.float32) rois = np.zeros((3, 4)) batch_indices = np.zeros((3)) node = onnx.helper.make_node('RoiAlign', inputs=['a', 'rois', 'batch_indices'], outputs=['y'], output_height=2, output_width=2) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Input')('a', list(a.shape), dtype='float32') rX = xlf.get_xop_factory_func('Constant')('rois', rois) bX = xlf.get_xop_factory_func('Constant')('batch_indices', batch_indices) xmap = {'a': aX, 'rois': rX, 'batch_indices': bX} params = {} Xs = ol4.roi_align(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'AnyOp' in X.type assert X.shapes.tolist() == [3, 2, 2, 2]
def test_gather_elements(self): a = np.zeros((3, 3), dtype=np.float32) b = np.zeros((3, 2)) node = onnx.helper.make_node('GatherElements', inputs=['a', 'b'], outputs=['y'], axis=1) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Constant')('a', a) bX = xlf.get_xop_factory_func('Constant')('b', b) xmap = {'a': aX, 'b': bX} params = {} Xs = ol4.gather_elements(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'AnyOp' in X.type assert X.shapes.tolist() == [3, 2]
def test_broadcast_ops(self): any_ops = ['Less', 'LessOrEqual'] for any_op in any_ops: a = np.zeros((1, 2, 3, 3), dtype=np.float32) b = np.zeros((3), dtype=np.float32) node = onnx.helper.make_node(any_op, inputs=['a', 'b'], outputs=['y']) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Input')('a', list(a.shape), dtype='float32') bX = xlf.get_xop_factory_func('Constant')('b', b) xmap = {'a': aX, 'b': bX} params = {} func = getattr(ol4, any_op.lower()) Xs = func(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'AnyOp' in X.type assert X.shapes.tolist() == [-1, 2, 3, 3]
def test_gather(self): a = np.zeros((1, 5, 3, 3), dtype=np.float32) b = np.array([0, 1, 3]) node = onnx.helper.make_node('Gather', inputs=['a', 'b'], outputs=['y'], axis=1) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Input')('a', list(a.shape), dtype='float32') bX = xlf.get_xop_factory_func('Constant')('b', b) xmap = {'a': aX, 'b': bX} params = {} Xs = ol4.gather(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'Take' in X.type assert X.shapes.tolist() == [-1, 3, 3, 3]
def test_compress(self): a = np.zeros((1, 2, 3, 3), dtype=np.float32) c = np.array([False, True]) node = onnx.helper.make_node('Compress', inputs=['a', 'c'], outputs=['y'], axis=2) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Input')('a', list(a.shape), dtype='float32') cX = xlf.get_xop_factory_func('Constant')('c', c) xmap = {'a': aX, 'c': cX} params = {} Xs = ol4.compress(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] # assert np.compress(c, a, axis=2) == (1, 2, 1, 3) assert X.name == 'y' assert 'AnyOp' in X.type assert X.shapes.tolist() == [-1, 2, 1, 3]
def get_add_const_layer(in_layer, const_layer): # Numpy style broadcasting == NHWC const_ndim = const_layer.data[0].ndim if const_ndim == 1: # Create name op_name = 'nn_bias_add-' + str(hash(expr)) const_size = const_layer.data[0].shape[0] in_shape = in_layer.shapes # Retrieve axis according to numpy broadcasting rules axis = [i for i in range(len(in_shape)-1, -1, -1) if in_shape[i] == const_size][0] X = xlf.get_xop_factory_func('BiasAdd')( op_name, in_layer, const_layer, axis, relay_id=[hash(expr)]) in_layer.tops.append(X.name) else: # Create name op_name = 'add-' + str(hash(expr)) X = xlf.get_xop_factory_func('Add')(op_name, [in_layer, const_layer], relay_id=[hash(expr)]) in_layer.tops.append(X.name) const_layer.tops.append(X.name) return X
def test_sub(self): a = np.array([[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]]).astype(np.float32) b = np.array([[[[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]]]]).astype(np.float32) node = onnx.helper.make_node( 'Sub', inputs=['a', 'b'], outputs=['y'] ) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Input')('a', list(a.shape), dtype='float32') bX = xlf.get_xop_factory_func('Input')('b', list(b.shape), dtype='float32') xmap = {'a': aX, 'b': bX} params = {} Xs = ol1b.sub(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'Sub' in X.type assert X.bottoms == ['a', 'b'] assert X.shapes.tolist() == [-1, 1, 3, 3]
def test_scatter_nd(self): a = np.zeros((1, 2, 3, 3), dtype=np.float32) indices = np.zeros((2, 3)) updates = np.zeros((2, 3)) node = onnx.helper.make_node('ScatterND', inputs=['a', 'indices', 'updates'], outputs=['y']) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Input')('a', list(a.shape), dtype='float32') iX = xlf.get_xop_factory_func('Constant')('indices', indices) uX = xlf.get_xop_factory_func('Constant')('updates', updates) xmap = {'a': aX, 'indices': iX, 'updates': uX} params = {} Xs = ol4.scatter_nd(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'AnyOp' in X.type assert X.shapes.tolist() == [-1, 2, 3, 3]
def test_add_constant_tensor(self): a = np.array([1]).astype(np.float32) b = np.array([[[[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]]]]).astype(np.float32) node = onnx.helper.make_node( 'Add', inputs=['a', 'b'], outputs=['y'] ) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Constant')('a', a) bX = xlf.get_xop_factory_func('Input')('b', list(b.shape), dtype='float32') xmap = {'a': aX, 'b': bX} params = {} Xs = ol1b.add(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'BiasAdd' in X.type assert X.bottoms == ['b'] np.testing.assert_array_equal(X.data[0], a) assert X.shapes.tolist() == [-1, 1, 3, 3] assert X.attrs['axis'] == 1
def test_where(self): condition = np.array([[1, 0], [1, 1]], dtype=np.bool) a = np.array([[1, 2], [3, 4]], dtype=np.float32) b = np.array([[9, 8], [7, 6]], dtype=np.float32) node = onnx.helper.make_node('Equal', inputs=['condition', 'a', 'b'], outputs=['y']) wrapped_node = NodeWrapper(node) cX = xlf.get_xop_factory_func('Constant')('condition', condition) aX = xlf.get_xop_factory_func('Constant')('a', a) bX = xlf.get_xop_factory_func('Constant')('b', b) xmap = {'condition': cX, 'a': aX, 'b': bX} params = {} Xs = ol4.where(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'AnyOp' in X.type assert X.shapes.tolist() == [2, 2]
def test_max_unpool_node_output_shape(self): x = np.array([[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]]).astype(np.float32) z = np.array([-1, 1, 4, 4]) node = onnx.helper.make_node('MaxUnPool', inputs=['x', 'y', 'z'], outputs=['y'], kernel_shape=[2, 2], strides=[2, 2]) wrapped_node = NodeWrapper(node) iX = xlf.get_xop_factory_func('Input')('x', list(x.shape), dtype='float32') zX = xlf.get_xop_factory_func('Constant')('z', z) xmap = {'x': iX, 'z': zX} params = {} Xs = ol2c.max_unpool(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'AnyOp' in X.type assert X.shapes.tolist() == [-1, 1, 4, 4]
def test_matmul_integer_basic(self): x = np.array([[1, 2]]).astype(np.int32) # 1 x 2 w = np.transpose(np.array([ [1, 2], [3, 4], [5, 6]]).astype(np.int32)) # 2 x 3 node = onnx.helper.make_node( 'MatMulInteger', inputs=['x', 'w'], outputs=['y'] ) wrapped_node = NodeWrapper(node) iX = xlf.get_xop_factory_func('Input')('x', list(x.shape), dtype='int32') wX = xlf.get_xop_factory_func('Constant')('w', w, onnx_id='w') xmap = {'x': iX, 'w': wX} params = {} Xs = ol1b.matmul(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'Dense' in X.type assert X.shapes.tolist() == [-1, 3]
def test_upsample_node(self): x = np.array([[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]]).astype(np.float32) scales = np.array([1.0, 1.0, 2.0, 3.0], dtype=np.float32) node = onnx.helper.make_node('Upsample', inputs=['x', 'scales'], outputs=['y']) wrapped_node = NodeWrapper(node) iX = xlf.get_xop_factory_func('Input')('x', list(x.shape), dtype='float32') sX = xlf.get_xop_factory_func('Constant')('scales', scales) xmap = {'x': iX, 'scales': sX} params = {} Xs = ol2c.upsample(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'Upsampling2D' in X.type assert X.shapes.tolist() == [-1, 1, 6, 9] assert X.attrs['scale_h'] == 2. assert X.attrs['scale_w'] == 3. assert X.attrs['data_layout'] == 'NCHW' assert X.attrs['method'] == 'nearest_neighbor'
def test_multiply_two_constants(self): a = np.array([[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]]).astype(np.float32) b = np.array([[[[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]]]]).astype(np.float32) node = onnx.helper.make_node( 'Mul', inputs=['a', 'b'], outputs=['y'] ) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Constant')('a', a) bX = xlf.get_xop_factory_func('Constant')('b', b) xmap = {'a': aX, 'b': bX} params = {} Xs = ol1b.mul(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'Constant' in X.type assert X.shapes.tolist() == [1, 1, 3, 3] res = np.array([[[[-1, -4, -9], [-16, -25, -36], [-49, -64, -81]]]]).astype(np.float32) np.testing.assert_array_equal(X.data[0], res)
def test_range(self): start = np.array([1]) limit = np.array([10]) delta = np.array([2]) node = onnx.helper.make_node('Range', inputs=['s', 'l', 'd'], outputs=['y']) wrapped_node = NodeWrapper(node) sX = xlf.get_xop_factory_func('Constant')('s', start) lX = xlf.get_xop_factory_func('Constant')('l', limit) dX = xlf.get_xop_factory_func('Constant')('d', delta) xmap = {'s': sX, 'l': lX, 'd': dX} params = {} Xs = ol0.range(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'AnyOp' in X.type assert X.shapes.tolist() == [5]
def test_mul_tensor_constant(self): a = np.array([[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]]).astype(np.float32) b = np.array([[[[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]]]]).astype(np.float32) node = onnx.helper.make_node( 'Mul', inputs=['a', 'b'], outputs=['y'] ) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Input')('a', list(a.shape), dtype='float32') bX = xlf.get_xop_factory_func('Constant')('b', b) xmap = {'a': aX, 'b': bX} params = {} Xs = ol1b.mul(wrapped_node, params, xmap) assert len(Xs) == 2 X = Xs[-1] assert X.name == 'y' assert 'Scale' in X.type assert X.bottoms == ['a'] np.testing.assert_array_equal(X.data.gamma, b) assert X.shapes.tolist() == [-1, 1, 3, 3] assert X.attrs['axis'] == -1
def test_softmax_cross_entropy_loss(self): a = np.zeros((2, 3, 2), dtype=np.float32) b = np.array([[2, 1], [0, 2]]) node = onnx.helper.make_node( 'SoftmaxCrossEntropyLoss', inputs=['a', 'b'], outputs=['y'], reduction='none' ) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Constant')('a', a) bX = xlf.get_xop_factory_func('Constant')('b', b) xmap = {'a': aX, 'b': bX} params = {} Xs = ol3.softmax_cross_entropy_loss(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'AnyOp' in X.type assert X.shapes.tolist() == [2, 2]
def test_sub_two_constants(self): a = np.array([[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]]).astype(np.float32) b = np.array([[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]]).astype(np.float32) node = onnx.helper.make_node( 'Sub', inputs=['a', 'b'], outputs=['y'] ) wrapped_node = NodeWrapper(node) aX = xlf.get_xop_factory_func('Constant')('a', a) bX = xlf.get_xop_factory_func('Constant')('b', b) xmap = {'a': aX, 'b': bX} params = {} Xs = ol1b.sub(wrapped_node, params, xmap) assert len(Xs) == 1 X = Xs[0] assert X.name == 'y' assert 'Constant' in X.type assert X.shapes.tolist() == [1, 1, 3, 3] np.testing.assert_array_equal( X.data[0], np.zeros((1, 1, 3, 3), dtype=np.float32))
def test_multiply_layer(self): iX1 = XLayer( type=["Input"], name="in1", shapes=[-1, 2, 1, 4], sizes=[8], bottoms=[], tops=[], targets=[], ) iX2 = XLayer( type=["Input"], name="in2", shapes=[-1, 2, 1, 4], sizes=[8], bottoms=[], tops=[], targets=[], ) mX = xlf.get_xop_factory_func("Multiply")("mul2", [iX1, iX2]) assert mX.type[0] == "Multiply" assert mX.shapes == [-1, 2, 1, 4] iX3 = XLayer( type=["Input"], name="in3", shapes=[-1, 1, 4, 1], sizes=[4], bottoms=[], tops=[], targets=[], ) mX = xlf.get_xop_factory_func("Multiply")("mul3", [iX1, iX3]) assert mX.type[0] == "Multiply" assert mX.shapes == [-1, 2, 4, 4] iX4 = XLayer( type=["Input"], name="in4", shapes=[4, 1], sizes=[4], bottoms=[], tops=[], targets=[], ) mX = xlf.get_xop_factory_func("Multiply")("mul4", [iX1, iX4]) assert mX.type[0] == "Multiply" assert mX.shapes == [-1, 2, 4, 4]
def test_multiply_layer(self): iX1 = XLayer( type=['Input'], name='in1', shapes=[-1, 2, 1, 4], sizes=[8], bottoms=[], tops=[], targets=[] ) iX2 = XLayer( type=['Input'], name='in2', shapes=[-1, 2, 1, 4], sizes=[8], bottoms=[], tops=[], targets=[] ) mX = xlf.get_xop_factory_func('Multiply')('mul2', [iX1, iX2]) assert mX.type[0] == 'Multiply' assert mX.shapes == [-1, 2, 1, 4] iX3 = XLayer( type=['Input'], name='in3', shapes=[-1, 1, 4, 1], sizes=[4], bottoms=[], tops=[], targets=[] ) mX = xlf.get_xop_factory_func('Multiply')('mul3', [iX1, iX3]) assert mX.type[0] == 'Multiply' assert mX.shapes == [-1, 2, 4, 4] iX4 = XLayer( type=['Input'], name='in4', shapes=[4, 1], sizes=[4], bottoms=[], tops=[], targets=[] ) mX = xlf.get_xop_factory_func('Multiply')('mul4', [iX1, iX4]) assert mX.type[0] == 'Multiply' assert mX.shapes == [-1, 2, 4, 4]
def test_conv_node_1(self): x = np.array([[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]]).astype(np.float32) W = np.array([[[[1, 1], [1, 1]]], [[[1, -1], [1, 1]]]]).astype(np.float32) B = np.array([1, -1]).astype(np.float32) node = onnx.helper.make_node( 'Conv', inputs=['x', 'W', 'B'], outputs=['y'], kernel_shape=[2, 2], pads=[1, 1, 0, 0] ) wrapped_node = NodeWrapper(node) iX = xlf.get_xop_factory_func('Input')('x', list(x.shape), dtype='float32') wX = xlf.get_xop_factory_func('Constant')('W', W, onnx_id='W') bX = xlf.get_xop_factory_func('Constant')('B', B, onnx_id='B') xmap = {'x': iX, 'W': wX, 'B': bX} params = {} Xs = ol2c.conv(wrapped_node, params, xmap) assert len(Xs) == 2 X, baX = Xs assert X.name == 'y_Conv' assert X.shapes.tolist() == [-1, 2, 3, 3] assert X.attrs['padding'] == [(0, 0), (0, 0), (1, 0), (1, 0)] assert X.attrs['strides'] == [1, 1] assert X.attrs['dilation'] == [1, 1] assert X.attrs['kernel_size'] == [2, 2] assert X.attrs['channels'] == [1, 2] assert X.attrs['data_layout'] == 'NCHW' assert X.attrs['kernel_layout'] == 'OIHW' assert X.attrs['groups'] == 1 assert X.attrs['onnx_id'] == 'y' assert baX.name == 'y' assert baX.shapes == [-1, 2, 3, 3] assert baX.attrs['axis'] == 1 assert baX.attrs['onnx_id'] == 'y'
def test_pad_layer(self): iX = XLayer( type=["Input"], name="in1", shapes=[1, 2, 7, 7], sizes=[98], bottoms=[], tops=[], targets=[], ) X = xlf.get_xop_factory_func("Pad")( op_name="pad1", padding=[[0, 0], [0, 0], [1, 0], [1, 0]], pad_value=0, input_layer=iX, ) assert X.type[0] == "Pad" assert X.shapes == [1, 2, 8, 8] assert X.sizes == [128] assert X.attrs["padding"] == [[0, 0], [0, 0], [1, 0], [1, 0]] from pyxir.graph.ops.l2_convolution import padding_transpose_transform padding_transpose_transform(X, axes=(0, 2, 3, 1)) assert X.type[0] == "Pad" assert X.shapes == [1, 8, 8, 2] assert X.attrs["padding"] == [[0, 0], [1, 0], [1, 0], [0, 0]]