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

Refactoring detection task #3860

Merged
merged 28 commits into from
Aug 27, 2024

Conversation

sungchul2
Copy link
Contributor

@sungchul2 sungchul2 commented Aug 17, 2024

Summary

This PR includes:

  • Create criterion modules for each model
  • Enable Factory template for building model
  • Remove dict type config -> in the next PR due to the conflicts w/ iseg

How to test

Checklist

  • I have added unit tests to cover my changes.​
  • I have added integration tests to cover my changes.​
  • I have ran e2e tests and there is no issues.
  • I have added the description of my changes into CHANGELOG in my target branch (e.g., CHANGELOG in develop).​
  • I have updated the documentation in my target branch accordingly (e.g., documentation in develop).
  • I have linked related issues.

License

  • I submit my code changes under the same Apache License that covers the project.
    Feel free to contact the maintainers if that's a concern.
  • I have updated the license header for each file (see an example below).
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

@github-actions github-actions bot added DEPENDENCY Any changes in any dependencies (new dep or its version) should be produced via Change Request on PM TEST Any changes in tests BUILD OTX 2.0 labels Aug 17, 2024
@sungchul2 sungchul2 force-pushed the refactoring-detection branch 3 times, most recently from cc6cf41 to 7a3b01d Compare August 17, 2024 15:28
@kprokofi kprokofi added this to the 2.3.0 milestone Aug 19, 2024
@github-actions github-actions bot removed DEPENDENCY Any changes in any dependencies (new dep or its version) should be produced via Change Request on PM BUILD labels Aug 21, 2024
@sungchul2 sungchul2 force-pushed the refactoring-detection branch from 392f59d to 3d7187b Compare August 23, 2024 01:23
@sungchul2
Copy link
Contributor Author

@kprokofi @harimkang We changed modules' names that are affected by factory class to ~Module such as SSDHeadModule (previously NNSSDHead), but I found the below part that uses a module's name to internally patch a variable.
I'm not sure if similar parts are there more, but I think changing the module's name doesn't seem like an appropriate decision because we need to change all parts that are affected by our new decision.
I'd like to suggest setting factory's name such as SSDHeadBuilder instead.

background_class = hasattr(self.model, "bbox_head") and isinstance(self.model.bbox_head, SSDHead)

@eunwoosh
Copy link
Contributor

@kprokofi @harimkang We changed modules' names that are affected by factory class to ~Module such as SSDHeadModule (previously NNSSDHead), but I found the below part that uses a module's name to internally patch a variable. I'm not sure if similar parts are there more, but I think changing the module's name doesn't seem like an appropriate decision because we need to change all parts that are affected by our new decision. I'd like to suggest setting factory's name such as SSDHeadBuilder instead.

background_class = hasattr(self.model, "bbox_head") and isinstance(self.model.bbox_head, SSDHead)

Honestly, I think it's better to make factory function than factory class. Recently, factory class with __new__ implementation is often used, but it looks weird that output of SomeClass(...) isn't instance of SomeClass. If class is preferred, than I think using class method like SSDHeadBuilder.make is better. Anyway it looks good to decide a policy of factory class for model at this point.

@sungchul2
Copy link
Contributor Author

Honestly, I think it's better to make factory function than factory class. Recently, factory class with __new__ implementation is often used, but it looks weird that output of SomeClass(...) isn't instance of SomeClass. If class is preferred, than I think using class method like SSDHeadBuilder.make is better. Anyway it looks good to decide a policy of factory class for model at this point.

Yes, I think it's a problem that output of SomeClass(...) isn't instance of SomeClass as @eunwoosh said.
Using factory function can be alternative, but I think it is important to maintain module's name no matter what method we choose.
If we use factory class, we can change factory's name like below:

class SSDHead: ...

class SSDHeadBuilder:
    SSDHEAD_CFG: ClassVar[dict[str, Any]] = {...}
    def __new__(cls, version: str, ...):
        ...
        return SSDHead(**SSDHEAD_CFG[version], ...)

For factory function, we can use below:

SSDHEAD_CFG: dict[str, Any] = {...}
def ssd_head_builder(version: str, ...):
    ...
    return SSDHead(**SSDHEAD_CFG[version], ...)

Copy link
Contributor

@eunwoosh eunwoosh left a comment

Choose a reason for hiding this comment

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

Thanks for your work :)
I agree overall direction of this PR, I have a one thing to discuss.
I'm not sure that we should change every module like a factory class even if that module supports single case. IMHO, it's better to leave it as it is and change it later if that module needs to support multiple cases.
How do you think about that?

src/otx/algo/detection/backbones/backbone_factory.py Outdated Show resolved Hide resolved
src/otx/algo/detection/ssd.py Outdated Show resolved Hide resolved
src/otx/algo/detection/heads/atss_head.py Show resolved Hide resolved
src/otx/algo/detection/huggingface_model.py Outdated Show resolved Hide resolved
src/otx/algo/detection/detectors/single_stage_detector.py Outdated Show resolved Hide resolved
src/otx/algo/common/utils/coders/base_bbox_coder.py Outdated Show resolved Hide resolved
src/otx/algo/detection/atss.py Outdated Show resolved Hide resolved
src/otx/algo/detection/atss.py Outdated Show resolved Hide resolved
src/otx/algo/detection/backbones/backbone_factory.py Outdated Show resolved Hide resolved
src/otx/core/model/detection.py Show resolved Hide resolved
src/otx/core/model/detection.py Show resolved Hide resolved
@sungchul2
Copy link
Contributor Author

Thanks for your work :) I agree overall direction of this PR, I have a one thing to discuss. I'm not sure that we should change every module like a factory class even if that module supports single case. IMHO, it's better to leave it as it is and change it later if that module needs to support multiple cases. How do you think about that?

Yeah, it seems unnecessary but I think it must exist for scalability and unified structure.

@sungchul2 sungchul2 added this pull request to the merge queue Aug 27, 2024
Merged via the queue into openvinotoolkit:develop with commit 0a395b2 Aug 27, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TEST Any changes in tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants