Modification on yolo11 for OBB

hi ,I modified yolo11 OBB architecture to this :

backbone:

[from, repeats, module, args]

  • [-1, 1, Conv, [64, 3, 2]] # 0-P1/2
  • [-1, 1, Conv, [128, 3, 2]] # 1-P2/4
  • [-1, 2, C3k2, [256, False, 0.25]]
  • [-1, 1, Conv, [256, 3, 2]] # 3-P3/8
  • [-1, 2, C3k2, [512, False, 0.25]]
  • [-1, 1, Conv, [512, 3, 2]] # 5-P4/16
  • [-1, 2, C3k2, [512, True]]
  • [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32
  • [-1, 2, C3k2, [1024, True]]
  • [-1, 1, SPPF, [1024, 5]] # 9
  • [-1, 2, C2PSA, [1024]] # 10

YOLO11n head

head:

  • [-1, 1, nn.Upsample, [None, 2, “nearest”]]

  • [[-1, 6], 1, Concat, [1]] # cat backbone P4

  • [-1, 2, C3k2, [512, False]] # 13

  • [-1, 1, CBAM, [512]]

  • [-1, 1, nn.Upsample, [None, 2, “nearest”]]

  • [[-1, 4], 1, Concat, [1]] # cat backbone P3

  • [-1, 2, C3k2, [256, False]] # 16 (P3/8-small)

  • [-1, 1, CBAM, [256]]

  • [-1, 1, Conv, [256, 3, 1]] #modified for supersmall size

  • [[-1, 2], 1, Concat, [1]]

  • [-1, 2, C3k2, [256, False]]

  • [-1, 1, CBAM, [256]]

  • [-1, 1, Conv, [256, 3, 2]]

  • [[-1, 13], 1, Concat, [1]] # cat head P4

  • [-1, 2, C3k2, [512, False]] # 19 (P4/16-medium)

  • [-1, 1, CBAM, [512]]

  • [-1, 1, Conv, [512, 3, 2]]

  • [[-1, 10], 1, Concat, [1]] # cat head P5

  • [-1, 2, C3k2, [1024, True]] # 22 (P5/32-large)

  • [-1, 1, CBAM, [1024]]

  • [[18, 22, 26, 30], 1, OBB, [nc, 1]] # Detect(P3, P4, P5, P3-supersmall)

when i add this super small part:

  • [-1, 1, Conv, [256, 3, 1]] #modified for supersmall size
  • [[-1, 2], 1, Concat, [1]]
  • [-1, 2, C3k2, [256, False]]
  • [-1, 1, CBAM, [256]]
    i faced with this error when i implement model = YOLO(“yolo11x-obb.yaml”) :
    RuntimeError Traceback (most recent call last)
    Cell In[2], line 2
    1 from ultralytics import YOLO
    ----> 2 model = YOLO(“yolo11x-obb.yaml”)

File /opt/conda/lib/python3.10/site-packages/ultralytics/models/yolo/model.py:23, in YOLO.init(self, model, task, verbose)
20 self.dict = new_instance.dict
21 else:
22 # Continue with default YOLO initialization
—> 23 super().init(model=model, task=task, verbose=verbose)

File /opt/conda/lib/python3.10/site-packages/ultralytics/engine/model.py:143, in Model.init(self, model, task, verbose)
141 # Load or create new YOLO model
142 if Path(model).suffix in {“.yaml”, “.yml”}:
→ 143 self._new(model, task=task, verbose=verbose)
144 else:
145 self._load(model, task=task)

File /opt/conda/lib/python3.10/site-packages/ultralytics/engine/model.py:251, in Model._new(self, cfg, task, model, verbose)
249 self.cfg = cfg
250 self.task = task or guess_model_task(cfg_dict)
→ 251 self.model = (model or self._smart_load(“model”))(cfg_dict, verbose=verbose and RANK == -1) # build model
252 self.overrides[“model”] = self.cfg
253 self.overrides[“task”] = self.task

File /opt/conda/lib/python3.10/site-packages/ultralytics/nn/tasks.py:399, in OBBModel.init(self, cfg, ch, nc, verbose)
397 def init(self, cfg=“yolov8n-obb.yaml”, ch=3, nc=None, verbose=True):
398 “”“Initialize YOLOv8 OBB model with given config and parameters.”“”
→ 399 super().init(cfg=cfg, ch=ch, nc=nc, verbose=verbose)

File /opt/conda/lib/python3.10/site-packages/ultralytics/nn/tasks.py:338, in DetectionModel.init(self, cfg, ch, nc, verbose)
335 return self.forward(x)[“one2many”]
336 return self.forward(x)[0] if isinstance(m, (Segment, Pose, OBB)) else self.forward(x)
→ 338 m.stride = torch.tensor([s / x.shape[-2] for x in _forward(torch.zeros(1, ch, s, s))]) # forward
339 self.stride = m.stride
340 m.bias_init() # only run once

File /opt/conda/lib/python3.10/site-packages/ultralytics/nn/tasks.py:336, in DetectionModel.init.._forward(x)
334 if self.end2end:
335 return self.forward(x)[“one2many”]
→ 336 return self.forward(x)[0] if isinstance(m, (Segment, Pose, OBB)) else self.forward(x)

File /opt/conda/lib/python3.10/site-packages/ultralytics/nn/tasks.py:114, in BaseModel.forward(self, x, *args, **kwargs)
112 if isinstance(x, dict): # for cases of training and validating while training.
113 return self.loss(x, *args, **kwargs)
→ 114 return self.predict(x, *args, **kwargs)

File /opt/conda/lib/python3.10/site-packages/ultralytics/nn/tasks.py:132, in BaseModel.predict(self, x, profile, visualize, augment, embed)
130 if augment:
131 return self._predict_augment(x)
→ 132 return self._predict_once(x, profile, visualize, embed)

File /opt/conda/lib/python3.10/site-packages/ultralytics/nn/tasks.py:153, in BaseModel._predict_once(self, x, profile, visualize, embed)
151 if profile:
152 self._profile_one_layer(m, x, dt)
→ 153 x = m(x) # run
154 y.append(x if m.i in self.save else None) # save output
155 if visualize:

File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1553, in Module._wrapped_call_impl(self, *args, **kwargs)
1551 return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc]
1552 else:
→ 1553 return self._call_impl(*args, **kwargs)

File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1562, in Module._call_impl(self, *args, **kwargs)
1557 # If we don’t have any hooks, we want to skip the rest of the logic in
1558 # this function, and just call forward.
1559 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
1560 or _global_backward_pre_hooks or _global_backward_hooks
1561 or _global_forward_hooks or _global_forward_pre_hooks):
→ 1562 return forward_call(*args, **kwargs)
1564 try:
1565 result = None

File /opt/conda/lib/python3.10/site-packages/ultralytics/nn/modules/conv.py:333, in Concat.forward(self, x)
331 def forward(self, x):
332 “”“Forward pass for the YOLOv8 mask Proto module.”“”
→ 333 return torch.cat(x, self.d)

RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 32 but got size 64 for tensor number 1 in the list.

can you help me thank you.

This is probably why

Fully custom modifications to the models are going to be tricky and it’s going to be challenging for most people to provide you with support. In all likelihood you’ll have to experiment with whatever you want to use for the new structure until you get it to work.

1 Like