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

Add oriented bounding box head for object detection tasks #73

Open
wants to merge 80 commits into
base: main
Choose a base branch
from

Conversation

mak-en
Copy link

@mak-en mak-en commented Sep 17, 2024

This PR introduces oriented bounding box functionality for object detection tasks, built on top of DetectionModel.

Implemented classes

  • OBBDetectionModel
  • EfficientOBBoxHead
  • RotatedTaskAlignedAssigner
  • OBBLoaderTorch
  • OBBLoader
  • OBBDetectionLoss
  • DFLoss
  • RotatedBboxLoss
  • MeanAveragePrecisionOBB
  • OBBoxVisualizer

DrejcPesjak and others added 30 commits February 20, 2024 03:44
* Added ResNet variants

* ResNet50 example

* Simplified example

* fixed resnet config

* [Automated] Updated coverage badge

---------

Co-authored-by: Martin Kozlovsky <martin.kozlovsky@luxonis.com>
Co-authored-by: GitHub Actions <actions@github.com>
* fixed incorrect class property call

* fixed exporter uploading

* uploadCheckpoint uploads on every checkpoint epoch

* fix temp files names

* updated callback readme

* pre-commit run
* option to source custom code in CLI

* removed empty dicts

* [Automated] Updated coverage badge

---------

Co-authored-by: GitHub Actions <actions@github.com>
* option to source custom code in CLI

* removed empty dicts

* fixed issue with removed tensor metadata in match case statements
* forbid extra fields in config

* fixed configs
* automatic inference of attach index based on type signature

* added inference for input and x names
* fixed link in docs

* fixed repvgg backbone

* fixed efficientnet
* upload logs to mlflow

* added mlflwo instance

* multithread log upload

* fixed upload logs

* fixed log file path

* removed exceptions

* logging exceptions

* fixed typo

* reverted exception

* moved line

* replaced warning with error log

* Update trainer.py
* add archiver CLI

* add archiver callback

* add max_det parameter to EfficientBBoxHead

* add enum to categorize tasks for the implemented heads

* add archiver tests

* adjust Archiver to new nn archive format

* pre-comit formatting

* add LDF creation and adjust to new nn archive format

* update requirements.txt

* add opencv-python to requirements.txt

* add support for ImplicitKeypointBBoxHead

* remove support for ObjectDetectionSSD

* Update requirements.txt

* Added mlflow and removed opencv

* [Automated] Updated coverage badge

* add support for SegmentationHead and BiSeNetHead

* base archiver tests on model from luxonis-train instead of torchvision

* adjust head parameters to changes in NN Archive

* adjust keypoint detection head parameters to changes in NN Archive

* bugfix - make sure self.max_det is used in nms

* add max_det parameter to ImplicitKeypointBBoxHead

* adjust task categorization for ImplicitKeypointBBoxHead

* fixing  Windows PermissionError occuring on file deletion

* fixing Windows PermissionError occuring on file deletion due to unreleased logging handlers

* add method to remove file handlers keeping the log file open

* add a logging statement at the end of archiving

* add optuna_integration to requirements.txt

* add hard-coded solution to determining is_softmax parameter

* added help

---------

Co-authored-by: Martin Kozlovský <martin.kozlovsky@luxonis.com>
Co-authored-by: GitHub Actions <actions@github.com>
* extend NN Archive generation test coverage to cover all implemented heads

* [Automated] Updated coverage badge

---------

Co-authored-by: GitHub Actions <actions@github.com>
* uploading all checkpoints

* fix names

* removed comment
* handling SIGTERM signal

* resume argument takes path
* handling SIGTERM signal

* resume argument takes path

* basic task group labels support

* updated requirements

* fixed tests

* fixed loader test

* Update luxonis_train/models/luxonis_model.py

Co-authored-by: conorsim <60359299+conorsim@users.noreply.github.com>

---------

Co-authored-by: conorsim <60359299+conorsim@users.noreply.github.com>
* option to set torch matmul precision for tensor cores

* updated readme
* fixed reset not being called

* added metric resets

* removed inheritance

* proper oks reset

* removed unnecessary resets

* added annotations
* Added seed to config for reproducibility

* fixed seg drawing when using torch deterministic backend

* added deterministic order of creating nodes

* removed seed from example config

* added reproducability to inspect

* formatting

---------

