Update MLP module for RTDETR backward compatibility (#14901)
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
parent
121f2242e1
commit
08263f5737
2 changed files with 5 additions and 2 deletions
|
|
@ -8,6 +8,7 @@ from PIL import Image
|
||||||
from tests import CUDA_DEVICE_COUNT, CUDA_IS_AVAILABLE
|
from tests import CUDA_DEVICE_COUNT, CUDA_IS_AVAILABLE
|
||||||
from ultralytics.cfg import TASK2DATA, TASK2MODEL, TASKS
|
from ultralytics.cfg import TASK2DATA, TASK2MODEL, TASKS
|
||||||
from ultralytics.utils import ASSETS, WEIGHTS_DIR, checks
|
from ultralytics.utils import ASSETS, WEIGHTS_DIR, checks
|
||||||
|
from ultralytics.utils.torch_utils import TORCH_1_9
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
TASK_MODEL_DATA = [(task, WEIGHTS_DIR / TASK2MODEL[task], TASK2DATA[task]) for task in TASKS]
|
TASK_MODEL_DATA = [(task, WEIGHTS_DIR / TASK2MODEL[task], TASK2DATA[task]) for task in TASKS]
|
||||||
|
|
@ -57,6 +58,8 @@ def test_rtdetr(task="detect", model="yolov8n-rtdetr.yaml", data="coco8.yaml"):
|
||||||
# Warning: must use imgsz=640 (note also add coma, spaces, fraction=0.25 args to test single-image training)
|
# Warning: must use imgsz=640 (note also add coma, spaces, fraction=0.25 args to test single-image training)
|
||||||
run(f"yolo train {task} model={model} data={data} --imgsz= 160 epochs =1, cache = disk fraction=0.25")
|
run(f"yolo train {task} model={model} data={data} --imgsz= 160 epochs =1, cache = disk fraction=0.25")
|
||||||
run(f"yolo predict {task} model={model} source={ASSETS / 'bus.jpg'} imgsz=160 save save_crop save_txt")
|
run(f"yolo predict {task} model={model} source={ASSETS / 'bus.jpg'} imgsz=160 save save_crop save_txt")
|
||||||
|
if TORCH_1_9:
|
||||||
|
run(f"yolo predict {task} model='rtdetr-l.pt' source={ASSETS / 'bus.jpg'} imgsz=160 save save_crop save_txt")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(checks.IS_PYTHON_3_12, reason="MobileSAM with CLIP is not supported in Python 3.12")
|
@pytest.mark.skipif(checks.IS_PYTHON_3_12, reason="MobileSAM with CLIP is not supported in Python 3.12")
|
||||||
|
|
|
||||||
|
|
@ -186,8 +186,8 @@ class MLP(nn.Module):
|
||||||
def forward(self, x):
|
def forward(self, x):
|
||||||
"""Forward pass for the entire MLP."""
|
"""Forward pass for the entire MLP."""
|
||||||
for i, layer in enumerate(self.layers):
|
for i, layer in enumerate(self.layers):
|
||||||
x = self.act(layer(x)) if i < self.num_layers - 1 else layer(x)
|
x = getattr(self, "act", nn.ReLU())(layer(x)) if i < self.num_layers - 1 else layer(x)
|
||||||
return x.sigmoid() if self.sigmoid else x
|
return x.sigmoid() if getattr(self, "sigmoid", False) else x
|
||||||
|
|
||||||
|
|
||||||
class LayerNorm2d(nn.Module):
|
class LayerNorm2d(nn.Module):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue