(ishape, osize, fmt, mode, dtype=None)
| 16 | @pytest.mark.skipif(not is_cuda_available(), reason="only support cuda now") |
| 17 | def test_resize(): |
| 18 | def tester(ishape, osize, fmt, mode, dtype=None): |
| 19 | dtype = dtype or np.float32 |
| 20 | inp = tensor(np.random.randn(*ishape), dtype=dtype) |
| 21 | oshape = F.vision.resize(inp, osize, fmt, mode).shape |
| 22 | dout = tensor(np.random.randn(*oshape), dtype=dtype) |
| 23 | mge._full_sync() |
| 24 | gm = GradManager() |
| 25 | |
| 26 | @jit.xla_trace(without_host=True, capture_as_const=True) |
| 27 | def func(inp, dout, mode): |
| 28 | gm.attach([inp]) |
| 29 | with gm: |
| 30 | out = F.vision.resize(inp, osize, fmt, mode) |
| 31 | gm.backward(out, dout) |
| 32 | return out, inp.grad |
| 33 | |
| 34 | mge_rsts = func(inp, dout, mode) |
| 35 | xla_rsts = func(inp, dout, mode) |
| 36 | |
| 37 | for mge_rst, xla_rst in zip(mge_rsts, xla_rsts): |
| 38 | np.testing.assert_allclose(mge_rst.numpy(), xla_rst.numpy(), atol=1e-5) |
| 39 | |
| 40 | for mode in ["linear", "nearest"]: |
| 41 | tester((4, 3, 1, 1), (1, 1), "NCHW", mode) |
no test coverage detected