{"record":{"id":"a55ff4be08549fbd","repo":"WZMIAOMIAO/deep-learning-for-image-processing","slug":"the-cfg-file-not-exist","errorCode":null,"errorMessage":"the cfg file not exist...","messagePattern":"the cfg file not exist\\.\\.\\.","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"pytorch_object_detection/yolov3_spp/build_utils/parse_config.py","lineNumber":8,"sourceCode":"import os\nimport numpy as np\n\n\ndef parse_model_cfg(path: str):\n    # 检查文件是否存在\n    if not path.endswith(\".cfg\") or not os.path.exists(path):\n        raise FileNotFoundError(\"the cfg file not exist...\")\n\n    # 读取文件信息\n    with open(path, \"r\") as f:\n        lines = f.read().split(\"\\n\")\n\n    # 去除空行和注释行\n    lines = [x for x in lines if x and not x.startswith(\"#\")]\n    # 去除每行开头和结尾的空格符\n    lines = [x.strip() for x in lines]\n\n    mdefs = []  # module definitions\n    for line in lines:\n        if line.startswith(\"[\"):  # this marks the start of a new block\n            mdefs.append({})\n            mdefs[-1][\"type\"] = line[1:-1].strip()  # 记录module类型\n            # 如果是卷积模块，设置默认不使用BN(普通卷积层后面会重写成1，最后的预测层conv保持为0)\n            if mdefs[-1][\"type\"] == \"convolutional\":\n                mdefs[-1][\"batch_normalize\"] = 0","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/WZMIAOMIAO/deep-learning-for-image-processing/blob/1ec3fe6f374fc9969973a61f819de25658595afa/pytorch_object_detection/yolov3_spp/build_utils/parse_config.py#L1-L26","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nparser.add_argument('--cfg', default='cfg/yolov3-spp.cfg.bak', help='model.cfg path')\n// after\nparser.add_argument('--cfg', default='cfg/yolov3-spp.cfg', help='model.cfg path')\n# and verify: import os; assert os.path.exists('cfg/yolov3-spp.cfg')","handlingStrategy":"validation","validationCode":"import os\ncfg = args.cfg\nassert cfg.endswith('.cfg') and os.path.exists(cfg), f'invalid cfg path: {cfg}'","typeGuard":null,"tryCatchPattern":"try:\n    module_defs = parse_model_cfg(cfg_path)\nexcept FileNotFoundError:\n    raise SystemExit(f'cfg not found or bad extension: {cfg_path} - pass e.g. cfg/yolov3-spp.cfg')","preventionTips":["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"],"tags":["python","file-not-found","yolo","config"],"backgroundTag":"file-not-found","analyzedSha":"1ec3fe6f374fc9969973a61f819de25658595afa","analyzedAt":"2026-08-30T09:19:11.901Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}