Example #1
0
def single_function_model(function, inputs, outputs, **kwargs):
    inputs = [nnoir.Value(x[0], shape=x[1], dtype='<f4') for x in inputs]
    outputs = [nnoir.Value(x[0], shape=x[1], dtype='<f4') for x in outputs]
    nodes = inputs + outputs
    input_names = [x.name for x in inputs]
    output_names = [x.name for x in outputs]
    functions = [
        getattr(nnoir.functions, function)(input_names, output_names, **kwargs)
    ]
    actual = nnoir.NNOIR(function.encode(), b'nnoir2chainer_test', "0.1",
                         input_names, output_names, nodes, functions).pack()
    expected = nnoir.load(
        os.path.join(os.path.abspath(os.path.dirname(__file__)),
                     function + '.nnoir')).pack()
    print(actual)
    print(expected)
    assert expected == actual
Example #2
0
def single_function_model(function, _inputs, _outputs, **kwargs):
    inputs = [nnoir.Value(x[0], shape=x[1], dtype='<f4') for x in _inputs]
    outputs = [nnoir.Value(x[0], shape=x[1], dtype='<f4') for x in _outputs]
    nodes = inputs + outputs
    input_names = [x.name for x in inputs]
    output_names = [x.name for x in outputs]
    functions = [
        getattr(nnoir.functions,
                function.partition('_')[0])(input_names, output_names,
                                            **kwargs)
    ]
    actual = nnoir.NNOIR(function.encode(), b'nnoir2chainer_test', "0.1",
                         input_names, output_names, nodes, functions)
    expected = nnoir.load(
        os.path.join(os.path.abspath(os.path.dirname(__file__)),
                     function + '.nnoir'))
    xs = [np.random.randn(*x[1]).astype('<f4') for x in _inputs]
    actuals = actual.run(*xs)
    expecteds = expected.run(*xs)
    assert len(expecteds) == len(actuals)
    for a, e in zip(actuals, expecteds):
        print(a - e)
        assert (a == e).all()
Example #3
0
 def save_and_run(self, model: NNOIR):
     with tempfile.NamedTemporaryFile(delete=TMP_REMOVE) as f:
         model.dump(f.name)
         reload_nnoir: NNOIR = nnoir.load(f.name)
         return self.execute_nnoir(reload_nnoir)