jax-ml/jax · error · ValueError

Unknown resize method "{s}"

Error message

Unknown resize method "{s}"

What it means

jax.image.scale's ResizeMethod.from_string parser only accepts a fixed set of method strings ('linear'/'bilinear', 'lanczos3', 'lanczos5', 'cubic'/'bicubic' and pytorch variants, 'nearest', 'area'). Any other string raises ValueError listing the unknown method.

Source

Thrown at jax/_src/image/scale.py:275

  @staticmethod
  def from_string(s: str):
    if s == 'nearest':
      return ResizeMethod.NEAREST
    if s in ['linear', 'bilinear', 'trilinear', 'triangle']:
      return ResizeMethod.LINEAR
    elif s == 'lanczos3':
      return ResizeMethod.LANCZOS3
    elif s == 'lanczos5':
      return ResizeMethod.LANCZOS5
    elif s in ['cubic', 'bicubic', 'tricubic']:
      return ResizeMethod.CUBIC
    elif s in ['cubic-pytorch', 'bicubic-pytorch']:
      return ResizeMethod.CUBIC_PYTORCH
    elif s == 'area':
      return ResizeMethod.AREA
    else:
      raise ValueError(f'Unknown resize method "{s}"')

_kernels = {
    ResizeMethod.LINEAR: (1, _fill_triangle_kernel),
    ResizeMethod.LANCZOS3: (3, lambda x: _fill_lanczos_kernel(3., x)),
    ResizeMethod.LANCZOS5: (5, lambda x: _fill_lanczos_kernel(5., x)),
    ResizeMethod.CUBIC: (2, _fill_keys_cubic_kernel),
    ResizeMethod.CUBIC_PYTORCH: (2, _fill_opencv_cubic_kernel),
    ResizeMethod.AREA: (1, _area_kernel),
}


# scale and translation here are scalar elements of an np.array, what is the
# correct type annotation?
def scale_and_translate(image, shape: core.Shape,
                        spatial_dims: Sequence[int],
                        scale, translation,
                        method: str | ResizeMethod,
                        antialias: bool = True,

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Use one of the supported strings or the ResizeMethod enum members directly (e.g. ResizeMethod.CUBIC)
  2. Validate/whitelist the string at config-load time against the known set
  3. Check the installed JAX version's supported list if using newer aliases

Example fix

# before
img2 = jax.image.resize(img, (64, 64), method='bicubic_tf')
# after
img2 = jax.image.resize(img, (64, 64), method='bicubic')
# or method=jax._src.image.scale.ResizeMethod.CUBIC
Defensive patterns

Strategy: validation

Validate before calling

VALID = {'linear','bilinear','lanczos3','lanczos5','cubic','bicubic','cubic-pytorch','bicubic-pytorch','nearest','area'}
if isinstance(method, str):
    assert method in VALID, f'method must be one of {VALID}'
jax.image.resize(img, shape, method=method)

Type guard

def is_valid_resize_method(s: str) -> bool:
    return s in {'linear','bilinear','lanczos3','lanczos5','cubic','bicubic','cubic-pytorch','bicubic-pytorch','nearest','area'}

Try / catch

try:
    jax.image.resize(img, shape, method=m)
except ValueError as e:
    if 'Unknown resize method' in str(e):
        m = 'cubic'  # safe fallback
        jax.image.resize(img, shape, method=m)

Prevention

When it happens

Trigger: Passing method='bicubic_tf', 'trilinear', a typo like 'lanczos4', or an enum passed as a non-matching string to jax.image.resize / scale_and_translate.

Common situations: Porting code from torchvision/tf.image with method names that don't map to JAX's set; config files with stale method names after JAX upgrades renaming aliases.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/046b538b436a6fb3. Report an issue: GitHub.