def verify_UpsampleLayerParams(input_dim, scale, mode): dtype = "float32" a_np = np.full(input_dim, 1, dtype=dtype) if mode == 'NN': b_np = topi.testing.upsampling_python(a_np, scale) else: new_h = input_dim[2] * scale new_w = input_dim[3] * scale b_np = topi.testing.bilinear_resize_python(a_np, (new_h, new_w), 'NCHW') input = [('input', datatypes.Array(*input_dim))] output = [('output', datatypes.Array(*b_np.shape))] builder = NeuralNetworkBuilder(input, output) builder.add_upsample(name='Upsample', scaling_factor_h=scale, scaling_factor_w=scale, mode=mode, input_name='input', output_name='output') model = cm.models.MLModel(builder.spec) for target, ctx in ctx_list(): out = run_tvm_graph(model, target, ctx, a_np, 'input', b_np.shape, dtype) tvm.testing.assert_allclose(out, b_np, rtol=1e-5)
def verify_UpsampleLayerParams(input_dim, scale, mode): dtype = "float32" a_np = np.full(input_dim, 1, dtype=dtype) if mode == "NN": b_np = tvm.topi.testing.upsampling_python(a_np, (scale, scale)) else: new_h = input_dim[2] * scale new_w = input_dim[3] * scale b_np = tvm.topi.testing.bilinear_resize_python(a_np, (new_h, new_w), "NCHW") input = [("input", datatypes.Array(*input_dim))] output = [("output", datatypes.Array(*b_np.shape))] builder = NeuralNetworkBuilder(input, output) builder.add_upsample( name="Upsample", scaling_factor_h=scale, scaling_factor_w=scale, mode=mode, input_name="input", output_name="output", ) model = cm.models.MLModel(builder.spec) for target, dev in tvm.testing.enabled_targets(): out = run_tvm_graph(model, target, dev, a_np, "input", b_np.shape, dtype) tvm.testing.assert_allclose(out, b_np, rtol=1e-5)
def verify_UpsampleLayerParams(input_dim, scale, mode): dtype = "float32" a_np = np.full(input_dim, 1, dtype=dtype) if mode == 'NN': b_np = topi.testing.upsampling_python(a_np, scale) else: new_h = input_dim[2] * scale new_w = input_dim[3] * scale b_np = topi.testing.bilinear_resize_python(a_np, (new_h, new_w), 'NCHW') input = [('input', datatypes.Array(*input_dim))] output = [('output', datatypes.Array(*b_np.shape))] builder = NeuralNetworkBuilder(input, output) builder.add_upsample(name='Upsample', scaling_factor_h=scale, scaling_factor_w=scale, mode=mode, input_name='input', output_name='output') model = cm.models.MLModel(builder.spec) for target, ctx in ctx_list(): out = run_tvm_graph(model, a_np, 'input', b_np.shape, dtype) tvm.testing.assert_allclose(out, b_np, rtol=1e-5)
def verify_UpsampleLayerParams(input_dim, scale, mode): dtype = "float32" a_np = np.full(input_dim, 1, dtype=dtype) if mode == "NN": method = "nearest_neighbor" coord_trans = "asymmetric" else: method = "linear" coord_trans = "align_corners" b_np = tvm.topi.testing.resize2d_python(a_np, (scale, scale), "NCHW", method, coord_trans) input = [("input", datatypes.Array(*input_dim))] output = [("output", datatypes.Array(*b_np.shape))] builder = NeuralNetworkBuilder(input, output) builder.add_upsample( name="Upsample", scaling_factor_h=scale, scaling_factor_w=scale, mode=mode, input_name="input", output_name="output", ) model = cm.models.MLModel(builder.spec) for target, dev in tvm.testing.enabled_targets(): out = run_tvm_graph(model, target, dev, a_np, "input", b_np.shape, dtype) tvm.testing.assert_allclose(out, b_np, rtol=1e-5)
def test_upsample_converter(self): input_dim = (1, 1, 1) output_dim = (1, 2, 2) input = [('input', datatypes.Array(*input_dim))] output = [('output', datatypes.Array(*output_dim))] builder = NeuralNetworkBuilder(input, output) builder.add_upsample(name='Upsample', scaling_factor_h=2, scaling_factor_w=2, input_name='input', output_name='output') model_onnx = convert_coreml(builder.spec) self.assertTrue(model_onnx is not None)
def test_upsample_converter(self): input_dim = (1, 1, 1) output_dim = (1, 2, 2) input = [('input', datatypes.Array(*input_dim))] output = [('output', datatypes.Array(*output_dim))] builder = NeuralNetworkBuilder(input, output) builder.add_upsample(name='Upsample', scaling_factor_h=2, scaling_factor_w=2, input_name='input', output_name='output') context = ConvertContext() node = UpsampleLayerConverter.convert( context, builder.spec.neuralNetwork.layers[0], ['input'], ['output']) self.assertTrue(node is not None)