Exemplo n.º 1
0
 def check(dim, axis, nstep):
     eps = 0.01
     x = sym.Variable("x") + 1
     beta = sym.Variable("beta")
     gamma = sym.Variable("gamma")
     moving_var = sym.Variable("moving_var")
     moving_mean = sym.Variable("moving_mean")
     y1, y2 = x, sym.Variable("xx") + 1
     ishape = {"x": tuple(10 for i in range(dim))}
     for i in range(nstep):
         y1 = sym.batch_norm(y1 + 1,
                             gamma,
                             beta,
                             moving_mean,
                             moving_var,
                             epsilon=eps,
                             axis=axis)
         y1 = sym.dropout(y1)
         y2 = simple_bn(y2 + 1,
                        gamma,
                        beta,
                        moving_mean,
                        moving_var,
                        epsilon=eps,
                        axis=axis,
                        shape=ishape["x"])
     g = nnvm.graph.create(y1)
     g2 = nnvm.graph.create(y2)
     graph_attr.set_shape_inputs(g, ishape)
     g1 = g.apply("InferShape").apply("SimplifyInference")
     # assert graph equals as expected
     graph_util.check_graph_equal(g1, g2)
Exemplo n.º 2
0
def compare_graph(sym1, sym2, ishape=(2, 3, 224, 224)):
    g1 = nnvm.graph.create(sym1)
    g2 = nnvm.graph.create(sym2)
    graph_attr.set_shape_inputs(g1, {'data':ishape})
    graph_attr.set_shape_inputs(g2, {'data':ishape})
    g1 = g1.apply("InferShape").apply("SimplifyInference")
    g2 = g2.apply("InferShape").apply("SimplifyInference")
    graph_util.check_graph_equal(g1, g2)
Exemplo n.º 3
0
def compare_graph(sym1, sym2, ishape=(2, 3, 224, 224)):
    g1 = nnvm.graph.create(sym1)
    g2 = nnvm.graph.create(sym2)
    graph_attr.set_shape_inputs(g1, {'data':ishape})
    graph_attr.set_shape_inputs(g2, {'data':ishape})
    g1 = g1.apply("InferShape").apply("SimplifyInference")
    g2 = g2.apply("InferShape").apply("SimplifyInference")
    graph_util.check_graph_equal(g1, g2)
Exemplo n.º 4
0
def compare_graph(onnx_file, nnvm_sym, ishape):
    onnx_graph = onnx.load(onnx_file)
    onnx_sym, params = nnvm.frontend.from_onnx(onnx_graph)
    g1 = nnvm.graph.create(onnx_sym)
    g2 = nnvm.graph.create(nnvm_sym)
    ishapes = {'input_0': ishape}
    graph_attr.set_shape_inputs(g1, ishapes)
    graph_attr.set_shape_inputs(g2, ishapes)
    g1 = g1.apply("InferShape").apply("SimplifyInference")
    g2 = g2.apply("InferShape").apply("SimplifyInference")
    graph_util.check_graph_equal(g1, g2)
Exemplo n.º 5
0
 def check(shape, channels):
     x = sym.Variable("x")
     bias = sym.Variable("bias")
     scale = sym.Variable("scale")
     y1 = before(x, scale, channels)
     ishape = {"x": shape, "scale": (channels, ), "bias": (channels, )}
     g1 = nnvm.graph.create(y1)
     graph_attr.set_shape_inputs(g1, ishape)
     g2 = g1.apply("InferShape").apply("FoldScaleAxis")
     # assert graph equals as expected
     graph_util.check_graph_equal(g1, g2)
