WZMIAOMIAO/deep-learning-for-image-processing · error · ValueError
Unsupported fields:{} in cfg
Error message
Unsupported fields:{} in cfg What it means
After parsing the .cfg into a list of dicts, parse_model_cfg checks every key in every module definition against a whitelist of supported fields. An unknown key (often a typo or a field from a newer/older YOLO cfg dialect) raises ValueError('Unsupported fields:{} in cfg').
Source
Thrown at pytorch_object_detection/yolov3_spp/build_utils/parse_config.py:56
else:
# TODO: .isnumeric() actually fails to get the float case
if val.isnumeric(): # return int or float 如果是数值的情况
mdefs[-1][key] = int(val) if (int(val) - float(val)) == 0 else float(val)
else:
mdefs[-1][key] = val # return string 是字符的情况
# check all fields are supported
supported = ['type', 'batch_normalize', 'filters', 'size', 'stride', 'pad', 'activation', 'layers', 'groups',
'from', 'mask', 'anchors', 'classes', 'num', 'jitter', 'ignore_thresh', 'truth_thresh', 'random',
'stride_x', 'stride_y', 'weights_type', 'weights_normalization', 'scale_x_y', 'beta_nms', 'nms_kind',
'iou_loss', 'iou_normalizer', 'cls_normalizer', 'iou_thresh', 'probability']
# 遍历检查每个模型的配置
for x in mdefs[1:]: # 0对应net配置
# 遍历每个配置字典中的key值
for k in x:
if k not in supported:
raise ValueError("Unsupported fields:{} in cfg".format(k))
return mdefs
def parse_data_cfg(path):
# Parses the data configuration file
if not os.path.exists(path) and os.path.exists('data' + os.sep + path): # add data/ prefix if omitted
path = 'data' + os.sep + path
with open(path, 'r') as f:
lines = f.readlines()
options = dict()
for line in lines:
line = line.strip()
if line == '' or line.startswith('#'):
continue
key, val = line.split('=')View on GitHub (pinned to 1ec3fe6f37)
Solutions
- Open the cfg at the reported key's block and remove or rename the unsupported field to one the parser supports
- Compare against the repo's bundled cfg files (cfg/yolov3-spp.cfg) and align your cfg with that dialect
- Update parse_config.py's supported set if you intentionally need the new field
Example fix
// before (in .cfg) [convolutional] batch_normalize=1 size=3 channels_out=128 // after (in .cfg) [convolutional] batch_normalize=1 size=3 filters=128
Defensive patterns
Strategy: validation
Validate before calling
supported = {'net','convolutional','maxpool','route','upsample','shortcut','yolo'}
import re
for block in re.findall(r'\[([^\]]+)\]', open(cfg).read()):
assert block.strip() in supported, f'unsupported block [{block}] in {cfg}' Try / catch
try:
mdefs = parse_model_cfg(cfg)
except ValueError as e:
if 'Unsupported fields' in str(e):
bad_key = e.args[0].split(':')[1].strip()
raise SystemExit(f'{cfg}: remove/rename unsupported key {bad_key}')
raise Prevention
- Start from the repo's bundled cfg and edit incrementally
- Diff custom cfgs against the stock yolov3-spp.cfg before training
- Check parse_config.py's supported set when adopting cfgs from other darknet forks
When it happens
Trigger: A [convolutional], [net], [yolo], [route], etc. block in the .cfg contains a key not in the supported set, e.g. misspelled 'batch_normalize' instead of 'batch_normalizing' variant, 'channels_out', or fields like 'groups'/'width_multiple' from other YOLO versions.
Common situations: Using a cfg copied from another YOLO repo (e.g. AlexeyAB/darknet cfgs with extra fields); hand-editing the cfg and typo-ing a key; upgrading the repo but keeping old cfgs.
Related errors
- the cfg file not exist...
- conv2d filter size must be int type.
- VOCdevkit dose not in path:'{}'.
- return_layers are not present in model
- VOCdevkit dose not in path:'{}'.
AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30).
Data as JSON: /api/errors/ce04083be356d055.
Report an issue: GitHub.