def test_upsampling_bilinear(): x = sym.Variable("x") scale = 2 y = sym.upsampling(x, scale=scale, method="BILINEAR", name="y", layout="NCHW") dtype = "float32" dshape = (1, 4, 32, 32) oshape = (1, 4, 32 * scale, 32 * scale) shape_dict = {"x": dshape} dtype_dict = {"x": dtype} for target, ctx in ctx_list(): graph, lib, _ = nnvm.compiler.build(y, target, shape_dict, dtype_dict) m = graph_runtime.create(graph, lib, ctx) a_np = np.random.uniform(size=dshape).astype(dtype) data = tvm.nd.array(a_np) m.run(x=data) out = m.get_output(0, tvm.nd.empty(oshape, dtype)) b_np = topi.testing.bilinear_resize_python(a_np, (32 * scale, 32 * scale), "NCHW", align_corners=False) tvm.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5, atol=1e-5)
def _impl(cls, inputs, args, params): width_scale = args['width_scale'] if 'width_scale' in args else 1 height_scale = args['height_scale'] if 'height_scale' in args else 1 assert width_scale == height_scale return _sym.upsampling( inputs[0], scale=int(width_scale), method="NEAREST_NEIGHBOR")
def get_sym(layout, kernel_layout, channels): data = sym.Variable(name="data") data = sym.conv2d(data=data, kernel_size=(3,3), channels=channels, padding=(1, 1), layout=layout, kernel_layout=kernel_layout, use_bias=True) data = sym.max_pool2d(data=data, pool_size=(2, 2), strides=(2, 2), layout=layout) data = sym.upsampling(data=data, scale=2, layout=layout) softmax_axis = 1 if layout == "NHWC": softmax_axis = 3 data = sym.softmax(data=data, axis=softmax_axis) return data
def test_upsampling_nearest_neighbor(): x = sym.Variable("x") scale = 2 y = sym.upsampling(x, scale=scale, name="y") dtype = "float32" dshape = (1, 16, 32, 32) oshape = (1, 16, 32*scale, 32*scale) shape_dict = {"x": dshape} for target, ctx in ctx_list(): graph, lib, _ = nnvm.compiler.build(y, target, shape_dict) m = graph_runtime.create(graph, lib, ctx) a_np = np.random.uniform(size=dshape).astype(dtype) data = tvm.nd.array(a_np) m.run(x=data) out = m.get_output(0, tvm.nd.empty(oshape, dtype)) b_np = topi.testing.upsampling_python(a_np, scale, "NCHW") np.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5)
def test_upsampling_nearest_neighbor(): x = sym.Variable("x") scale = 2 y = sym.upsampling(x, scale=scale, name="y") dtype = "float32" dshape = (1, 16, 32, 32) oshape = (1, 16, 32*scale, 32*scale) shape_dict = {"x": dshape} for target, ctx in ctx_list(): graph, lib, _ = nnvm.compiler.build(y, target, shape_dict) m = graph_runtime.create(graph, lib, ctx) a_np = np.random.uniform(size=dshape).astype(dtype) data = tvm.nd.array(a_np) m.run(x=data) out = m.get_output(0, tvm.nd.empty(oshape, dtype)) b_np = topi.testing.upsampling_python(a_np, scale, "NCHW") tvm.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5)