Exemplo n.º 6
0
def compare_graph(init, predict, nnvm_sym, ishape):
    caffe2_sym, params = nnvm.frontend.from_caffe2(init, predict)
    g1 = nnvm.graph.create(caffe2_sym)
    g2 = nnvm.graph.create(nnvm_sym)
    input_name = predict.external_input[0]
    ishapes = {input_name: ishape}
    graph_attr.set_shape_inputs(g1, ishapes)
    graph_attr.set_shape_inputs(g2, ishapes)
    g1 = g1.apply("InferShape").apply("SimplifyInference")
    g2 = g2.apply("InferShape").apply("SimplifyInference")
    graph_util.check_graph_equal(g1, g2)
Exemplo n.º 7
0
def compare_graph(onnx_file, nnvm_sym, ishape):
    onnx_graph = onnx.load(onnx_file)
    onnx_sym, params = nnvm.frontend.from_onnx(onnx_graph)
    g1 = nnvm.graph.create(onnx_sym)
    g2 = nnvm.graph.create(nnvm_sym)
    ishapes = {'input_0': ishape}
    graph_attr.set_shape_inputs(g1, ishapes)
    graph_attr.set_shape_inputs(g2, ishapes)
    g1 = g1.apply("InferShape").apply("SimplifyInference")
    g2 = g2.apply("InferShape").apply("SimplifyInference")
    graph_util.check_graph_equal(g1, g2)
Exemplo n.º 8
0
 def check(shape, channels):
     x = sym.Variable("x")
     bias = sym.Variable("bias")
     scale = sym.Variable("scale")
     y1 = before(x, scale, channels)
     ishape = {"x": shape, "scale": (channels,), "bias": (channels,)}
     g1 = nnvm.graph.create(y1)
     graph_attr.set_shape_inputs(g1, ishape)
     g2 = g1.apply("InferShape").apply("FoldScaleAxis")
     # assert graph equals as expected
     graph_util.check_graph_equal(g1, g2)
Exemplo n.º 9
0
def compare_graph(init, predict, nnvm_sym, ishape):
    caffe2_sym, params = nnvm.frontend.from_caffe2(init, predict)
    g1 = nnvm.graph.create(caffe2_sym)
    g2 = nnvm.graph.create(nnvm_sym)
    input_name = predict.external_input[0]
    ishapes = {input_name: ishape}
    graph_attr.set_shape_inputs(g1, ishapes)
    graph_attr.set_shape_inputs(g2, ishapes)
    g1 = g1.apply("InferShape").apply("SimplifyInference")
    g2 = g2.apply("InferShape").apply("SimplifyInference")
    graph_util.check_graph_equal(g1, g2)
Exemplo n.º 10
0
def compare_graph(onnx_file, nnvm_sym, ishape):
    onnx_model = onnx.load_model(onnx_file)
    onnx_sym, params = nnvm.frontend.from_onnx(onnx_model)
    g1 = nnvm.graph.create(onnx_sym)
    g2 = nnvm.graph.create(nnvm_sym)
    input_name = onnx_model.graph.input[0].name
    ishapes = {input_name: ishape}
    graph_attr.set_shape_inputs(g1, ishapes)
    graph_attr.set_shape_inputs(g2, ishapes)
    g1 = g1.apply("InferShape").apply("SimplifyInference")
    g2 = g2.apply("InferShape").apply("SimplifyInference")
    graph_util.check_graph_equal(g1, g2)
Exemplo n.º 11
0
def compare_graph(onnx_file, nnvm_sym, ishape):
    onnx_model = onnx.load_model(onnx_file)
    onnx_sym, params = nnvm.frontend.from_onnx(onnx_model)
    g1 = nnvm.graph.create(onnx_sym)
    g2 = nnvm.graph.create(nnvm_sym)
    input_name = onnx_model.graph.input[0].name
    ishapes = {input_name: ishape}
    graph_attr.set_shape_inputs(g1, ishapes)
    graph_attr.set_shape_inputs(g2, ishapes)
    g1 = g1.apply("InferShape").apply("SimplifyInference")
    g2 = g2.apply("InferShape").apply("SimplifyInference")
    graph_util.check_graph_equal(g1, g2)
