예제 #1
0
    def setUp(self):
        # these parameters are referenced from chainer test
        in_shape = (3, 3, 12, 8)
        self.x = input_generator.positive_increasing(*in_shape)
        # In chainer test, x is shuffled and normalize-like conversion,
        # In this test, those operations are skipped.
        # If x includes negative value, not match with onnxruntime output.
        # You can reproduce this issue by changing `positive_increasing` to
        # `increase`
        self.rois = np.array([
            [0, 1, 1, 6, 6],
            [2, 6, 2, 7, 11],
            [1, 3, 1, 5, 10],
            [0, 3, 3, 3, 3]], dtype=np.float32)
        kwargs = {
            'outh': 3,
            'outw': 7,
            'spatial_scale': 0.6
        }

        class Model(chainer.Chain):
            def __init__(self, kwargs):
                super(Model, self).__init__()
                self.kwargs = kwargs

            def __call__(self, x, rois):
                return F.roi_pooling_2d(x, rois, **self.kwargs)

        self.model = Model(kwargs)
예제 #2
0
    def setup_test_case(self):
        class Model(chainer.Chain):
            def __init__(self, ops):
                super(Model, self).__init__()
                self.ops = ops

            def __call__(self, a):
                if not isinstance(a, chainer.Variable):
                    a = chainer.Variable(a)
                return eval(self.ops)

        self.model = Model(self.ops)
        self.a = input_generator.positive_increasing(2, 3) / 10.0

        name = self.op_name.lower()
        if hasattr(self, 'condition'):
            name += '_' + self.condition
        self.name = name

        skip_opset_version = []
        if self.op_name == 'Cosh' or self.op_name == 'Sinh':
            skip_opset_version.append(7)
            skip_opset_version.append(8)

        if self.op_name == 'BroadcastTo':
            skip_opset_version.append(7)

        self.skip_opset_version = skip_opset_version
예제 #3
0
    def setUp(self):
        class Model(chainer.Chain):
            def __init__(self, ops):
                super(Model, self).__init__()
                self.ops = ops

            def __call__(self, a):
                if not isinstance(a, chainer.Variable):
                    a = chainer.Variable(a)
                return eval(self.ops)

        self.model = Model(self.ops)
        self.a = chainer.Variable(input_generator.positive_increasing(2, 3))
예제 #4
0
def test_export_external_converters_overwrite(tmpdir, check_model_expect):
    path = str(tmpdir)

    model = chainer.Sequential(chainer.functions.sigmoid)
    x = input_generator.positive_increasing(2, 5)

    def custom_converter(params):
        return onnx_helper.make_node('Tanh', params.input_names,
                                     params.output_names),

    addon_converters = {'Sigmoid': custom_converter}
    export_testcase(model, x, path, external_converters=addon_converters)

    tanh_outputs = chainer.functions.tanh(x).array
    output_path = os.path.join(path, 'test_data_set_0', 'output_0.pb')
    onnx_helper.write_tensor_pb(output_path, '', tanh_outputs)  # overwrite

    check_model_expect(path)
예제 #5
0
 def vector(self):
     a = chainer.Variable(input_generator.positive_increasing(2, ))
     b = chainer.Variable(input_generator.nonzero_increasing(2, ) * 0.3)
     return (a, b)
예제 #6
0
 def matrix(self):
     a = chainer.Variable(input_generator.positive_increasing(5, 2, 3))
     b = chainer.Variable(input_generator.nonzero_increasing(5, 2, 3) * 0.3)
     return (a, b)