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

Create YOLOv5 BaseModel class #8829

Merged
merged 6 commits into from
Aug 2, 2022
Merged

Create YOLOv5 BaseModel class #8829

merged 6 commits into from
Aug 2, 2022

Conversation

glenn-jocher
Copy link
Member

@glenn-jocher glenn-jocher commented Aug 1, 2022

Creates 4 new model classes.

  • BaseModel(nn.module)
  • DetectionModel(BaseModel) <-- equivalent to current Model(nn.module)
  • ClassificationModel(BaseModel)
  • SegmentationModel(BaseModel) <-- available in theory, not created in this PR

Defines DetectionModel = Model for backwards compatibility, where current YOLOv5 models are of type models.yolo.Model

@AyushExel please review

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Refactor classifier script and introduce YOLOv5 ClassificationModel.

📊 Key Changes

  • Created a ClassificationModel class, derived from the new BaseModel class structure.
  • Removed redundant code and cleaned up the importing of modules and methods.
  • smart_hub_load method introduced to handle model loading more gracefully, especially considering the new Torch 1.12 version requirements.
  • Simplified data loader functionality by always using InfiniteDataLoader instead of choosing between it and DataLoader.

🎯 Purpose & Impact

  • 🔨 Refactoring: The changes aim to streamline classifiers by creating a more structured and distinguished classification model, simplifying the codebase.
  • 🆕 Feature Introduction: The new smart_hub_load method is introduced to handle model downloads and loading more efficiently, reducing potential errors and improving compatibility with latest PyTorch versions.
  • 🚀 Performance: Cleaner and more maintainable code often leads to fewer bugs and easier future enhancements.
  • ⏱️ Efficiency: By always using InfiniteDataLoader, the data loading process is potentially more consistent and easier to manage.
  • 💡 User Experience: These changes are set to improve the overall experience for developers using the Ultralytics YOLOv5 classifier, providing a solid and simpler foundation for building classification models.

@glenn-jocher glenn-jocher self-assigned this Aug 1, 2022
@glenn-jocher glenn-jocher changed the title Create BaseModel Create YOLOv5 BaseModel class Aug 1, 2022
@glenn-jocher glenn-jocher changed the base branch from master to classifier August 1, 2022 22:43
@AyushExel
Copy link
Contributor

Looks good! Please merge
Great idea. we should keep the same naming convention for all tasks? Or maybe use yoloDetector, yoloClassifier, yoloPoseEstimator .. etc? I prefer what you've got here.

@glenn-jocher glenn-jocher merged commit e567764 into classifier Aug 2, 2022
@glenn-jocher glenn-jocher deleted the update/BaseModel branch August 2, 2022 11:37
@glenn-jocher
Copy link
Member Author

@AyushExel awesome, its done!

glenn-jocher added a commit that referenced this pull request Aug 17, 2022
* Update

