WZMIAOMIAO/deep-learning-for-image-processing · error · KeyError
{} not in download_links
Error message
{} not in download_links What it means
The download script hardcodes model_name='regnetx_400mf' and checks it against the download_links dict, raising KeyError if the name has no entry. This prevents attempting an HTTP request with an unknown URL.
Source
Thrown at pytorch_classification/Test10_regnet/pretrain_weights.py:37
"regnety_600mf": 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-regnet/regnety_006-c67e57ec.pth',
"regnety_800mf": 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-regnet/regnety_008-dc900dbe.pth',
"regnety_1.6gf": 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-regnet/regnety_016-54367f74.pth',
"regnety_3.2gf": 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/regnety_032_ra-7f2439f9.pth',
"regnety_4.0gf": 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-regnet/regnety_040-f0d569f9.pth',
"regnety_6.4gf": 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-regnet/regnety_064-0a48325c.pth',
"regnety_8.0gf": 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-regnet/regnety_080-e7f3eb93.pth',
"regnety_12gf": 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-regnet/regnety_120-721ba79a.pth',
"regnety_16gf": 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-regnet/regnety_160-d64013cd.pth',
"regnety_32gf": 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-regnet/regnety_320-ba464b29.pth',
}
def main():
model_name = "regnetx_400mf"
print("download weights name: " + model_name)
if model_name not in download_links.keys():
raise KeyError("{} not in download_links".format(model_name))
headers = {"Content-Type": "application/json",
"Connection": "close",
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0"}
save_weights = "./" + model_name + ".pth"
req = requests.get(url=download_links[model_name],
stream=True, headers=headers, timeout=10)
req.raise_for_status()
info = int(req.headers["Content-Length"])
accumulate_data = 0
with open(save_weights, "wb") as f:
for data in req.iter_content(2048):
f.write(data)
accumulate_data += 2048
print("\rdownload: [{}Mb/{}Mb] {}%".format(int(accumulate_data / 1024 / 1024),View on GitHub (pinned to 1ec3fe6f37)
Solutions
- Set model_name to a key that exists in download_links (print download_links.keys() to inspect).
- Add a URL entry to download_links for the desired model.
- Use the name shown in the KeyError message guidance / supported training script defaults.
Example fix
// before model_name = "regnetx_4_0gf" // after model_name = "regnetx_400mf" # exists in download_links
Defensive patterns
Strategy: validation
Validate before calling
from pretrain_weights import download_links
name = "regnetx_400mf"
if name not in download_links:
raise SystemExit(f"{name} not available; choose from {sorted(download_links)}") Type guard
def is_downloadable(name: str) -> bool:
from pretrain_weights import download_links
return name in download_links Try / catch
try:
main()
except KeyError as e:
print(f"Unknown weights name {e}. Available: {sorted(download_links.keys())}") Prevention
- Only use names present in download_links
- Print download_links.keys() before editing model_name
- Add new URLs to download_links when introducing new variants
When it happens
Trigger: Running pretrain_weights.py after editing model_name to a value missing from download_links (e.g. 'regnetx_4_0gf'), or after download_links was trimmed.
Common situations: Users changing the hardcoded name to the variant they actually train, but no link was added for it.
Related errors
- not support model name: {}
- no match key '{}'
- not support data format '{self.data_format}'
- image: {} isn't RGB mode.
- Transformer input dimension should be divisible by head dime
AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30).
Data as JSON: /api/errors/bd996d555e90c90b.
Report an issue: GitHub.