Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve YOLOv9 performance #3953

Merged
merged 14 commits into from
Sep 26, 2024
4 changes: 2 additions & 2 deletions src/otx/algo/detection/heads/yolo_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ def __init__(
csp_args: dict[str, Any] | None = None,
aux_cfg: dict[str, Any] | None = None,
with_nms: bool = True,
min_confidence: float = 0.05,
min_iou: float = 0.9,
min_confidence: float = 0.1,
min_iou: float = 0.65,
) -> None:
if len(csp_channels) - 1 != len(concat_sources):
msg = (
Expand Down
6 changes: 3 additions & 3 deletions src/otx/algo/detection/losses/yolov9_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,9 @@ def __init__(
loss_dfl: nn.Module | None = None,
loss_iou: nn.Module | None = None,
reg_max: int = 16,
cls_rate: float = 1.5,
dfl_rate: float = 7.5,
iou_rate: float = 0.5,
cls_rate: float = 0.5,
dfl_rate: float = 1.5,
iou_rate: float = 7.5,
aux_rate: float = 0.25,
) -> None:
super().__init__()
Expand Down
9 changes: 9 additions & 0 deletions src/otx/algo/detection/yolov9.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from otx.core.metrics.fmeasure import MeanAveragePrecisionFMeasureCallable
from otx.core.model.base import DefaultOptimizerCallable, DefaultSchedulerCallable
from otx.core.model.detection import OTXDetectionModel
from otx.core.types.export import TaskLevelExportParameters

if TYPE_CHECKING:
from lightning.pytorch.cli import LRSchedulerCallable, OptimizerCallable
Expand Down Expand Up @@ -135,6 +136,14 @@ def _exporter(self) -> OTXModelExporter:
output_names=None, # TODO (someone): support XAI
)

@property
def _export_parameters(self) -> TaskLevelExportParameters:
"""Defines parameters required to export a particular model implementation."""
return super()._export_parameters.wrap(
confidence_threshold=self.model.bbox_head.min_confidence,
iou_threshold=self.model.bbox_head.min_iou,
)

def to(self, *args, **kwargs) -> Self:
"""Sync device of the model and its components."""
ret = super().to(*args, **kwargs)
Expand Down
9 changes: 4 additions & 5 deletions src/otx/recipe/detection/yolov9_c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ model:
optimizer:
class_path: torch.optim.SGD
init_args:
lr: 0.001
lr: 0.0001
momentum: 0.937
weight_decay: 0.0005
nesterov: true
Expand Down Expand Up @@ -42,9 +42,8 @@ overrides:
input_size:
- 640
- 640
image_color_channel: BGR
train_subset:
batch_size: 16
batch_size: 10
transforms:
- class_path: otx.core.data.transform_libs.torchvision.CachedMosaic
init_args:
Expand Down Expand Up @@ -75,7 +74,7 @@ overrides:
class_path: otx.algo.samplers.balanced_sampler.BalancedSampler

val_subset:
batch_size: 16
batch_size: 10
transforms:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
Expand All @@ -95,7 +94,7 @@ overrides:
std: [255.0, 255.0, 255.0]

test_subset:
batch_size: 16
batch_size: 10
transforms:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
Expand Down
9 changes: 4 additions & 5 deletions src/otx/recipe/detection/yolov9_m.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ model:
optimizer:
class_path: torch.optim.SGD
init_args:
lr: 0.001
lr: 0.0001
momentum: 0.937
weight_decay: 0.0005
nesterov: true
Expand Down Expand Up @@ -42,9 +42,8 @@ overrides:
input_size:
- 640
- 640
image_color_channel: BGR
train_subset:
batch_size: 16
batch_size: 12
transforms:
- class_path: otx.core.data.transform_libs.torchvision.CachedMosaic
init_args:
Expand Down Expand Up @@ -75,7 +74,7 @@ overrides:
class_path: otx.algo.samplers.balanced_sampler.BalancedSampler

val_subset:
batch_size: 16
batch_size: 12
transforms:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
Expand All @@ -95,7 +94,7 @@ overrides:
std: [255.0, 255.0, 255.0]

test_subset:
batch_size: 16
batch_size: 12
transforms:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
Expand Down
14 changes: 5 additions & 9 deletions src/otx/recipe/detection/yolov9_s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ model:
label_info: 80

optimizer:
class_path: torch.optim.SGD
class_path: torch.optim.Adam
init_args:
lr: 0.01
momentum: 0.937
weight_decay: 0.0005
nesterov: true
lr: 0.001

scheduler:
class_path: otx.core.schedulers.LinearWarmupSchedulerCallable
Expand Down Expand Up @@ -42,9 +39,8 @@ overrides:
input_size:
- 640
- 640
image_color_channel: BGR
train_subset:
batch_size: 16
batch_size: 14
transforms:
- class_path: otx.core.data.transform_libs.torchvision.CachedMosaic
init_args:
Expand Down Expand Up @@ -75,7 +71,7 @@ overrides:
class_path: otx.algo.samplers.balanced_sampler.BalancedSampler

val_subset:
batch_size: 16
batch_size: 14
transforms:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
Expand All @@ -95,7 +91,7 @@ overrides:
std: [255.0, 255.0, 255.0]

test_subset:
batch_size: 16
batch_size: 14
transforms:
- class_path: otx.core.data.transform_libs.torchvision.Resize
init_args:
Expand Down
Loading