* Logger step fix: Increment step with epochs (#8654)

* enhance

* revert

* allow training from scratch

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update --img argument from train.py 

single line

* fix image size from 640 to 128

* suport custom dataloader and augmentation

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* format

* Update dataloaders.py

* Single line return, single line comment, remove unused argument

* address PR comments

* fix spelling

* don't augment eval set

* use fstring

* update augmentations.py

* new maning convention for transforms

* reverse if statement, inline ops

* reverse if statement, inline ops

* updates

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update dataloaders

* Remove additional if statement

* Remove is_train as redundant

* Cleanup

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Cleanup2

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update classifier.py

* Update augmentations.py

* fix: imshow clip warning

* update

* Revert ToTensorV2 removal

* Update classifier.py

* Update normalize values, revert uint8

* normalize image using cv2

* remove dedundant comment

* Update classifier.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* replace print with logger

* commit steps

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <[email protected]>

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Allow logging models from GenericLogger (#8676)

* enhance

* revert

* allow training from scratch

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update --img argument from train.py 

single line

* fix image size from 640 to 128

* suport custom dataloader and augmentation

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* format

* Update dataloaders.py

* Single line return, single line comment, remove unused argument

* address PR comments

* fix spelling

* don't augment eval set

* use fstring

* update augmentations.py

* new maning convention for transforms

* reverse if statement, inline ops

* reverse if statement, inline ops

* updates

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update dataloaders

* Remove additional if statement

* Remove is_train as redundant

* Cleanup

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Cleanup2

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update classifier.py

* Update augmentations.py

* fix: imshow clip warning

* update

* Revert ToTensorV2 removal

* Update classifier.py

* Update normalize values, revert uint8

* normalize image using cv2

* remove dedundant comment

* Update classifier.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* replace print with logger

* commit steps

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* support final model logging

* update

* update

* update

* update

* remove curses

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update classifier.py

* Update __init__.py

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <[email protected]>

* Update

* Update

* Update

* Update

* Update dataset download

* Update dataset download

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Pass imgsz to classify_transforms()

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Cos scheduler

* Cos scheduler

* Remove unused args

* Update

* Add seed

* Add seed

* Update

* Update

* Add run(), main()

* Merge master

* Merge master

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Create YOLOv5 BaseModel class (#8829)

* Create BaseModel

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix

* Hub load device fix

* Update

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Add experiment

* Merge master

* Attach names

* weight decay = 1e-4

* weight decay = 5e-5

* update smart_optimizer console printout

* fashion-mnist fix

* Merge master

* Update Table

* Update Table

* Remove destroy process group

* add kwargs to forward()

* fuse fix for resnet50

* nc, names fix for resnet50

* nc, names fix for resnet50

* ONNX CPU inference fix

* revert

* cuda

* if augment or visualize

* if augment or visualize

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* New smart_inference_mode()

* Update README

* Refactor into /classify dir

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* reset defaults

* reset defaults

* fix gpu predict

* warmup

* ema half fix

* spacing

* remove data

* remove cache

* remove denormalize

* save run settings

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* verbose false on initial plots

* new save_yaml() function

* Update ci-testing.yml

* Path(data) CI fix

* Separate classification CI

* fix val

* fix val

* fix val

* smartCrossEntropyLoss

* skip validation on hub load

* autodownload with working dir root

* str(data)

* Dataset usage example

* im_show normalize

* im_show normalize

* add imagenet simple names to multibackend

* Add validation speeds

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* 24-space names

* Update bash scripts

* Update permissions

* Add bash script arguments

* remove verbose

* TRT data fix

* names generator fix

* optimize if names

* update usage

* Add local loading

* Verbose=False

* update names printing

* Add Usage examples

* Add Usage examples

* Add Usage examples

* Add Usage examples

* named_children

* reshape_classifier_outputs

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update

* update

* fix CI

* fix incorrect class substitution

* fix incorrect class substitution

* remove denormalize

* ravel fix

* cleanup

* update opt file printing

* update opt file printing

* update defaults

* add opt to checkpoint

* Add warning

* Add comment

* plot half bug fix

* Use NotImplementedError

* fix export shape report

* Fix TRT load

* cleanup CI

* profile comment

* CI fix

* Add cls models

* avoid inplace error

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix usage examples

* Update README

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

Co-authored-by: Ayush Chaurasia <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
ctjanuhowski pushed a commit to ctjanuhowski/yolov5 that referenced this pull request Sep 8, 2022
* Update

* Logger step fix: Increment step with epochs (ultralytics#8654)

* enhance

* revert

* allow training from scratch

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update --img argument from train.py 

single line

* fix image size from 640 to 128

* suport custom dataloader and augmentation

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* format

* Update dataloaders.py

* Single line return, single line comment, remove unused argument

* address PR comments

* fix spelling

* don't augment eval set

* use fstring

* update augmentations.py

* new maning convention for transforms

* reverse if statement, inline ops

* reverse if statement, inline ops

* updates

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update dataloaders

* Remove additional if statement

* Remove is_train as redundant

* Cleanup

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Cleanup2

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update classifier.py

* Update augmentations.py

* fix: imshow clip warning

* update

* Revert ToTensorV2 removal

* Update classifier.py

* Update normalize values, revert uint8

* normalize image using cv2

* remove dedundant comment

* Update classifier.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* replace print with logger

* commit steps

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <[email protected]>

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Allow logging models from GenericLogger (ultralytics#8676)

* enhance

* revert

* allow training from scratch

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update --img argument from train.py 

single line

* fix image size from 640 to 128

* suport custom dataloader and augmentation

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* format

* Update dataloaders.py

* Single line return, single line comment, remove unused argument

* address PR comments

* fix spelling

* don't augment eval set

* use fstring

* update augmentations.py

* new maning convention for transforms

* reverse if statement, inline ops

* reverse if statement, inline ops

* updates

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update dataloaders

* Remove additional if statement

* Remove is_train as redundant

* Cleanup

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Cleanup2

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update classifier.py

* Update augmentations.py

* fix: imshow clip warning

* update

* Revert ToTensorV2 removal

* Update classifier.py

* Update normalize values, revert uint8

* normalize image using cv2

* remove dedundant comment

* Update classifier.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* replace print with logger

* commit steps

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* support final model logging

* update

* update

* update

* update

* remove curses

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update classifier.py

* Update __init__.py

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <[email protected]>

* Update

* Update

* Update

* Update

* Update dataset download

* Update dataset download

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Pass imgsz to classify_transforms()

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Cos scheduler

* Cos scheduler

* Remove unused args

* Update

* Add seed

* Add seed

* Update

* Update

* Add run(), main()

* Merge master

* Merge master

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Create YOLOv5 BaseModel class (ultralytics#8829)

* Create BaseModel

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix

* Hub load device fix

* Update

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Add experiment

* Merge master

* Attach names

* weight decay = 1e-4

* weight decay = 5e-5

* update smart_optimizer console printout

* fashion-mnist fix

* Merge master

* Update Table

* Update Table

* Remove destroy process group

* add kwargs to forward()

* fuse fix for resnet50

* nc, names fix for resnet50

* nc, names fix for resnet50

* ONNX CPU inference fix

* revert

* cuda

* if augment or visualize

* if augment or visualize

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* New smart_inference_mode()

* Update README

* Refactor into /classify dir

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* reset defaults

* reset defaults

* fix gpu predict

* warmup

* ema half fix

* spacing

* remove data

* remove cache

* remove denormalize

* save run settings

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* verbose false on initial plots

* new save_yaml() function

* Update ci-testing.yml

* Path(data) CI fix

* Separate classification CI

* fix val

* fix val

* fix val

* smartCrossEntropyLoss

* skip validation on hub load

* autodownload with working dir root

* str(data)

* Dataset usage example

* im_show normalize

* im_show normalize

* add imagenet simple names to multibackend

* Add validation speeds

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* 24-space names

* Update bash scripts

* Update permissions

* Add bash script arguments

* remove verbose

* TRT data fix

* names generator fix

* optimize if names

* update usage

* Add local loading

* Verbose=False

* update names printing

* Add Usage examples

* Add Usage examples

* Add Usage examples

* Add Usage examples

* named_children

* reshape_classifier_outputs

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update

* update

* fix CI

* fix incorrect class substitution

* fix incorrect class substitution

* remove denormalize

* ravel fix

* cleanup

* update opt file printing

* update opt file printing

* update defaults

* add opt to checkpoint

* Add warning

* Add comment

* plot half bug fix

* Use NotImplementedError

* fix export shape report

* Fix TRT load

* cleanup CI

* profile comment

* CI fix

* Add cls models

* avoid inplace error

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix usage examples

* Update README

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

* Update README

Co-authored-by: Ayush Chaurasia <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

2 participants