def testResizeUp(self, dtype, image_shape, target_shape, method): data = [64, 32, 32, 64, 50, 100] expected_data = {} expected_data["linear"] = [ 64.0, 56.0, 40.0, 32.0, 56.0, 52.0, 44.0, 40.0, 40.0, 44.0, 52.0, 56.0, 36.5, 45.625, 63.875, 73.0, 45.5, 56.875, 79.625, 91.0, 50.0, 62.5, 87.5, 100.0 ] expected_data["lanczos3"] = [ 75.8294, 59.6281, 38.4313, 22.23, 60.6851, 52.0037, 40.6454, 31.964, 35.8344, 41.0779, 47.9383, 53.1818, 24.6968, 43.0769, 67.1244, 85.5045, 35.7939, 56.4713, 83.5243, 104.2017, 44.8138, 65.1949, 91.8603, 112.2413 ] expected_data["lanczos5"] = [ 77.5699, 60.0223, 40.6694, 23.1219, 61.8253, 51.2369, 39.5593, 28.9709, 35.7438, 40.8875, 46.5604, 51.7041, 21.5942, 43.5299, 67.7223, 89.658, 32.1213, 56.784, 83.984, 108.6467, 44.5802, 66.183, 90.0082, 111.6109 ] expected_data["cubic"] = [ 70.1453, 59.0252, 36.9748, 25.8547, 59.3195, 53.3386, 41.4789, 35.4981, 36.383, 41.285, 51.0051, 55.9071, 30.2232, 42.151, 65.8032, 77.731, 41.6492, 55.823, 83.9288, 98.1026, 47.0363, 62.2744, 92.4903, 107.7284 ] x = np.array(data, dtype=dtype).reshape(image_shape) output = image.resize(x, target_shape, method) expected = np.array(expected_data[method], dtype=dtype).reshape(target_shape) self.assertAllClose(output, expected, atol=1e-04)
def onnx_upsample(x, scales: float, mode='nearest'): sizes = jnp.asarray(x.shape) * scales sizes = sizes.astype(jnp.int32) if mode == 'nearest': method = ResizeMethod.NEAREST elif mode == 'linear': method = ResizeMethod.LINEAR elif mode == 'cubic': method = ResizeMethod.CUBIC else: raise NotImplemented(f"Resize mode: {mode}") return resize(image=x, shape=sizes, method=method, antialias=True)
def upsample(image): b, h, w, c = image.shape upsampled_image = ji.resize(image, [b, 2 * h, 2 * w, c], 'nearest') return upsampled_image
def resize(img, shape): n, _, _, c = img.shape return image.resize(img, (n, ) + shape + (c, ), 'nearest')
def __call__(self, img): return image.resize(img, self.size, "bilinear").reshape(-1)