WZMIAOMIAO/deep-learning-for-image-processing · error · KeyError

not support model name: {}

Error message

not support model name: {}

What it means

Factory function create_regnet looks up the lowercased, underscore-normalized model name in model_cfgs and raises KeyError (after printing the supported names) if absent. This catches invalid model_name strings before constructing a RegNet.

Source

Thrown at pytorch_classification/Test10_regnet/model.py:308

        stage_widths, stage_depths = np.unique(widths, return_counts=True)
        stage_groups = [cfg['group_w'] for _ in range(num_stages)]
        stage_widths, stage_groups = adjust_width_groups_comp(stage_widths, stage_groups)

        info = []
        for i in range(num_stages):
            info.append(dict(out_c=stage_widths[i],
                             depth=stage_depths[i],
                             group_width=stage_groups[i],
                             se_ratio=cfg["se_ratio"]))

        return info


def create_regnet(model_name="RegNetX_200MF", num_classes=1000):
    model_name = model_name.lower().replace("-", "_")
    if model_name not in model_cfgs.keys():
        print("support model name: \n{}".format("\n".join(model_cfgs.keys())))
        raise KeyError("not support model name: {}".format(model_name))

    model = RegNet(cfg=model_cfgs[model_name], num_classes=num_classes)
    return model

View on GitHub (pinned to 1ec3fe6f37)

Solutions

  1. Use an exact supported key; the printed list from the KeyError message shows all valid names.
  2. Normalize your name the same way the function does: lower() and replace('-','_') before checking.
  3. Add a new entry to model_cfgs if you genuinely need an unsupported variant.

Example fix

// before
model = create_regnet("RegNetY-400MF", num_classes=5)
// after
model = create_regnet("RegNetX-400MF", num_classes=5)  # key present in model_cfgs
Defensive patterns

Strategy: validation

Validate before calling

def safe_create_regnet(model_name, num_classes):
    key = model_name.lower().replace("-", "_")
    from model import model_cfgs
    if key not in model_cfgs:
        raise KeyError(f"{key} not supported. Valid: {sorted(model_cfgs)}")
    return create_regnet(model_name, num_classes)

Type guard

def is_supported_regnet(name: str, valid_keys) -> bool:
    return name.lower().replace("-", "_") in valid_keys

Try / catch

try:
    model = create_regnet(args.model, num_classes=5)
except KeyError as e:
    print(f"Unsupported model {e}; falling back to RegNetX_200MF")
    model = create_regnet("RegNetX_200MF", num_classes=5)

Prevention

When it happens

Trigger: Calling create_regnet('RegNetY-400MF') or a typo like 'regnet_x_400' when only specific X-variant keys exist in model_cfgs.

Common situations: Copy-pasted names from papers/blogs ('RegNetX400MF', hyphenated variants), requesting Y/F variants not defined in this repo.

Related errors


AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30). Data as JSON: /api/errors/2feeb99cde20744f. Report an issue: GitHub.