WZMIAOMIAO/deep-learning-for-image-processing · error · FileNotFoundError
the cfg file not exist...
Error message
the cfg file not exist...
What it means
parse_model_cfg validates the model config path before reading: it must end with '.cfg' and exist on disk, otherwise FileNotFoundError('the cfg file not exist...') is raised. Note the message does not distinguish between bad extension and missing file.
Source
Thrown at pytorch_object_detection/yolov3_spp/build_utils/parse_config.py:8
import os
import numpy as np
def parse_model_cfg(path: str):
# 检查文件是否存在
if not path.endswith(".cfg") or not os.path.exists(path):
raise FileNotFoundError("the cfg file not exist...")
# 读取文件信息
with open(path, "r") as f:
lines = f.read().split("\n")
# 去除空行和注释行
lines = [x for x in lines if x and not x.startswith("#")]
# 去除每行开头和结尾的空格符
lines = [x.strip() for x in lines]
mdefs = [] # module definitions
for line in lines:
if line.startswith("["): # this marks the start of a new block
mdefs.append({})
mdefs[-1]["type"] = line[1:-1].strip() # 记录module类型
# 如果是卷积模块,设置默认不使用BN(普通卷积层后面会重写成1,最后的预测层conv保持为0)
if mdefs[-1]["type"] == "convolutional":
mdefs[-1]["batch_normalize"] = 0View on GitHub (pinned to 1ec3fe6f37)
Solutions
- Ensure the argument is the model .cfg file (e.g. cfg/yolov3-spp.cfg) and that the file exists
- Use an absolute path or run training from the project root
- Check you are not accidentally passing --weights to the --cfg argument
Example fix
// before
parser.add_argument('--cfg', default='cfg/yolov3-spp.cfg.bak', help='model.cfg path')
// after
parser.add_argument('--cfg', default='cfg/yolov3-spp.cfg', help='model.cfg path')
# and verify: import os; assert os.path.exists('cfg/yolov3-spp.cfg') Defensive patterns
Strategy: validation
Validate before calling
import os
cfg = args.cfg
assert cfg.endswith('.cfg') and os.path.exists(cfg), f'invalid cfg path: {cfg}' Try / catch
try:
module_defs = parse_model_cfg(cfg_path)
except FileNotFoundError:
raise SystemExit(f'cfg not found or bad extension: {cfg_path} - pass e.g. cfg/yolov3-spp.cfg') Prevention
- Keep .cfg files under a cfg/ directory in the repo and reference them relative to project root
- Never pass the .pt weights path as --cfg
- Check path.endswith('.cfg') and os.path.exists before calling parse_model_cfg
When it happens
Trigger: Calling parse_model_cfg(path) with a path that lacks the .cfg extension, or with a .cfg path that does not exist (typo, wrong CWD, file not downloaded).
Common situations: Passing the weights path (.pt) instead of the cfg path; relative cfg path resolved from wrong directory; yolov3-spp.cfg never copied into the project; Windows backslash path issues on Linux.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- %s does not exist
- Error loading data from {}. {}
- Unsupported fields:{} in cfg
- conv2d filter size must be int type.
- VOCdevkit dose not in path:'{}'.
AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30).
Data as JSON: /api/errors/a55ff4be08549fbd.
Report an issue: GitHub.