Exemplo n.º 12
0
 def check(shape, channels):
     x = sym.Variable("x") + 1
     weight = sym.Variable("weight")
     bias = sym.Variable("bias")
     in_scale = sym.Variable("in_scale")
     out_scale = sym.Variable("out_scale")
     y1 = before(x, weight, bias, in_scale, out_scale, channels)
     y2 = expected(x, weight, bias, in_scale, out_scale, channels)
     ishape = {"x": shape, "out_scale": (channels,), "in_scale": (shape[1],)}
     g1 = nnvm.graph.create(y1)
     g2 = nnvm.graph.create(y2)
     graph_attr.set_shape_inputs(g1, ishape)
     g1 = g1.apply("InferShape").apply("FoldScaleAxis")
     # assert graph equals as expected
     graph_util.check_graph_equal(g1, g2)
Exemplo n.º 13
0
 def check(shape, channels):
     x = sym.Variable("x") + 1
     weight = sym.Variable("weight")
     bias = sym.Variable("bias")
     in_scale = sym.Variable("in_scale")
     out_scale = sym.Variable("out_scale")
     y1 = before(x, weight, bias, in_scale, out_scale, channels)
     y2 = expected(x, weight, bias, in_scale, out_scale, channels)
     ishape = {"x": shape, "out_scale": (channels,), "in_scale": (shape[1],)}
     g1 = nnvm.graph.create(y1)
     g2 = nnvm.graph.create(y2)
     graph_attr.set_shape_inputs(g1, ishape)
     g1 = g1.apply("InferShape").apply("FoldScaleAxis")
     # assert graph equals as expected
     graph_util.check_graph_equal(g1, g2)
Exemplo n.º 14
0
def compare_graph(onnx_file, nnvm_sym, ishape):
    onnx_vars = [int(n) for n in onnx.__version__.split('.')] if hasattr(onnx, "__version__") else []
    if len(onnx_vars) >= 2 and (onnx_vars[0] > 0 or onnx_vars[1] >= 2):  # version >= 0.2
        onnx_model = onnx.load(onnx_file)
        onnx_sym, params = nnvm.frontend.from_onnx(onnx_model.graph)
    else:
        onnx_graph = onnx.load(onnx_file)
        onnx_sym, params = nnvm.frontend.from_onnx(onnx_graph)
    g1 = nnvm.graph.create(onnx_sym)
    g2 = nnvm.graph.create(nnvm_sym)
    ishapes = {'input_0': ishape}
    graph_attr.set_shape_inputs(g1, ishapes)
    graph_attr.set_shape_inputs(g2, ishapes)
    g1 = g1.apply("InferShape").apply("SimplifyInference")
    g2 = g2.apply("InferShape").apply("SimplifyInference")
    graph_util.check_graph_equal(g1, g2)
Exemplo n.º 15
0
 def check(dim, axis, nstep):
     eps = 0.01
     x = sym.Variable("x") + 1
     beta = sym.Variable("beta")
     gamma = sym.Variable("gamma")
     moving_var = sym.Variable("moving_var")
     moving_mean = sym.Variable("moving_mean")
     y1, y2 = x, sym.Variable("xx") + 1
     ishape = {"x": tuple(10 for i in range(dim))}
     for i in range(nstep):
         y1 = sym.batch_norm(
             y1 + 1, gamma, beta, moving_mean, moving_var, epsilon=eps, axis=axis)
         y1 = sym.dropout(y1)
         y2 = simple_bn(y2 + 1, gamma, beta, moving_mean, moving_var,
                        epsilon=eps, axis=axis, shape=ishape["x"])
     g = nnvm.graph.create(y1)
     g2 = nnvm.graph.create(y2)
     graph_attr.set_shape_inputs(g, ishape)
     g1 = g.apply("InferShape").apply("SimplifyInference")
     # assert graph equals as expected
     graph_util.check_graph_equal(g1, g2)