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

Move yolox to object_detection module #167

Merged
merged 2 commits into from
Nov 5, 2021
Merged

Conversation

r-b-g-b
Copy link
Contributor

@r-b-g-b r-b-g-b commented Nov 5, 2021

Closes #139

The cycle we're up against:

  • data.video.load_video_frames
  • models.megadetector_lite_yolox
  • models.init
  • models.efficientnet_models
  • pytorch_lightning.utils.ZambaVideoClassificationLightningModule
  • data.video.VideoLoaderConfig

In summary, the frame loader needs YoloX, which is in zamba.models so calls that zamba.models.__init__, which instantiates all models for the registry. For example, efficientnet loads the base class ZambaVideoClassificationLightningModule, which loads the zamba.data.video.VideoLoaderConfig. And there's our cycle.

The simplest way to resolve the circular import issue seemed to be to move YoloX code out of models and into its own zamba.object_detection module.

I updated the docs to reflect that; I think I caught everything.

@r-b-g-b r-b-g-b changed the title Move yolox to object_detection module and update references and docs Move yolox to object_detection module Nov 5, 2021
@r-b-g-b r-b-g-b requested review from pjbull and ejm714 November 5, 2021 16:59
@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2021

@codecov
Copy link

codecov bot commented Nov 5, 2021

Codecov Report

Merging #167 (f00257b) into master (b82c3f8) will increase coverage by 0.0%.
The diff coverage is 95.4%.

@@          Coverage Diff           @@
##           master    #167   +/-   ##
======================================
  Coverage    84.9%   85.0%           
======================================
  Files          28      30    +2     
  Lines        1839    1843    +4     
======================================
+ Hits         1563    1567    +4     
  Misses        276     276           
Impacted Files Coverage Δ
zamba/__init__.py 100.0% <ø> (ø)
zamba/object_detection/yolox/yolox_base.py 18.7% <ø> (ø)
zamba/pytorch_lightning/utils.py 97.4% <ø> (+0.6%) ⬆️
zamba/models/registry.py 85.7% <85.7%> (ø)
zamba/data/video.py 79.7% <100.0%> (ø)
zamba/models/__init__.py 100.0% <100.0%> (ø)
zamba/models/efficientnet_models.py 100.0% <100.0%> (ø)
zamba/models/model_manager.py 84.1% <100.0%> (+<0.1%) ⬆️
zamba/models/slowfast_models.py 88.5% <100.0%> (+0.3%) ⬆️
zamba/object_detection/__init__.py 100.0% <100.0%> (ø)
... and 2 more

Copy link
Member

@pjbull pjbull left a comment

Choose a reason for hiding this comment

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

Code change looks great to me pending tests passing 🎉 !

@ejm714
Copy link
Collaborator

ejm714 commented Nov 5, 2021

Still curious if there's a simpler way. Seems like only importing VideoLoaderConfig in pytorch_lightning.utils for type checking might resolve this without needing to move YOLOX?

@pjbull
Copy link
Member

pjbull commented Nov 5, 2021

I kind of like separating out object detection from the classification models, but I don't feel too strongly

docs/mkdocs.yml Show resolved Hide resolved
@ejm714
Copy link
Collaborator

ejm714 commented Nov 5, 2021

I kind of like separating out object detection from the classification models, but I don't feel too strongly

Agree this is a nice organization. We might end up further organizing our models directory then into classification vs. denspose vs. object detection. But this is sufficient for now

@ejm714 ejm714 self-requested a review November 5, 2021 19:01
@r-b-g-b
Copy link
Contributor Author

r-b-g-b commented Nov 5, 2021

@ejm714 I did try that, which does fix the ZambaVideoClassificationLightningModule circular dependency, but there are other circular dependencies that show up then :/ I think that points to a pretty strong cycle in the code due to the fact that load_video_frames requires YoloX, YoloX is in models, which through models.__init__ ends up calling lots of model initialization code, including the dataloader, which needs load_video_frames. There might be another way to break the cycle by pulling the dataloader code out instead, but no guarantees that would solve it + I kind of like putting object detection in its own module.

@ejm714 ejm714 merged commit 62797d9 into master Nov 5, 2021
@ejm714 ejm714 deleted the 139-resolve-circular-imports branch November 5, 2021 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resolve circular imports if models are imported in zamba/models/__init__.py
3 participants