apocaliss92 commited on
Commit
50e6bdc
·
verified ·
1 Parent(s): 2991ff3

source: convert_lib — a Detect head must hold the box branch (cv2.* / one2one_cv2.*)

Browse files
Files changed (1) hide show
  1. source/convert_lib.py +11 -3
source/convert_lib.py CHANGED
@@ -115,15 +115,23 @@ _HEAD_MODULE = re.compile(r"^(/model\.\d+)/")
115
  def detect_head_prefix(ops: "Iterable[tuple[str, str]]") -> "Optional[str]":
116
  """The Ultralytics Detect module (``/model.22`` for YOLOv9, ``/model.23``
117
  for YOLO26): the module holding the graph's LAST Sigmoid, which is the
118
- class-score sigmoid (the Ultralytics exporter finds its head the same way).
 
119
  ``ops`` is ``(friendly_name, type_name)`` in graph order. None when the
120
- model is not an Ultralytics export — it is then quantised whole."""
 
121
  last = None
122
  for name, kind in ops:
123
  if kind == "Sigmoid":
124
  last = name
125
  match = _HEAD_MODULE.match(last) if last else None
126
- return match.group(1) if match else None
 
 
 
 
 
 
127
 
128
 
129
  def is_end_to_end_head(names: "Iterable[str]", head: str) -> bool:
 
115
  def detect_head_prefix(ops: "Iterable[tuple[str, str]]") -> "Optional[str]":
116
  """The Ultralytics Detect module (``/model.22`` for YOLOv9, ``/model.23``
117
  for YOLO26): the module holding the graph's LAST Sigmoid, which is the
118
+ class-score sigmoid (the Ultralytics exporter finds its head the same way),
119
+ provided that module holds the box branch (``cv2.*`` / ``one2one_cv2.*``).
120
  ``ops`` is ``(friendly_name, type_name)`` in graph order. None when the
121
+ model is not an Ultralytics detector — it then keeps NNCF's defaults."""
122
+ ops = list(ops)
123
  last = None
124
  for name, kind in ops:
125
  if kind == "Sigmoid":
126
  last = name
127
  match = _HEAD_MODULE.match(last) if last else None
128
+ if not match:
129
+ return None
130
+ head = match.group(1)
131
+ # `/model.N/` is also PyTorch's naming for any `self.model = nn.Sequential`:
132
+ # only a module that holds the box branch is a Detect head.
133
+ box_branch = (f"{head}/cv2.", f"{head}/one2one_cv2.")
134
+ return head if any(name.startswith(box_branch) for name, _ in ops) else None
135
 
136
 
137
  def is_end_to_end_head(names: "Iterable[str]", head: str) -> bool: