invoke-ai/InvokeAI · error · ValueError

Invalid RealESRGAN model: {self.model_name}

Error message

Invalid RealESRGAN model: {self.model_name}

What it means

The RealESRGAN upscale invocation only recognizes a fixed set of model names (its ESRGAN_MODEL_URLS map keys, e.g. RealESRGAN_x4plus, RealESRGAN_x2plus, and the anime variants). When self.model_name is not a key of that map, it logs and raises ValueError.

Source

Thrown at invokeai/app/invocations/upscale.py:90

                num_grow_ch=32,
                scale=4,
            )
            netscale = 4
        elif self.model_name in ["RealESRGAN_x2plus.pth"]:
            # x2 RRDBNet model
            rrdbnet_model = RRDBNet(
                num_in_ch=3,
                num_out_ch=3,
                num_feat=64,
                num_block=23,
                num_grow_ch=32,
                scale=2,
            )
            netscale = 2
        else:
            msg = f"Invalid RealESRGAN model: {self.model_name}"
            context.logger.error(msg)
            raise ValueError(msg)

        loadnet = context.models.load_remote_model(
            source=ESRGAN_MODEL_URLS[self.model_name],
        )

        with loadnet as loadnet_model:
            upscaler = RealESRGAN(
                scale=netscale,
                loadnet=loadnet_model,
                model=rrdbnet_model,
                half=False,
                tile=self.tile_size,
            )

            # prepare image - Real-ESRGAN uses cv2 internally, and cv2 uses BGR vs RGB for PIL
            # TODO: This strips the alpha... is that okay?
            cv2_image = cv2.cvtColor(np.array(image.convert("RGB")), cv2.COLOR_RGB2BGR)
            upscaled_image = upscaler.upscale(cv2_image)

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Set model_name to one of the exact keys in ESRGAN_MODEL_URLS (e.g. 'RealESRGAN_x4plus')
  2. Update stale workflows to current RealESRGAN model names
  3. Check the invocation's model_name enum/field description for the accepted list

Example fix

// before
model_name="RealESRGAN_x4"
// after
model_name="RealESRGAN_x4plus"
Defensive patterns

Strategy: validation

Validate before calling

from invokeai.app.invocations.upscale import ESRGAN_MODEL_URLS
if model_name not in ESRGAN_MODEL_URLS:
    raise ValueError(f"model_name must be one of {sorted(ESRGAN_MODEL_URLS)}, got {model_name!r}")

Type guard

def is_valid_realesrgan_model(name: str) -> bool:
    from invokeai.app.invocations.upscale import ESRGAN_MODEL_URLS
    return name in ESRGAN_MODEL_URLS

Try / catch

try:
    output = invocation.invoke(context)
except ValueError as e:
    if str(e).startswith("Invalid RealESRGAN model"):
        invocation.model_name = "RealESRGAN_x4plus"
        output = invocation.invoke(context)
    else:
        raise

Prevention

When it happens

Trigger: Passing model_name values like 'RealESRGAN_x4plus_anime_6B' misspelled, 'esrgan-x4', or any name absent from ESRGAN_MODEL_URLS when invoking the upscale invocation.

Common situations: Workflow JSON referencing a model renamed across InvokeAI versions; mixing up RealESRGAN names with plain ESRGAN model names; typo or wrong capitalization.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/e0773a06fb11daca. Report an issue: GitHub.