Skip to content

[CONCEPT] Introduces ModelMeta class#14706

Draft
Burhan-Q wants to merge 85 commits intomainfrom
meta-kwargs
Draft

[CONCEPT] Introduces ModelMeta class#14706
Burhan-Q wants to merge 85 commits intomainfrom
meta-kwargs

Conversation

@Burhan-Q
Copy link
Contributor

@Burhan-Q Burhan-Q commented Jul 26, 2024

Concept New ModelMeta class

I understand this is a big add, but this was something I know we've discussed and I had a moment of inspiration and ran with it. I don't think it's perfect, but I think it can serve as a starting point or perhaps inspiration.

  • limited to YOLO models.
  • adds type hinting for arguments
  • adds full docstring for Mode methods
  • includes new utils/doc_methods.py for converting MetaModel method arguments into a similar format as cfg/default.yaml (not exactly the same)

Could close #8155

Open Tasks

  • hyperparameter arguments need to be added
  • tests would have to be updated to use keyword arguments (not positional)
  • ensure all tests are passing

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

This PR introduces the new ModelMeta class to the YOLO codebase, enhancing model functionalities such as export, predict, train, and track.

📊 Key Changes

  • New ModelMeta Class: Introduced to encapsulate meta-information and functionalities for YOLO models.
  • Methods Implemented:
    • benchmark: Assesses model performance across various export formats.
    • export: Exports models to different formats.
    • predict: Performs predictions on various image sources.
    • train: Provides an extensive training pipeline.
    • track: Adds object tracking capabilities.
    • val: Validates model performance.
  • Refactor YOLO Class: Now inherits from ModelMeta instead of Model.
  • Auto-generate Method Documentation: Code to inspect methods, their arguments, and return types, and save this metadata as YAML.

🎯 Purpose & Impact

  • Enhanced Flexibility: By separating metadata from the model logic, the ModelMeta class allows more modular and reusable code.
  • Improved Export Options: Users can now easily export models in various formats, ensuring compatibility with different deployment environments.
  • Comprehensive Training & Inference: The new methods provide a robust pipeline for training, validating, and making predictions, enhancing usability.
  • Documentation: Auto-generating method documentation ensures up-to-date, accurate, and accessible information for developers and users.

These changes aim to make the YOLO model more versatile and user-friendly, benefiting both developers and end-users in deploying and experimenting with object detection tasks.

🔧✨

@Burhan-Q Burhan-Q added the enhancement New feature or request label Jul 26, 2024
@UltralyticsAssistant UltralyticsAssistant added the exports Model exports (ONNX, TensorRT, TFLite, etc.) label Jul 26, 2024
@Burhan-Q
Copy link
Contributor Author

Here's a sample from VS Code of the type hinting and docstring preview

image

@Burhan-Q
Copy link
Contributor Author

All the tests failing 😆 I know this will go no where without being able to pass the CI tests, but like I mentioned, it's more of a conceptual starting point.

Going to add some tasks to the original PR comment that pertain to some of the CI test failures.

@glenn-jocher
Copy link
Member

glenn-jocher commented Jul 27, 2024

@Burhan-Q would it be possible to just expand the arguments in model and read the defaults directly from the YAML, i.e. something like:

args = read from default.yaml here

def train(imgsz: int = args["imgsz"],
...

EDIT: No I guess not:

Screenshot 2024-07-27 at 14 34 19

@Burhan-Q Burhan-Q removed the exports Model exports (ONNX, TensorRT, TFLite, etc.) label Jul 29, 2024
@Burhan-Q
Copy link
Contributor Author

@glenn-jocher as far as I'm aware, the type hinting is all done statically, so we can't use the YAML values. This was something I thought about and tried, but wasn't able to and couldn't find a way make work.

From what I understand from reading/research on this topic, is that in an ideal world, the code would be sufficient to be "self-documenting." That would mean that artifacts (like the default.yaml) shouldn't be necessary. I'm not saying that it should be removed, only saying that my understanding is that it shouldn't be relied on as it's "external" to the source code.
This is the same idea of not having information replicated, but takes it one step further by ensuring it's the source code that is "the single source of truth" and removes reliance on any external artifact. We can create artifacts like default.yaml and the documentation from the source code, but my understanding is that generally you don't want to try to generate code/logic from these artifacts (at least not partially).

If we use something like this concept, the ModelMeta class becomes the definitive source of truth as far as what's permitted into the high-level methods of the model. These get passed down to the other model inherited classes as needed. It would also mean that it would be the source to generate whatever artifacts or documentation needed (and I'm not claiming that what I have here is perfect or even close to the "correct" way to achieve this).

My thinking is that (for this implementation at least), we could generate the new default.yaml file from the ModelMeta class, but still make things backwards compatible with the old format. This would also mean that the argument checking done under the cfg/__init__.py would have to be modified, and I haven't thought about how (or if) it's feasible to make this backwards compatible as well. Really, moving all the arguments to a class like this would mean that all the "checks" for correct arguments could be offloaded to the python interpreter (which might make things quicker), but off the cuff, if we generate a default.yaml from the ModelMeta class, then the same checks could be run with an accounting for the change in structure.

@Burhan-Q Burhan-Q marked this pull request as ready for review December 1, 2024 20:47
@Burhan-Q Burhan-Q marked this pull request as draft December 1, 2024 20:47
@harshraaj harshraaj mentioned this pull request Jan 22, 2025
2 tasks
@pooya-github
Copy link

pooya-github commented Feb 19, 2025

Hi @Burhan-Q !
Can I contribute in this task? Where can I start?

@github-actions
Copy link

👋 Hello there! We wanted to let you know that we've decided to close this pull request due to inactivity. We appreciate the effort you put into contributing to our project, but unfortunately, not all contributions are suitable or aligned with our product roadmap.

We hope you understand our decision, and please don't let it discourage you from contributing to open source projects in the future. We value all of our community members and their contributions, and we encourage you to keep exploring new projects and ways to get involved.

For additional resources and information, please see the links below:

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale Stale and schedule for closing soon label Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Stale Stale and schedule for closing soon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add AutoModel class

5 participants