Co-authored-by: DrejcPesjak <dp8949@student.uni-lj.si>
Co-authored-by: Martin Kozlovský <martin.kozlovsky@luxonis.com>
* support for custom loaders and datasets

* updated configs

* custom loaders in inspect command

* updated inspect for multi-task labels

* removed custom loader from test config

* deleted comment

* deleted comment

* removed custom dataset

* removed comment

* skipping archiver test untill fixed in luxonis-ml

* [Automated] Updated coverage badge

---------

Co-authored-by: GitHub Actions <actions@github.com>
Co-authored-by: GitHub Actions <actions@github.com>
Co-authored-by: GitHub Actions <actions@github.com>
Co-authored-by: GitHub Actions <actions@github.com>
Co-authored-by: GitHub Actions <actions@github.com>
Co-authored-by: Martin Kozlovsky <martin.kozlovsky@luxonis.com>
Co-authored-by: Martin Kozlovsky <martin.kozlovsky@luxonis.com>
Co-authored-by: Michal Sejak <hyas@seznam.cz>
Co-authored-by: GitHub Actions <actions@github.com>
Co-authored-by: Martin Kozlovsky <martin.kozlovsky@luxonis.com>
@mak-en mak-en added the enhancement New feature or request label Sep 17, 2024
@mak-en mak-en self-assigned this Sep 17, 2024
Copy link

Test Results

2 files  2 suites   18s ⏱️
2 tests 0 ✅ 0 💤 0 ❌ 2 🔥
4 runs  0 ✅ 0 💤 0 ❌ 4 🔥

For more details on these errors, see this check.

Results for commit 4265845.

@kozlov721 kozlov721 requested a review from a team as a code owner September 19, 2024 05:43
@kozlov721 kozlov721 requested review from tersekmatija and removed request for a team September 19, 2024 05:43
Copy link
Collaborator

@kozlov721 kozlov721 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of code duplication, confusing commented code and incorrect docstrings. Also please make sure the CI pipeline passes (see CONTRIBUTING.md for more info).
Otherwise looks good

@@ -257,3 +267,135 @@ def _get_final_assignments(
)

return assigned_labels, assigned_bboxes, assigned_scores


class RotatedTaskAlignedAssigner(TaskAlignedAssigner):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this to a separate file

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the name could be changed to OrientedTaskAlignedAssigner to be consistent with the OBB naming.

return out_target


class VarifocalLoss(nn.Module):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The VarifocalLoss is already implemented in luxonis_train.attached_modules.losses.adaptive_detection_loss

"""Select the positive anchor center in gt for rotated bounding
boxes.

Args:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring must be in epytext

"""
super().__init__(**kwargs)

if not isinstance(self.node, EfficientOBBoxHead):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary; the check is done automatically in BaseAttachedModule.

gt_cxcywhr = target[:, :, 1:]
mask_gt = (gt_cxcywhr.sum(-1, keepdim=True) > 0).float()

# TODO: log change of assigner (once common Logger)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no change of assigner to log

return stack([pt1, pt2, pt3, pt4], -2)


def xyxy2xywh(x: Tensor) -> Tensor:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already torchvision.ops.box_convert for this

return y


def xywh2xyxy(x: Tensor) -> Tensor:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

torchision.ops.box_convert

@@ -269,6 +405,128 @@ def bbox_iou(
return iou


def probiou(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more readable function name

return iou


def batch_probiou(obb1: Tensor, obb2: Tensor, eps: float = 1e-7) -> Tensor:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is almost identical to probiou, why do we need both?

@@ -411,6 +669,182 @@ def non_max_suppression(
return output


def non_max_suppression_obb(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is almost identical to non_max_suppression. Can you improve non_max_suppression to also support oriented bboxes instead of having this function?

klemen1999 and others added 4 commits September 20, 2024 11:41
Co-authored-by: Martin Kozlovsky <martin.kozlovsky@luxonis.com>
Co-authored-by: Martin Kozlovsky <martin.kozlovsky@luxonis.com>
Co-authored-by: GitHub Actions <actions@github.com>
@kozlov721 kozlov721 deleted the branch main October 9, 2024 10:35
@kozlov721 kozlov721 closed this Oct 9, 2024
@kozlov721 kozlov721 reopened this Oct 9, 2024
@kozlov721 kozlov721 changed the base branch from dev to main October 9, 2024 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants