diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml index 371439b..632cec3 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.yml +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -80,6 +80,6 @@ body: label: Are you willing to submit a PR? description: > (Optional) We encourage you to submit a [Pull Request](https://github.com/ultralytics/ultralytics/pulls) (PR) to help improve YOLOv8 for everyone, especially if you have a good understanding of how to implement a fix or feature. - See the YOLOv8 [Contributing Guide](https://github.com/ultralytics/ultralytics/blob/main/CONTRIBUTING.md) to get started. + See the YOLOv8 [Contributing Guide](https://docs.ultralytics.com/help/contributing) to get started. options: - label: Yes I'd like to help by submitting a PR! diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml index 627ffb1..39158a0 100644 --- a/.github/ISSUE_TEMPLATE/feature-request.yml +++ b/.github/ISSUE_TEMPLATE/feature-request.yml @@ -45,6 +45,6 @@ body: label: Are you willing to submit a PR? description: > (Optional) We encourage you to submit a [Pull Request](https://github.com/ultralytics/ultralytics/pulls) (PR) to help improve YOLOv8 for everyone, especially if you have a good understanding of how to implement a fix or feature. - See the YOLOv8 [Contributing Guide](https://github.com/ultralytics/ultralytics/blob/main/CONTRIBUTING.md) to get started. + See the YOLOv8 [Contributing Guide](https://docs.ultralytics.com/help/contributing) to get started. options: - label: Yes I'd like to help by submitting a PR! diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml index 70a9163..bb9c26a 100644 --- a/.github/workflows/cla.yml +++ b/.github/workflows/cla.yml @@ -25,7 +25,7 @@ jobs: PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} with: path-to-signatures: 'signatures/version1/cla.json' - path-to-document: 'https://github.com/ultralytics/assets/blob/main/documents/CLA.md' # CLA document + path-to-document: 'https://docs.ultralytics.com/help/CLA' # CLA document # branch should not be protected branch: 'main' allowlist: dependabot[bot],github-actions,[pre-commit*,pre-commit*,bot* diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml index 1f4d6a2..37d08f3 100644 --- a/.github/workflows/greetings.yml +++ b/.github/workflows/greetings.yml @@ -23,7 +23,7 @@ jobs: - ✅ Update YOLOv8 [Docs](https://docs.ultralytics.com) for any new or updated features. - ✅ Reduce changes to the absolute **minimum** required for your bug fix or feature addition. _"It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is."_ — Bruce Lee - See our [Contributing Guide](https://github.com/ultralytics/ultralytics/blob/main/CONTRIBUTING.md) for details and let us know if you have any questions! + See our [Contributing Guide](https://docs.ultralytics.com/help/contributing) for details and let us know if you have any questions! issue-message: | 👋 Hello @${{ github.actor }}, thank you for your interest in YOLOv8 🚀! We recommend a visit to the [YOLOv8 Docs](https://docs.ultralytics.com) for new users where you can find many [Python](https://docs.ultralytics.com/usage/python/) and [CLI](https://docs.ultralytics.com/usage/cli/) usage examples and where many of the most common questions may already be answered. diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e0edf44..0612585 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -47,6 +47,7 @@ jobs: d = [a - b for a, b in zip(v_local, v_pypi)] # diff increment = (d[0] == d[1] == 0) and d[2] == 1 # only publish if patch version increments by 1 os.system(f'echo "increment={increment}" >> $GITHUB_OUTPUT') + os.system(f'echo "version={ultralytics.__version__}" >> $GITHUB_OUTPUT') if increment: print('Local version is higher than PyPI version. Publishing new version to PyPI ✅.') id: check_pypi @@ -64,6 +65,44 @@ jobs: env: PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} run: | - mkdocs gh-deploy --force || true - # git checkout gh-pages - # git push https://$PERSONAL_ACCESS_TOKEN@github.com/ultralytics/docs gh-pages --force + mkdocs build + git config --global user.name "Glenn Jocher" + git config --global user.email "glenn.jocher@ultralytics.com" + git clone https://github.com/ultralytics/docs.git docs-repo + cd docs-repo + git checkout gh-pages || git checkout -b gh-pages + rm -rf * + cp -R ../site/* . + git add . + git commit -m "Update Docs for 'ultralytics ${{ steps.check_pypi.outputs.version }}'" + git push https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/ultralytics/docs.git gh-pages + - name: Extract PR Details + run: | + if [ "${{ github.event_name }}" = "pull_request" ]; then + PR_JSON=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}) + PR_NUMBER=${{ github.event.pull_request.number }} + PR_TITLE=$(echo $PR_JSON | jq -r '.title') + else + COMMIT_SHA=${{ github.event.after }} + PR_JSON=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/search/issues?q=repo:${{ github.repository }}+is:pr+is:merged+sha:$COMMIT_SHA") + PR_NUMBER=$(echo $PR_JSON | jq -r '.items[0].number') + PR_TITLE=$(echo $PR_JSON | jq -r '.items[0].title') + fi + echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV + echo "PR_TITLE=$PR_TITLE" >> $GITHUB_ENV + - name: Notify on Slack (Success) + if: success() && github.event_name == 'push' && steps.check_pypi.outputs.increment == 'True' + uses: slackapi/slack-github-action@v1.23.0 + with: + payload: | + {"text": " GitHub Actions success for ${{ github.workflow }} ✅\n\n\n*Repository:* https://github.com/${{ github.repository }}\n*Action:* https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\n*Author:* ${{ github.actor }}\n*Event:* NEW 'ultralytics ${{ steps.check_pypi.outputs.version }}' pip package published 😃\n*Job Status:* ${{ job.status }}\n*Pull Request:* ${{ env.PR_TITLE }}\n"} + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_YOLO }} + - name: Notify on Slack (Failure) + if: failure() + uses: slackapi/slack-github-action@v1.23.0 + with: + payload: | + {"text": " GitHub Actions error for ${{ github.workflow }} ❌\n\n\n*Repository:* https://github.com/${{ github.repository }}\n*Action:* https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\n*Author:* ${{ github.actor }}\n*Event:* ${{ github.event_name }}\n*Job Status:* ${{ job.status }}\n*Pull Request:* ${{ env.PR_TITLE }}\n"} + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_YOLO }} diff --git a/README.md b/README.md index 2bfd612..c376b7b 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ [Ultralytics](https://ultralytics.com) [YOLOv8](https://github.com/ultralytics/ultralytics) is a cutting-edge, state-of-the-art (SOTA) model that builds upon the success of previous YOLO versions and introduces new features and improvements to further boost performance and flexibility. YOLOv8 is designed to be fast, accurate, and easy to use, making it an excellent choice for a wide range of object detection and tracking, instance segmentation, image classification and pose estimation tasks. -We hope that the resources here will help you get the most out of YOLOv8. Please browse the YOLOv8 Docs for details, raise an issue on GitHub for support, and join our Discord community for questions and discussions! +We hope that the resources here will help you get the most out of YOLOv8. Please browse the YOLOv8 Docs for details, raise an issue on GitHub for support, and join our Discord community for questions and discussions! To request an Enterprise License please complete the form at [Ultralytics Licensing](https://ultralytics.com/license). @@ -219,7 +219,7 @@ Experience seamless AI with [Ultralytics HUB](https://bit.ly/ultralytics_hub) ##
Contribute
-We love your input! YOLOv5 and YOLOv8 would not be possible without help from our community. Please see our [Contributing Guide](CONTRIBUTING.md) to get started, and fill out our [Survey](https://ultralytics.com/survey?utm_source=github&utm_medium=social&utm_campaign=Survey) to send us feedback on your experience. Thank you 🙏 to all our contributors! +We love your input! YOLOv5 and YOLOv8 would not be possible without help from our community. Please see our [Contributing Guide](https://docs.ultralytics.com/help/contributing) to get started, and fill out our [Survey](https://ultralytics.com/survey?utm_source=github&utm_medium=social&utm_campaign=Survey) to send us feedback on your experience. Thank you 🙏 to all our contributors! diff --git a/README.zh-CN.md b/README.zh-CN.md index fec7b23..8b85887 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -20,7 +20,7 @@ [Ultralytics](https://ultralytics.com) [YOLOv8](https://github.com/ultralytics/ultralytics) 是一款前沿、最先进(SOTA)的模型,基于先前 YOLO 版本的成功,引入了新功能和改进,进一步提升性能和灵活性。YOLOv8 设计快速、准确且易于使用,使其成为各种物体检测与跟踪、实例分割、图像分类和姿态估计任务的绝佳选择。 -我们希望这里的资源能帮助您充分利用 YOLOv8。请浏览 YOLOv8 文档 了解详细信息,在 GitHub 上提交问题以获得支持,并加入我们的 Discord 社区进行问题和讨论! +我们希望这里的资源能帮助您充分利用 YOLOv8。请浏览 YOLOv8 文档 了解详细信息,在 GitHub 上提交问题以获得支持,并加入我们的 Discord 社区进行问题和讨论! 如需申请企业许可,请在 [Ultralytics Licensing](https://ultralytics.com/license) 处填写表格 @@ -218,7 +218,7 @@ success = model.export(format="onnx") # 将模型导出为 ONNX 格式 ##
贡献
-我们喜欢您的参与!没有社区的帮助,YOLOv5 和 YOLOv8 将无法实现。请参阅我们的[贡献指南](CONTRIBUTING.md)以开始使用,并填写我们的[调查问卷](https://ultralytics.com/survey?utm_source=github&utm_medium=social&utm_campaign=Survey)向我们提供您的使用体验反馈。感谢所有贡献者的支持!🙏 +我们喜欢您的参与!没有社区的帮助,YOLOv5 和 YOLOv8 将无法实现。请参阅我们的[贡献指南](https://docs.ultralytics.com/help/contributing)以开始使用,并填写我们的[调查问卷](https://ultralytics.com/survey?utm_source=github&utm_medium=social&utm_campaign=Survey)向我们提供您的使用体验反馈。感谢所有贡献者的支持!🙏 diff --git a/docs/SECURITY.md b/docs/SECURITY.md index c00e145..0b2dd7b 100644 --- a/docs/SECURITY.md +++ b/docs/SECURITY.md @@ -1,3 +1,5 @@ +# Security Policy + At [Ultralytics](https://ultralytics.com), the security of our users' data and systems is of utmost importance. To ensure the safety and security of our [open-source projects](https://github.com/ultralytics), we have implemented several measures to detect and prevent security vulnerabilities. diff --git a/docs/help/CLA.md b/docs/help/CLA.md new file mode 100644 index 0000000..c8dd717 --- /dev/null +++ b/docs/help/CLA.md @@ -0,0 +1,65 @@ +# Ultralytics Individual Contributor License Agreement + +Thank you for your interest in contributing to open source software projects (“Projects”) made available by Ultralytics +SE or its affiliates (“Ultralytics”). This Individual Contributor License Agreement (“Agreement”) sets out the terms +governing any source code, object code, bug fixes, configuration changes, tools, specifications, documentation, data, +materials, feedback, information or other works of authorship that you submit or have submitted, in any form and in any +manner, to Ultralytics in respect of any of the Projects (collectively “Contributions”). If you have any questions +respecting this Agreement, please contact hello@ultralytics.com. + +You agree that the following terms apply to all of your past, present and future Contributions. Except for the licenses +granted in this Agreement, you retain all of your right, title and interest in and to your Contributions. + +**Copyright License.** You hereby grant, and agree to grant, to Ultralytics a non-exclusive, perpetual, irrevocable, +worldwide, fully-paid, royalty-free, transferable copyright license to reproduce, prepare derivative works of, publicly +display, publicly perform, and distribute your Contributions and such derivative works, with the right to sublicense the +foregoing rights through multiple tiers of sublicensees. + +**Patent License.** You hereby grant, and agree to grant, to Ultralytics a non-exclusive, perpetual, irrevocable, +worldwide, fully-paid, royalty-free, transferable patent license to make, have made, use, offer to sell, sell, +import, and otherwise transfer your Contributions, where such license applies only to those patent claims +licensable by you that are necessarily infringed by your Contributions alone or by combination of your +Contributions with the Project to which such Contributions were submitted, with the right to sublicense the +foregoing rights through multiple tiers of sublicensees. + +**Moral Rights.** To the fullest extent permitted under applicable law, you hereby waive, and agree not to +assert, all of your “moral rights” in or relating to your Contributions for the benefit of Ultralytics, its assigns, and +their respective direct and indirect sublicensees. + +**Third Party Content/Rights.** If your Contribution includes or is based on any source code, object code, bug +fixes, configuration changes, tools, specifications, documentation, data, materials, feedback, information or +other works of authorship that were not authored by you (“Third Party Content”) or if you are aware of any +third party intellectual property or proprietary rights associated with your Contribution (“Third Party Rights”), +then you agree to include with the submission of your Contribution full details respecting such Third Party +Content and Third Party Rights, including, without limitation, identification of which aspects of your +Contribution contain Third Party Content or are associated with Third Party Rights, the owner/author of the +Third Party Content and Third Party Rights, where you obtained the Third Party Content, and any applicable +third party license terms or restrictions respecting the Third Party Content and Third Party Rights. For greater +certainty, the foregoing obligations respecting the identification of Third Party Content and Third Party Rights +do not apply to any portion of a Project that is incorporated into your Contribution to that same Project. + +**Representations.** You represent that, other than the Third Party Content and Third Party Rights identified by +you in accordance with this Agreement, you are the sole author of your Contributions and are legally entitled +to grant the foregoing licenses and waivers in respect of your Contributions. If your Contributions were +created in the course of your employment with your past or present employer(s), you represent that such +employer(s) has authorized you to make your Contributions on behalf of such employer(s) or such employer +(s) has waived all of their right, title or interest in or to your Contributions. + +**Disclaimer.** To the fullest extent permitted under applicable law, your Contributions are provided on an "asis" +basis, without any warranties or conditions, express or implied, including, without limitation, any implied +warranties or conditions of non-infringement, merchantability or fitness for a particular purpose. You are not +required to provide support for your Contributions, except to the extent you desire to provide support. + +**No Obligation.** You acknowledge that Ultralytics is under no obligation to use or incorporate your Contributions +into any of the Projects. The decision to use or incorporate your Contributions into any of the Projects will be +made at the sole discretion of Ultralytics or its authorized delegates .. + +**Disputes.** This Agreement shall be governed by and construed in accordance with the laws of the State of +New York, United States of America, without giving effect to its principles or rules regarding conflicts of laws, +other than such principles directing application of New York law. The parties hereby submit to venue in, and +jurisdiction of the courts located in New York, New York for purposes relating to this Agreement. In the event +that any of the provisions of this Agreement shall be held by a court or other tribunal of competent jurisdiction +to be unenforceable, the remaining portions hereof shall remain in full force and effect. + +**Assignment.** You agree that Ultralytics may assign this Agreement, and all of its rights, obligations and licenses +hereunder. diff --git a/docs/help/FAQ.md b/docs/help/FAQ.md new file mode 100644 index 0000000..e2aff1f --- /dev/null +++ b/docs/help/FAQ.md @@ -0,0 +1,33 @@ +# Ultralytics YOLO Frequently Asked Questions (FAQ) + +This FAQ section addresses some common questions and issues users might encounter while working with Ultralytics YOLO repositories. + +## 1. What are the hardware requirements for running Ultralytics YOLO? + +Ultralytics YOLO can be run on a variety of hardware configurations, including CPUs, GPUs, and even some edge devices. However, for optimal performance and faster training and inference, we recommend using a GPU with a minimum of 8GB of memory. NVIDIA GPUs with CUDA support are ideal for this purpose. + +## 2. How do I fine-tune a pre-trained YOLO model on my custom dataset? + +To fine-tune a pre-trained YOLO model on your custom dataset, you'll need to create a dataset configuration file (YAML) that defines the dataset's properties, such as the path to the images, the number of classes, and class names. Next, you'll need to modify the model configuration file to match the number of classes in your dataset. Finally, use the `train.py` script to start the training process with your custom dataset and the pre-trained model. You can find a detailed guide on fine-tuning YOLO in the Ultralytics documentation. + +## 3. How do I convert a YOLO model to ONNX or TensorFlow format? + +Ultralytics provides built-in support for converting YOLO models to ONNX format. You can use the `export.py` script to convert a saved model to ONNX format. If you need to convert the model to TensorFlow format, you can use the ONNX model as an intermediary and then use the ONNX-TensorFlow converter to convert the ONNX model to TensorFlow format. + +## 4. Can I use Ultralytics YOLO for real-time object detection? + +Yes, Ultralytics YOLO is designed to be efficient and fast, making it suitable for real-time object detection tasks. The actual performance will depend on your hardware configuration and the complexity of the model. Using a GPU and optimizing the model for your specific use case can help achieve real-time performance. + +## 5. How can I improve the accuracy of my YOLO model? + +Improving the accuracy of a YOLO model may involve several strategies, such as: + +- Fine-tuning the model on more annotated data +- Data augmentation to increase the variety of training samples +- Using a larger or more complex model architecture +- Adjusting the learning rate, batch size, and other hyperparameters +- Using techniques like transfer learning or knowledge distillation + +Remember that there's often a trade-off between accuracy and inference speed, so finding the right balance is crucial for your specific application. + +If you have any more questions or need assistance, don't hesitate to consult the Ultralytics documentation or reach out to the community through GitHub Issues or the official discussion forum. \ No newline at end of file diff --git a/docs/help/code_of_conduct.md b/docs/help/code_of_conduct.md new file mode 100644 index 0000000..b88a5ad --- /dev/null +++ b/docs/help/code_of_conduct.md @@ -0,0 +1,128 @@ +# Ultralytics Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +- Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +- The use of sexualized language or imagery, and sexual attention or + advances of any kind +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or email + address, without their explicit permission +- Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +hello@ultralytics.com. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. + +[homepage]: https://www.contributor-covenant.org diff --git a/docs/help/contributing.md b/docs/help/contributing.md new file mode 100644 index 0000000..cf1abd1 --- /dev/null +++ b/docs/help/contributing.md @@ -0,0 +1,69 @@ +# Contributing to Ultralytics Open-Source YOLO Repositories + +First of all, thank you for your interest in contributing to Ultralytics open-source YOLO repositories! Your contributions will help improve the project and benefit the community. This document provides guidelines and best practices for contributing to Ultralytics YOLO repositories. + +## Table of Contents + +- [Code of Conduct](#code-of-conduct) +- [Pull Requests](#pull-requests) + - [CLA Signing](#cla-signing) + - [Google-Style Docstrings](#google-style-docstrings) + - [GitHub Actions CI Tests](#github-actions-ci-tests) +- [Bug Reports](#bug-reports) + - [Minimum Reproducible Example](#minimum-reproducible-example) +- [License and Copyright](#license-and-copyright) + +## Code of Conduct + +All contributors are expected to adhere to the [Code of Conduct](code_of_conduct.md) to ensure a welcoming and inclusive environment for everyone. + +## Pull Requests + +We welcome contributions in the form of pull requests. To make the review process smoother, please follow these guidelines: + +1. **Fork the repository**: Fork the Ultralytics YOLO repository to your own GitHub account. + +2. **Create a branch**: Create a new branch in your forked repository with a descriptive name for your changes. + +3. **Make your changes**: Make the changes you want to contribute. Ensure that your changes follow the coding style of the project and do not introduce new errors or warnings. + +4. **Test your changes**: Test your changes locally to ensure that they work as expected and do not introduce new issues. + +5. **Commit your changes**: Commit your changes with a descriptive commit message. Make sure to include any relevant issue numbers in your commit message. + +6. **Create a pull request**: Create a pull request from your forked repository to the main Ultralytics YOLO repository. In the pull request description, provide a clear explanation of your changes and how they improve the project. + +### CLA Signing + +Before we can accept your pull request, you need to sign a [Contributor License Agreement (CLA)](CLA.md). This is a legal document stating that you agree to the terms of contributing to the Ultralytics YOLO repositories. The CLA ensures that your contributions are properly licensed and that the project can continue to be distributed under the AGPL-3.0 license. + +To sign the CLA, follow the instructions provided by the CLA bot after you submit your PR. + +### Google-Style Docstrings + +When adding new functions or classes, please include a [Google-style docstring](https://google.github.io/styleguide/pyguide.html) to provide clear and concise documentation for other developers. This will help ensure that your contributions are easy to understand and maintain. + +Example Google-style docstring: + +```python +def example_function(arg1: int, arg2: str) -> bool: + """Example function that demonstrates Google-style docstrings. + + Args: + arg1 (int): The first argument. + arg2 (str): The second argument. + + Returns: + bool: True if successful, False otherwise. + + Raises: + ValueError: If `arg1` is negative or `arg2` is empty. + """ + if arg1 < 0 or not arg2: + raise ValueError("Invalid input values") + return True +``` + +### GitHub Actions CI Tests + +Before your pull request can be merged, all GitHub Actions Continuous Integration (CI) tests must pass. These tests include linting, unit tests, and other checks to ensure that your changes meet the quality standards of the project. Make sure to review the output of the GitHub Actions and fix any issues \ No newline at end of file diff --git a/docs/help/index.md b/docs/help/index.md new file mode 100644 index 0000000..c859d07 --- /dev/null +++ b/docs/help/index.md @@ -0,0 +1,10 @@ +Welcome to the Ultralytics Help page! We are committed to providing you with comprehensive resources to make your experience with Ultralytics YOLO repositories as smooth and enjoyable as possible. On this page, you'll find essential links to guides and documents that will help you navigate through common tasks and address any questions you might have while using our repositories. + +- [Frequently Asked Questions (FAQ)](FAQ.md): Find answers to common questions and issues faced by users and contributors of Ultralytics YOLO repositories. +- [Contributing Guide](contributing.md): Learn the best practices for submitting pull requests, reporting bugs, and contributing to the development of our repositories. +- [Contributor License Agreement (CLA)](CLA.md): Familiarize yourself with our CLA to understand the terms and conditions for contributing to Ultralytics projects. +- [Minimum Reproducible Example (MRE) Guide](minimum_reproducible_example.md): Understand how to create an MRE when submitting bug reports to ensure that our team can quickly and efficiently address the issue. +- [Code of Conduct](code_of_conduct.md): Learn about our community guidelines and expectations to ensure a welcoming and inclusive environment for all participants. +- [Security Policy](../SECURITY.md): Understand our security practices and how to report security vulnerabilities responsibly. + +We highly recommend going through these guides to make the most of your collaboration with the Ultralytics community. Our goal is to maintain a welcoming and supportive environment for all users and contributors. If you need further assistance, don't hesitate to reach out to us through GitHub Issues or the official discussion forum. Happy coding! \ No newline at end of file diff --git a/docs/help/minimum_reproducible_example.md b/docs/help/minimum_reproducible_example.md new file mode 100644 index 0000000..813194c --- /dev/null +++ b/docs/help/minimum_reproducible_example.md @@ -0,0 +1,72 @@ +# Creating a Minimum Reproducible Example for Bug Reports in Ultralytics YOLO Repositories + +When submitting a bug report for Ultralytics YOLO repositories, it's essential to provide a [minimum reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) (MRE). An MRE is a small, self-contained piece of code that demonstrates the problem you're experiencing. Providing an MRE helps maintainers and contributors understand the issue and work on a fix more efficiently. This guide explains how to create an MRE when submitting bug reports to Ultralytics YOLO repositories. + +## 1. Isolate the Problem + +The first step in creating an MRE is to isolate the problem. This means removing any unnecessary code or dependencies that are not directly related to the issue. Focus on the specific part of the code that is causing the problem and remove any irrelevant code. + +## 2. Use Public Models and Datasets + +When creating an MRE, use publicly available models and datasets to reproduce the issue. For example, use the 'yolov8n.pt' model and the 'coco8.yaml' dataset. This ensures that the maintainers and contributors can easily run your example and investigate the problem without needing access to proprietary data or custom models. + +## 3. Include All Necessary Dependencies + +Make sure to include all the necessary dependencies in your MRE. If your code relies on external libraries, specify the required packages and their versions. Ideally, provide a `requirements.txt` file or list the dependencies in your bug report. + +## 4. Write a Clear Description of the Issue + +Provide a clear and concise description of the issue you're experiencing. Explain the expected behavior and the actual behavior you're encountering. If applicable, include any relevant error messages or logs. + +## 5. Format Your Code Properly + +When submitting an MRE, format your code properly using code blocks in the issue description. This makes it easier for others to read and understand your code. In GitHub, you can create a code block by wrapping your code with triple backticks (\```) and specifying the language: + +
+```python
+# Your Python code goes here
+```
+
+ +## 6. Test Your MRE + +Before submitting your MRE, test it to ensure that it accurately reproduces the issue. Make sure that others can run your example without any issues or modifications. + +## Example of an MRE + +Here's an example of an MRE for a hypothetical bug report: + +**Bug description:** + +When running the `detect.py` script on the sample image from the 'coco8.yaml' dataset, I get an error related to the dimensions of the input tensor. + +**MRE:** + +```python +import torch +from ultralytics import YOLO + +# Load the model +model = YOLO("yolov8n.pt") + +# Load a 0-channel image +image = torch.rand(1, 0, 640, 640) + +# Run the model +results = model(image) +``` + +**Error message:** + +``` +RuntimeError: Expected input[1, 0, 640, 640] to have 3 channels, but got 0 channels instead +``` + +**Dependencies:** + +- torch==2.0.0 +- ultralytics==8.0.90 + +In this example, the MRE demonstrates the issue with a minimal amount of code, uses a public model ('yolov8n.pt'), includes all necessary dependencies, and provides a clear description of the problem along with the error message. + +By following these guidelines, you'll help the maintainers and contributors of Ultralytics YOLO repositories to understand and resolve your issue more efficiently. \ No newline at end of file diff --git a/docs/models/index.md b/docs/models/index.md new file mode 100644 index 0000000..8a2e3e3 --- /dev/null +++ b/docs/models/index.md @@ -0,0 +1,155 @@ +Ultralytics supports many models and architectures with more to come in the future. What to add your model architecture? [Here's](../help/contributing.md) how you can contribute + + +## YOLO +Model *.yaml files may be used directly in the Command Line Interface (CLI) with a yolo command: + +```bash +yolo task=detect mode=train model=yolov8n.yaml data=coco128.yaml epochs=100 +``` + +They may also be used directly in a Python environment, and accepts the same arguments as in the CLI example above: + +```python +from ultralytics import YOLO + +model = YOLO("model.yaml") # build a YOLOv8n model from scratch +# YOLO("model.pt") use pre-trained model if available +model.info() # display model information +model.train(data="coco128.yaml", epochs=100) # train the model +``` + +## YOLOv8 + +### About + + +### Supported Tasks + +| Model Type | Pre-trained Weights | Task | +|-------------|------------------------------------------------------------------------------------------------------------------|-----------------------| +| YOLOv8 | `yolov8n.pt`, `yolov8s.pt`, `yolov8m.pt`, `yolov8l.pt`, `yolov8x.pt` | Detection | +| YOLOv8-seg | `yolov8n-seg.pt`, `yolov8s-seg.pt`, `yolov8m-seg.pt`, `yolov8l-seg.pt`, `yolov8x-seg.pt` | Instance Segmentation | +| YOLOv8-pose | `yolov8n-pose.pt`, `yolov8s-pose.pt`, `yolov8m-pose.pt`, `yolov8l-pose.pt`, `yolov8x-pose.pt` ,`yolov8x-pose-p6` | Pose/Keypoints | +| YOLOv8-cls | `yolov8n-cls.pt`, `yolov8s-cls.pt`, `yolov8m-cls.pt`, `yolov8l-cls.pt`, `yolov8x-cls.pt` | Classification | + +### Supported Modes +| Mode | Supported | +|------------|--------------------| +| Inference | :heavy_check_mark: | +| Validation | :heavy_check_mark: | +| Training | :heavy_check_mark: | + +??? Performance + + === "Detection" + + | Model | size
(pixels) | mAPval
50-95 | Speed
CPU ONNX
(ms) | Speed
A100 TensorRT
(ms) | params
(M) | FLOPs
(B) | + | ------------------------------------------------------------------------------------ | --------------------- | -------------------- | ------------------------------ | ----------------------------------- | ------------------ | ----------------- | + | [YOLOv8n](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt) | 640 | 37.3 | 80.4 | 0.99 | 3.2 | 8.7 | + | [YOLOv8s](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8s.pt) | 640 | 44.9 | 128.4 | 1.20 | 11.2 | 28.6 | + | [YOLOv8m](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8m.pt) | 640 | 50.2 | 234.7 | 1.83 | 25.9 | 78.9 | + | [YOLOv8l](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8l.pt) | 640 | 52.9 | 375.2 | 2.39 | 43.7 | 165.2 | + | [YOLOv8x](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8x.pt) | 640 | 53.9 | 479.1 | 3.53 | 68.2 | 257.8 | + + === "Segmentation" + + | Model | size
(pixels) | mAPbox
50-95 | mAPmask
50-95 | Speed
CPU ONNX
(ms) | Speed
A100 TensorRT
(ms) | params
(M) | FLOPs
(B) | + | -------------------------------------------------------------------------------------------- | --------------------- | -------------------- | --------------------- | ------------------------------ | ----------------------------------- | ------------------ | ----------------- | + | [YOLOv8n-seg](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n-seg.pt) | 640 | 36.7 | 30.5 | 96.1 | 1.21 | 3.4 | 12.6 | + | [YOLOv8s-seg](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8s-seg.pt) | 640 | 44.6 | 36.8 | 155.7 | 1.47 | 11.8 | 42.6 | + | [YOLOv8m-seg](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8m-seg.pt) | 640 | 49.9 | 40.8 | 317.0 | 2.18 | 27.3 | 110.2 | + | [YOLOv8l-seg](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8l-seg.pt) | 640 | 52.3 | 42.6 | 572.4 | 2.79 | 46.0 | 220.5 | + | [YOLOv8x-seg](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8x-seg.pt) | 640 | 53.4 | 43.4 | 712.1 | 4.02 | 71.8 | 344.1 | + + === "Classification" + + | Model | size
(pixels) | acc
top1 | acc
top5 | Speed
CPU ONNX
(ms) | Speed
A100 TensorRT
(ms) | params
(M) | FLOPs
(B) at 640 | + | -------------------------------------------------------------------------------------------- | --------------------- | ---------------- | ---------------- | ------------------------------ | ----------------------------------- | ------------------ | ------------------------ | + | [YOLOv8n-cls](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n-cls.pt) | 224 | 66.6 | 87.0 | 12.9 | 0.31 | 2.7 | 4.3 | + | [YOLOv8s-cls](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8s-cls.pt) | 224 | 72.3 | 91.1 | 23.4 | 0.35 | 6.4 | 13.5 | + | [YOLOv8m-cls](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8m-cls.pt) | 224 | 76.4 | 93.2 | 85.4 | 0.62 | 17.0 | 42.7 | + | [YOLOv8l-cls](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8l-cls.pt) | 224 | 78.0 | 94.1 | 163.0 | 0.87 | 37.5 | 99.7 | + | [YOLOv8x-cls](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8x-cls.pt) | 224 | 78.4 | 94.3 | 232.0 | 1.01 | 57.4 | 154.8 | + + === "Pose" + + | Model | size
(pixels) | mAPpose
50-95 | mAPpose
50 | Speed
CPU ONNX
(ms) | Speed
A100 TensorRT
(ms) | params
(M) | FLOPs
(B) | + | ---------------------------------------------------------------------------------------------------- | --------------------- | --------------------- | ------------------ | ------------------------------ | ----------------------------------- | ------------------ | ----------------- | + | [YOLOv8n-pose](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n-pose.pt) | 640 | 50.4 | 80.1 | 131.8 | 1.18 | 3.3 | 9.2 | + | [YOLOv8s-pose](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8s-pose.pt) | 640 | 60.0 | 86.2 | 233.2 | 1.42 | 11.6 | 30.2 | + | [YOLOv8m-pose](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8m-pose.pt) | 640 | 65.0 | 88.8 | 456.3 | 2.00 | 26.4 | 81.0 | + | [YOLOv8l-pose](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8l-pose.pt) | 640 | 67.6 | 90.0 | 784.5 | 2.59 | 44.4 | 168.6 | + | [YOLOv8x-pose](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8x-pose.pt) | 640 | 69.2 | 90.2 | 1607.1 | 3.73 | 69.4 | 263.2 | + | [YOLOv8x-pose-p6](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8x-pose-p6.pt) | 1280 | 71.6 | 91.2 | 4088.7 | 10.04 | 99.1 | 1066.4 | + + +## YOLOv5u + +### About +Anchor-free YOLOv5 models with improved accuracy-speed tradeoff. + +### Supported Tasks + +| Model Type | Pre-trained Weights | Task | +|------------|-----------------------------------------------------------------------------------------------------------------------------|-----------| +| YOLOv5u | `yolov5nu`, `yolov5su`, `yolov5mu`, `yolov5lu`, `yolov5xu`, `yolov5n6u`, `yolov5s6u`, `yolov5m6u`, `yolov5l6u`, `yolov5x6u` | Detection | + +### Supported Modes +| Mode | Supported | +|------------|--------------------| +| Inference | :heavy_check_mark: | +| Validation | :heavy_check_mark: | +| Training | :heavy_check_mark: | + + +??? Performance + + + === "Detection" + + | Model | size
(pixels) | mAPval
50-95 | Speed
CPU ONNX
(ms) | Speed
A100 TensorRT
(ms) | params
(M) | FLOPs
(B) | + | ---------------------------------------------------------------------------------------- | --------------------- | -------------------- | ------------------------------ | ----------------------------------- | ------------------ | ----------------- | + | [YOLOv5nu](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5nu.pt) | 640 | 34.3 | 73.6 | 1.06 | 2.6 | 7.7 | + | [YOLOv5su](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5su.pt) | 640 | 43.0 | 120.7 | 1.27 | 9.1 | 24.0 | + | [YOLOv5mu](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5mu.pt) | 640 | 49.0 | 233.9 | 1.86 | 25.1 | 64.2 | + | [YOLOv5lu](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5lu.pt) | 640 | 52.2 | 408.4 | 2.50 | 53.2 | 135.0 | + | [YOLOv5xu](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5xu.pt) | 640 | 53.2 | 763.2 | 3.81 | 97.2 | 246.4 | + | | | | | | | | + | [YOLOv5n6u](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5n6u.pt) | 1280 | 42.1 | - | - | 4.3 | 7.8 | + | [YOLOv5s6u](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5s6u.pt) | 1280 | 48.6 | - | - | 15.3 | 24.6 | + | [YOLOv5m6u](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5m6u.pt) | 1280 | 53.6 | - | - | 41.2 | 65.7 | + | [YOLOv5l6u](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5l6u.pt) | 1280 | 55.7 | - | - | 86.1 | 137.4 | + | [YOLOv5x6u](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5x6u.pt) | 1280 | 56.8 | - | - | 155.4 | 250.7 | + +--- +## Vision Transformers +Vit models currently support Python environment: + +```python +from ultralytics.vit import SAM +# from ultralytics.vit import MODEL_TYPe + +model = SAM("sam_b.pt") +model.info() # display model information +model.predict(...) # train the model +``` + +## Segment Anything + +### About + + +### Supported Tasks + +| Model Type | Pre-trained Weights | Tasks Supported | +|------------|---------------------|-----------------------| +| sam base | `sam_b.pt` | Instance Segmentation | +| sam large | `sam_l.pt` | Instance Segmentation | + +### Supported Modes +| Mode | Supported | +|------------|--------------------| +| Inference | :heavy_check_mark: | +| Validation | :x: | +| Training | :x: | diff --git a/docs/reference/nn/modules.md b/docs/reference/nn/modules.md index 05cd7bc..9ec6eaf 100644 --- a/docs/reference/nn/modules.md +++ b/docs/reference/nn/modules.md @@ -138,6 +138,16 @@ :::ultralytics.nn.modules.Detect

+# MLPBlock +--- +:::ultralytics.nn.modules.MLPBlock +

+ +# LayerNorm2d +--- +:::ultralytics.nn.modules.LayerNorm2d +

+ # Segment --- :::ultralytics.nn.modules.Segment diff --git a/docs/reference/yolo/data/annotator.md b/docs/reference/yolo/data/annotator.md new file mode 100644 index 0000000..ec61aca --- /dev/null +++ b/docs/reference/yolo/data/annotator.md @@ -0,0 +1,4 @@ +# auto_annotate +--- +:::ultralytics.yolo.data.annotator.auto_annotate +

diff --git a/docs/reference/yolo/data/build.md b/docs/reference/yolo/data/build.md index 8b9b5a8..d333d9d 100644 --- a/docs/reference/yolo/data/build.md +++ b/docs/reference/yolo/data/build.md @@ -13,14 +13,14 @@ :::ultralytics.yolo.data.build.seed_worker

-# build_dataloader +# build_yolo_dataset --- -:::ultralytics.yolo.data.build.build_dataloader +:::ultralytics.yolo.data.build.build_yolo_dataset

-# build_classification_dataloader +# build_dataloader --- -:::ultralytics.yolo.data.build.build_classification_dataloader +:::ultralytics.yolo.data.build.build_dataloader

# check_source diff --git a/docs/reference/yolo/utils/callbacks/comet.md b/docs/reference/yolo/utils/callbacks/comet.md index 3d3b5e0..6265e15 100644 --- a/docs/reference/yolo/utils/callbacks/comet.md +++ b/docs/reference/yolo/utils/callbacks/comet.md @@ -1,3 +1,38 @@ +# _get_comet_mode +--- +:::ultralytics.yolo.utils.callbacks.comet._get_comet_mode +

+ +# _get_comet_model_name +--- +:::ultralytics.yolo.utils.callbacks.comet._get_comet_model_name +

+ +# _get_eval_batch_logging_interval +--- +:::ultralytics.yolo.utils.callbacks.comet._get_eval_batch_logging_interval +

+ +# _get_max_image_predictions_to_log +--- +:::ultralytics.yolo.utils.callbacks.comet._get_max_image_predictions_to_log +

+ +# _scale_confidence_score +--- +:::ultralytics.yolo.utils.callbacks.comet._scale_confidence_score +

+ +# _should_log_confusion_matrix +--- +:::ultralytics.yolo.utils.callbacks.comet._should_log_confusion_matrix +

+ +# _should_log_image_predictions +--- +:::ultralytics.yolo.utils.callbacks.comet._should_log_image_predictions +

+ # _get_experiment_type --- :::ultralytics.yolo.utils.callbacks.comet._get_experiment_type diff --git a/docs/reference/yolo/utils/callbacks/neptune.md b/docs/reference/yolo/utils/callbacks/neptune.md new file mode 100644 index 0000000..bd17a2e --- /dev/null +++ b/docs/reference/yolo/utils/callbacks/neptune.md @@ -0,0 +1,39 @@ +# _log_scalars +--- +:::ultralytics.yolo.utils.callbacks.neptune._log_scalars +

+ +# _log_images +--- +:::ultralytics.yolo.utils.callbacks.neptune._log_images +

+ +# _log_plot +--- +:::ultralytics.yolo.utils.callbacks.neptune._log_plot +

+ +# on_pretrain_routine_start +--- +:::ultralytics.yolo.utils.callbacks.neptune.on_pretrain_routine_start +

+ +# on_train_epoch_end +--- +:::ultralytics.yolo.utils.callbacks.neptune.on_train_epoch_end +

+ +# on_fit_epoch_end +--- +:::ultralytics.yolo.utils.callbacks.neptune.on_fit_epoch_end +

+ +# on_val_end +--- +:::ultralytics.yolo.utils.callbacks.neptune.on_val_end +

+ +# on_train_end +--- +:::ultralytics.yolo.utils.callbacks.neptune.on_train_end +

diff --git a/docs/yolov5/index.md b/docs/yolov5/index.md index 966a8c8..0e5c2db 100644 --- a/docs/yolov5/index.md +++ b/docs/yolov5/index.md @@ -84,4 +84,7 @@ hours and on every commit. + + + \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index f587be8..b2adecd 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -84,6 +84,8 @@ extra: link: https://hub.docker.com/r/ultralytics/ultralytics/ - icon: fontawesome/brands/python link: https://pypi.org/project/ultralytics/ + - icon: fontawesome/brands/discord + link: https://discord.gg/n6cFeSPZdD extra_css: - stylesheets/style.css @@ -201,6 +203,8 @@ nav: - Segment: tasks/segment.md - Classify: tasks/classify.md - Pose: tasks/pose.md + - Models: + - models/index.md - Quickstart: quickstart.md - Modes: - modes/index.md @@ -246,6 +250,7 @@ nav: - matching: reference/tracker/utils/matching.md - yolo: - data: + - annotator: reference/yolo/data/annotator.md - augment: reference/yolo/data/augment.md - base: reference/yolo/data/base.md - build: reference/yolo/data/build.md @@ -330,4 +335,11 @@ nav: - Neural Magic's DeepSparse: yolov5/tutorials/neural_magic_pruning_quantization.md - Comet Logging: yolov5/tutorials/comet_logging_integration.md - Clearml Logging: yolov5/tutorials/clearml_logging_integration.md - - Security: SECURITY.md + - Help: + - Help: help/index.md + - Frequently Asked Questions (FAQ): help/FAQ.md + - Contributing Guide: help/contributing.md + - Contributor License Agreement (CLA): help/CLA.md + - Minimum Reproducible Example (MRE) Guide: help/minimum_reproducible_example.md + - Code of Conduct: help/code_of_conduct.md + - Security Policy: SECURITY.md diff --git a/tests/test_python.py b/tests/test_python.py index 56bac37..ac5d971 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -51,6 +51,7 @@ def test_predict_img(): model = YOLO(MODEL) seg_model = YOLO('yolov8n-seg.pt') cls_model = YOLO('yolov8n-cls.pt') + pose_model = YOLO('yolov8n-pose.pt') im = cv2.imread(str(SOURCE)) assert len(model(source=Image.open(SOURCE), save=True, verbose=True)) == 1 # PIL assert len(model(source=im, save=True, save_txt=True)) == 1 # ndarray @@ -64,18 +65,20 @@ def test_predict_img(): cv2.imread(str(SOURCE)), # OpenCV Image.open(SOURCE), # PIL np.zeros((320, 640, 3))] # numpy - assert len(model(batch)) == len(batch) # multiple sources in a batch + assert len(model(batch, visualize=True)) == len(batch) # multiple sources in a batch # Test tensor inference im = cv2.imread(str(SOURCE)) # OpenCV t = cv2.resize(im, (32, 32)) t = torch.from_numpy(t.transpose((2, 0, 1))) t = torch.stack([t, t, t, t]) - results = model(t) + results = model(t, visualize=True) assert len(results) == t.shape[0] - results = seg_model(t) + results = seg_model(t, visualize=True) assert len(results) == t.shape[0] - results = cls_model(t) + results = cls_model(t, visualize=True) + assert len(results) == t.shape[0] + results = pose_model(t, visualize=True) assert len(results) == t.shape[0] diff --git a/ultralytics/__init__.py b/ultralytics/__init__.py index fc9d002..24d0866 100644 --- a/ultralytics/__init__.py +++ b/ultralytics/__init__.py @@ -1,6 +1,6 @@ # Ultralytics YOLO 🚀, AGPL-3.0 license -__version__ = '8.0.89' +__version__ = '8.0.90' from ultralytics.hub import start from ultralytics.vit.sam import SAM diff --git a/ultralytics/models/README.md b/ultralytics/models/README.md index 3e05794..a0edc4b 100644 --- a/ultralytics/models/README.md +++ b/ultralytics/models/README.md @@ -12,7 +12,7 @@ directory provides a great starting point for your custom model development need To get started, simply browse through the models in this directory and find one that best suits your needs. Once you've selected a model, you can use the provided `*.yaml` file to train and deploy your custom YOLO model with ease. See full -details at the Ultralytics [Docs](https://docs.ultralytics.com), and if you need help or have any questions, feel free +details at the Ultralytics [Docs](https://docs.ultralytics.com/models), and if you need help or have any questions, feel free to reach out to the Ultralytics team for support. So, don't wait, start creating your custom YOLO model now! ### Usage @@ -37,92 +37,9 @@ model.train(data="coco128.yaml", epochs=100) # train the model ## Pre-trained Model Architectures -Ultralytics supports many model architectures. Visit [models](#) page to view detailed information and usage. -Any of these models can be used by loading their configs or pretrained checkpoints if available. +Ultralytics supports many model architectures. Visit https://docs.ultralytics.com/models to view detailed information +and usage. Any of these models can be used by loading their configs or pretrained checkpoints if available. -What to add your model architecture? [Here's](#) how you can contribute +## Contributing New Models -### 1. YOLOv8 - -**About** - Cutting edge Detection, Segmentation, Classification and Pose models developed by Ultralytics.
- -Available Models: - -- Detection - `yolov8n`, `yolov8s`, `yolov8m`, `yolov8l`, `yolov8x` -- Instance Segmentation - `yolov8n-seg`, `yolov8s-seg`, `yolov8m-seg`, `yolov8l-seg`, `yolov8x-seg` -- Classification - `yolov8n-cls`, `yolov8s-cls`, `yolov8m-cls`, `yolov8l-cls`, `yolov8x-cls` -- Pose - `yolov8n-pose`, `yolov8s-pose`, `yolov8m-pose`, `yolov8l-pose`, `yolov8x-pose`, `yolov8x-pose-p6` - -
Performance - -### Detection - -| Model | size
(pixels) | mAPval
50-95 | Speed
CPU ONNX
(ms) | Speed
A100 TensorRT
(ms) | params
(M) | FLOPs
(B) | -| ------------------------------------------------------------------------------------ | --------------------- | -------------------- | ------------------------------ | ----------------------------------- | ------------------ | ----------------- | -| [YOLOv8n](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt) | 640 | 37.3 | 80.4 | 0.99 | 3.2 | 8.7 | -| [YOLOv8s](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8s.pt) | 640 | 44.9 | 128.4 | 1.20 | 11.2 | 28.6 | -| [YOLOv8m](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8m.pt) | 640 | 50.2 | 234.7 | 1.83 | 25.9 | 78.9 | -| [YOLOv8l](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8l.pt) | 640 | 52.9 | 375.2 | 2.39 | 43.7 | 165.2 | -| [YOLOv8x](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8x.pt) | 640 | 53.9 | 479.1 | 3.53 | 68.2 | 257.8 | - -### Segmentation - -| Model | size
(pixels) | mAPbox
50-95 | mAPmask
50-95 | Speed
CPU ONNX
(ms) | Speed
A100 TensorRT
(ms) | params
(M) | FLOPs
(B) | -| -------------------------------------------------------------------------------------------- | --------------------- | -------------------- | --------------------- | ------------------------------ | ----------------------------------- | ------------------ | ----------------- | -| [YOLOv8n-seg](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n-seg.pt) | 640 | 36.7 | 30.5 | 96.1 | 1.21 | 3.4 | 12.6 | -| [YOLOv8s-seg](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8s-seg.pt) | 640 | 44.6 | 36.8 | 155.7 | 1.47 | 11.8 | 42.6 | -| [YOLOv8m-seg](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8m-seg.pt) | 640 | 49.9 | 40.8 | 317.0 | 2.18 | 27.3 | 110.2 | -| [YOLOv8l-seg](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8l-seg.pt) | 640 | 52.3 | 42.6 | 572.4 | 2.79 | 46.0 | 220.5 | -| [YOLOv8x-seg](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8x-seg.pt) | 640 | 53.4 | 43.4 | 712.1 | 4.02 | 71.8 | 344.1 | - -### Classification - -| Model | size
(pixels) | acc
top1 | acc
top5 | Speed
CPU ONNX
(ms) | Speed
A100 TensorRT
(ms) | params
(M) | FLOPs
(B) at 640 | -| -------------------------------------------------------------------------------------------- | --------------------- | ---------------- | ---------------- | ------------------------------ | ----------------------------------- | ------------------ | ------------------------ | -| [YOLOv8n-cls](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n-cls.pt) | 224 | 66.6 | 87.0 | 12.9 | 0.31 | 2.7 | 4.3 | -| [YOLOv8s-cls](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8s-cls.pt) | 224 | 72.3 | 91.1 | 23.4 | 0.35 | 6.4 | 13.5 | -| [YOLOv8m-cls](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8m-cls.pt) | 224 | 76.4 | 93.2 | 85.4 | 0.62 | 17.0 | 42.7 | -| [YOLOv8l-cls](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8l-cls.pt) | 224 | 78.0 | 94.1 | 163.0 | 0.87 | 37.5 | 99.7 | -| [YOLOv8x-cls](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8x-cls.pt) | 224 | 78.4 | 94.3 | 232.0 | 1.01 | 57.4 | 154.8 | - -### Pose - -| Model | size
(pixels) | mAPpose
50-95 | mAPpose
50 | Speed
CPU ONNX
(ms) | Speed
A100 TensorRT
(ms) | params
(M) | FLOPs
(B) | -| ---------------------------------------------------------------------------------------------------- | --------------------- | --------------------- | ------------------ | ------------------------------ | ----------------------------------- | ------------------ | ----------------- | -| [YOLOv8n-pose](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n-pose.pt) | 640 | 50.4 | 80.1 | 131.8 | 1.18 | 3.3 | 9.2 | -| [YOLOv8s-pose](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8s-pose.pt) | 640 | 60.0 | 86.2 | 233.2 | 1.42 | 11.6 | 30.2 | -| [YOLOv8m-pose](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8m-pose.pt) | 640 | 65.0 | 88.8 | 456.3 | 2.00 | 26.4 | 81.0 | -| [YOLOv8l-pose](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8l-pose.pt) | 640 | 67.6 | 90.0 | 784.5 | 2.59 | 44.4 | 168.6 | -| [YOLOv8x-pose](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8x-pose.pt) | 640 | 69.2 | 90.2 | 1607.1 | 3.73 | 69.4 | 263.2 | -| [YOLOv8x-pose-p6](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8x-pose-p6.pt) | 1280 | 71.6 | 91.2 | 4088.7 | 10.04 | 99.1 | 1066.4 | - -
- -### 2. YOLOv5u - -**About** - Anchor-free YOLOv5 models with new detection head and better speed-accuracy tradeoff
- -Available Models: - -- Detection P5/32 - `yolov5nu`, `yolov5su`, `yolov5mu`, `yolov5lu`, `yolov5xu` -- Detection P6/64 - `yolov5n6u`, `yolov5s6u`, `yolov5m6u`, `yolov5l6u`, `yolov5x6u` - -
Performance - -### Detection - -| Model | size
(pixels) | mAPval
50-95 | Speed
CPU ONNX
(ms) | Speed
A100 TensorRT
(ms) | params
(M) | FLOPs
(B) | -| ---------------------------------------------------------------------------------------- | --------------------- | -------------------- | ------------------------------ | ----------------------------------- | ------------------ | ----------------- | -| [YOLOv5nu](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5nu.pt) | 640 | 34.3 | 73.6 | 1.06 | 2.6 | 7.7 | -| [YOLOv5su](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5su.pt) | 640 | 43.0 | 120.7 | 1.27 | 9.1 | 24.0 | -| [YOLOv5mu](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5mu.pt) | 640 | 49.0 | 233.9 | 1.86 | 25.1 | 64.2 | -| [YOLOv5lu](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5lu.pt) | 640 | 52.2 | 408.4 | 2.50 | 53.2 | 135.0 | -| [YOLOv5xu](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5xu.pt) | 640 | 53.2 | 763.2 | 3.81 | 97.2 | 246.4 | -| | | | | | | | -| [YOLOv5n6u](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5n6u.pt) | 1280 | 42.1 | - | - | 4.3 | 7.8 | -| [YOLOv5s6u](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5s6u.pt) | 1280 | 48.6 | - | - | 15.3 | 24.6 | -| [YOLOv5m6u](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5m6u.pt) | 1280 | 53.6 | - | - | 41.2 | 65.7 | -| [YOLOv5l6u](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5l6u.pt) | 1280 | 55.7 | - | - | 86.1 | 137.4 | -| [YOLOv5x6u](https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov5x6u.pt) | 1280 | 56.8 | - | - | 155.4 | 250.7 | - -
+If you've developed a new model architecture or have improvements for existing models that you'd like to contribute to the Ultralytics community, please submit your contribution in a new Pull Request. For more details, visit our [Contributing Guide](https://docs.ultralytics.com/help/contributing). diff --git a/ultralytics/nn/tasks.py b/ultralytics/nn/tasks.py index dae593a..b4d6050 100644 --- a/ultralytics/nn/tasks.py +++ b/ultralytics/nn/tasks.py @@ -13,6 +13,7 @@ from ultralytics.nn.modules import (C1, C2, C3, C3TR, SPP, SPPF, Bottleneck, Bot GhostBottleneck, GhostConv, Pose, Segment) from ultralytics.yolo.utils import DEFAULT_CFG_DICT, DEFAULT_CFG_KEYS, LOGGER, colorstr, emojis, yaml_load from ultralytics.yolo.utils.checks import check_requirements, check_suffix, check_yaml +from ultralytics.yolo.utils.plotting import feature_visualization from ultralytics.yolo.utils.torch_utils import (fuse_conv_and_bn, fuse_deconv_and_bn, initialize_weights, intersect_dicts, make_divisible, model_info, scale_img, time_sync) @@ -58,8 +59,7 @@ class BaseModel(nn.Module): x = m(x) # run y.append(x if m.i in self.save else None) # save output if visualize: - LOGGER.info('visualize feature not yet supported') - # TODO: feature_visualization(x, m.type, m.i, save_dir=visualize) + feature_visualization(x, m.type, m.i, save_dir=visualize) return x def _profile_one_layer(self, m, x, dt): diff --git a/ultralytics/tracker/trackers/byte_tracker.py b/ultralytics/tracker/trackers/byte_tracker.py index bb87ae9..b8552cf 100644 --- a/ultralytics/tracker/trackers/byte_tracker.py +++ b/ultralytics/tracker/trackers/byte_tracker.py @@ -217,7 +217,7 @@ class BYTETracker: strack_pool = self.joint_stracks(tracked_stracks, self.lost_stracks) # Predict the current location with KF self.multi_predict(strack_pool) - if hasattr(self, 'gmc'): + if hasattr(self, 'gmc') and img is not None: warp = self.gmc.apply(img, dets) STrack.multi_gmc(strack_pool, warp) STrack.multi_gmc(unconfirmed, warp) diff --git a/ultralytics/vit/sam/modules/encoders.py b/ultralytics/vit/sam/modules/encoders.py index 4da6155..52be592 100644 --- a/ultralytics/vit/sam/modules/encoders.py +++ b/ultralytics/vit/sam/modules/encoders.py @@ -233,10 +233,10 @@ class PromptEncoder(nn.Module): embeddings. Arguments: - points (tuple(torch.Tensor, torch.Tensor) or none): point coordinates + points (tuple(torch.Tensor, torch.Tensor), None): point coordinates and labels to embed. - boxes (torch.Tensor or none): boxes to embed - masks (torch.Tensor or none): masks to embed + boxes (torch.Tensor, None): boxes to embed + masks (torch.Tensor, None): masks to embed Returns: torch.Tensor: sparse embeddings for the points and boxes, with shape @@ -337,7 +337,7 @@ class Block(nn.Module): rel_pos_zero_init (bool): If True, zero initialize relative positional parameters. window_size (int): Window size for window attention blocks. If it equals 0, then use global attention. - input_size (tuple(int, int) or None): Input resolution for calculating the relative + input_size (tuple(int, int), None): Input resolution for calculating the relative positional parameter size. """ super().__init__() @@ -392,9 +392,8 @@ class Attention(nn.Module): dim (int): Number of input channels. num_heads (int): Number of attention heads. qkv_bias (bool): If True, add a learnable bias to query, key, value. - rel_pos (bool): If True, add relative positional embeddings to the attention map. rel_pos_zero_init (bool): If True, zero initialize relative positional parameters. - input_size (tuple(int, int) or None): Input resolution for calculating the relative + input_size (tuple(int, int), None): Input resolution for calculating the relative positional parameter size. """ super().__init__() diff --git a/ultralytics/vit/sam/modules/mask_generator.py b/ultralytics/vit/sam/modules/mask_generator.py index ff17fb9..f014608 100644 --- a/ultralytics/vit/sam/modules/mask_generator.py +++ b/ultralytics/vit/sam/modules/mask_generator.py @@ -45,7 +45,7 @@ class SamAutomaticMaskGenerator: Arguments: model (Sam): The SAM model to use for mask prediction. - points_per_side (int or None): The number of points to be sampled + points_per_side (int, None): The number of points to be sampled along one side of the image. The total number of points is points_per_side**2. If None, 'point_grids' must provide explicit point sampling. @@ -70,7 +70,7 @@ class SamAutomaticMaskGenerator: the image length. Later layers with more crops scale down this overlap. crop_n_points_downscale_factor (int): The number of points-per-side sampled in layer n is scaled down by crop_n_points_downscale_factor**n. - point_grids (list(np.ndarray) or None): A list over explicit grids + point_grids (list(np.ndarray), None): A list over explicit grids of points used for sampling, normalized to [0,1]. The nth grid in the list is used in the nth crop layer. Exclusive with points_per_side. min_mask_region_area (int): If >0, postprocessing will be applied @@ -128,9 +128,8 @@ class SamAutomaticMaskGenerator: image (np.ndarray): The image to generate masks for, in HWC uint8 format. Returns: - list(dict(str, any)): A list over records for masks. Each record is - a dict containing the following keys: - segmentation (dict(str, any) or np.ndarray): The mask. If + list(dict(str, any)): A list over records for masks. Each record is a dict containing the following keys: + segmentation (dict(str, any), np.ndarray): The mask. If output_mode='binary_mask', is an array of shape HW. Otherwise, is a dictionary containing the RLE. bbox (list(float)): The box around the mask, in XYWH format. diff --git a/ultralytics/vit/sam/modules/prompt_predictor.py b/ultralytics/vit/sam/modules/prompt_predictor.py index 82da985..bf61186 100644 --- a/ultralytics/vit/sam/modules/prompt_predictor.py +++ b/ultralytics/vit/sam/modules/prompt_predictor.py @@ -81,12 +81,12 @@ class PromptPredictor: Predict masks for the given input prompts, using the currently set image. Arguments: - point_coords (np.ndarray or None): A Nx2 array of point prompts to the + point_coords (np.ndarray, None): A Nx2 array of point prompts to the model. Each point is in (X,Y) in pixels. - point_labels (np.ndarray or None): A length N array of labels for the + point_labels (np.ndarray, None): A length N array of labels for the point prompts. 1 indicates a foreground point and 0 indicates a background point. - box (np.ndarray or None): A length 4 array given a box prompt to the + box (np.ndarray, None): A length 4 array given a box prompt to the model, in XYXY format. mask_input (np.ndarray): A low resolution mask input to the model, typically coming from a previous prediction iteration. Has form 1xHxW, where @@ -158,12 +158,12 @@ class PromptPredictor: transformed to the input frame using ResizeLongestSide. Arguments: - point_coords (torch.Tensor or None): A BxNx2 array of point prompts to the + point_coords (torch.Tensor, None): A BxNx2 array of point prompts to the model. Each point is in (X,Y) in pixels. - point_labels (torch.Tensor or None): A BxN array of labels for the + point_labels (torch.Tensor, None): A BxN array of labels for the point prompts. 1 indicates a foreground point and 0 indicates a background point. - boxes (np.ndarray or None): A Bx4 array given a box prompt to the + boxes (np.ndarray, None): A Bx4 array given a box prompt to the model, in XYXY format. mask_input (np.ndarray): A low resolution mask input to the model, typically coming from a previous prediction iteration. Has form Bx1xHxW, where diff --git a/ultralytics/yolo/data/annotator.py b/ultralytics/yolo/data/annotator.py index ec52194..56b8eb1 100644 --- a/ultralytics/yolo/data/annotator.py +++ b/ultralytics/yolo/data/annotator.py @@ -6,6 +6,18 @@ from ultralytics.yolo.utils.torch_utils import select_device def auto_annotate(data, det_model='yolov8x.pt', sam_model='sam_b.pt', device='', output_dir=None): + """ + Automatically annotates images using a YOLO object detection model and a SAM segmentation model. + + Args: + data (str): Path to a folder containing images to be annotated. + det_model (str, optional): Pre-trained YOLO detection model. Defaults to 'yolov8x.pt'. + sam_model (str, optional): Pre-trained SAM segmentation model. Defaults to 'sam_b.pt'. + device (str, optional): Device to run the models on. Defaults to an empty string (CPU or GPU, if available). + output_dir (str, None, optional): Directory to save the annotated results. + Defaults to a 'labels' folder in the same directory as 'data'. + + """ device = select_device(device) det_model = YOLO(det_model) sam_model = build_sam(sam_model) @@ -33,7 +45,7 @@ def auto_annotate(data, det_model='yolov8x.pt', sam_model='sam_b.pt', device='', result.update(masks=masks.squeeze(1)) segments = result.masks.xyn # noqa - with open(str(Path(output_dir) / Path(result.path).stem) + '.txt', 'w') as f: + with open(f'{str(Path(output_dir) / Path(result.path).stem)}.txt', 'w') as f: for i in range(len(segments)): s = segments[i] if len(s) == 0: diff --git a/ultralytics/yolo/data/build.py b/ultralytics/yolo/data/build.py index c5f5e2a..0b08006 100644 --- a/ultralytics/yolo/data/build.py +++ b/ultralytics/yolo/data/build.py @@ -141,11 +141,8 @@ def load_inference_source(source=None, imgsz=640, vid_stride=1): Args: source (str, Path, Tensor, PIL.Image, np.ndarray): The input source for inference. - transforms (callable, optional): Custom transformations to be applied to the input source. imgsz (int, optional): The size of the image for inference. Default is 640. vid_stride (int, optional): The frame interval for video sources. Default is 1. - stride (int, optional): The model stride. Default is 32. - auto (bool, optional): Automatically apply pre-processing. Default is True. Returns: dataset (Dataset): A dataset object for the specified input source. diff --git a/ultralytics/yolo/data/dataloaders/stream_loaders.py b/ultralytics/yolo/data/dataloaders/stream_loaders.py index d6aca45..0a39788 100644 --- a/ultralytics/yolo/data/dataloaders/stream_loaders.py +++ b/ultralytics/yolo/data/dataloaders/stream_loaders.py @@ -72,9 +72,6 @@ class LoadStreams: # Check for common shapes self.bs = self.__len__() - if not self.rect: - LOGGER.warning('WARNING ⚠️ Stream shapes differ. For optimal performance supply similarly-shaped streams.') - def update(self, i, cap, stream): """Read stream `i` frames in daemon thread.""" n, f = 0, self.frames[i] # frame number, frame array diff --git a/ultralytics/yolo/engine/predictor.py b/ultralytics/yolo/engine/predictor.py index f27a8f4..957e97d 100644 --- a/ultralytics/yolo/engine/predictor.py +++ b/ultralytics/yolo/engine/predictor.py @@ -116,6 +116,9 @@ class BasePredictor: """ if not isinstance(im, torch.Tensor): auto = all(x.shape == im[0].shape for x in im) and self.model.pt + if not auto: + LOGGER.warning( + 'WARNING ⚠️ Source shapes differ. For optimal performance supply similarly-shaped sources.') im = np.stack([LetterBox(self.imgsz, auto=auto, stride=self.model.stride)(image=x) for x in im]) im = im[..., ::-1].transpose((0, 3, 1, 2)) # BGR to RGB, BHWC to BCHW, (n, 3, h, w) im = np.ascontiguousarray(im) # contiguous @@ -217,7 +220,8 @@ class BasePredictor: self.run_callbacks('on_predict_batch_start') self.batch = batch path, im0s, vid_cap, s = batch - visualize = increment_path(self.save_dir / Path(path).stem, mkdir=True) if self.args.visualize else False + visualize = increment_path(self.save_dir / Path(path[0]).stem, + mkdir=True) if self.args.visualize and (not self.source_type.tensor) else False # Preprocess with self.dt[0]: @@ -298,7 +302,7 @@ class BasePredictor: cv2.namedWindow(str(p), cv2.WINDOW_NORMAL | cv2.WINDOW_KEEPRATIO) # allow window resize (Linux) cv2.resizeWindow(str(p), im0.shape[1], im0.shape[0]) cv2.imshow(str(p), im0) - cv2.waitKey(500 if self.batch[4].startswith('image') else 1) # 1 millisecond + cv2.waitKey(500 if self.batch[3].startswith('image') else 1) # 1 millisecond def save_preds(self, vid_cap, idx, save_path): """Save video predictions as mp4 at specified path.""" diff --git a/ultralytics/yolo/utils/metrics.py b/ultralytics/yolo/utils/metrics.py index 70c5fd2..4008767 100644 --- a/ultralytics/yolo/utils/metrics.py +++ b/ultralytics/yolo/utils/metrics.py @@ -205,7 +205,7 @@ class FocalLoss(nn.Module): return loss.mean() elif self.reduction == 'sum': return loss.sum() - else: # 'none' + else: # 'None' return loss diff --git a/ultralytics/yolo/utils/ops.py b/ultralytics/yolo/utils/ops.py index a45fc17..17dbd4a 100644 --- a/ultralytics/yolo/utils/ops.py +++ b/ultralytics/yolo/utils/ops.py @@ -148,7 +148,7 @@ def non_max_suppression( Perform non-maximum suppression (NMS) on a set of boxes, with support for masks and multiple labels per box. Arguments: - prediction (torch.Tensor): A tensor of shape (batch_size, num_boxes, num_classes + 4 + num_masks) + prediction (torch.Tensor): A tensor of shape (batch_size, num_classes + 4 + num_masks, num_boxes) containing the predicted boxes, classes, and masks. The tensor should be in the format output by a model, such as YOLO. conf_thres (float): The confidence threshold below which boxes will be filtered out. diff --git a/ultralytics/yolo/utils/plotting.py b/ultralytics/yolo/utils/plotting.py index a351db2..0b352d8 100644 --- a/ultralytics/yolo/utils/plotting.py +++ b/ultralytics/yolo/utils/plotting.py @@ -469,3 +469,39 @@ def output_to_target(output, max_det=300): targets.append(torch.cat((j, cls, xyxy2xywh(box), conf), 1)) targets = torch.cat(targets, 0).numpy() return targets[:, 0], targets[:, 1], targets[:, 2:] + + +def feature_visualization(x, module_type, stage, n=32, save_dir=Path('runs/detect/exp')): + """ + Visualize feature maps of a given model module during inference. + + Args: + x (torch.Tensor): Features to be visualized. + module_type (str): Module type. + stage (int): Module stage within the model. + n (int, optional): Maximum number of feature maps to plot. Defaults to 32. + save_dir (Path, optional): Directory to save results. Defaults to Path('runs/detect/exp'). + + Returns: + None: This function does not return any value; it saves the visualization to the specified directory. + """ + for m in ['Detect', 'Pose', 'Segment']: + if m in module_type: + return + batch, channels, height, width = x.shape # batch, channels, height, width + if height > 1 and width > 1: + f = save_dir / f"stage{stage}_{module_type.split('.')[-1]}_features.png" # filename + + blocks = torch.chunk(x[0].cpu(), channels, dim=0) # select batch index 0, block by channels + n = min(n, channels) # number of plots + fig, ax = plt.subplots(math.ceil(n / 8), 8, tight_layout=True) # 8 rows x n/8 cols + ax = ax.ravel() + plt.subplots_adjust(wspace=0.05, hspace=0.05) + for i in range(n): + ax[i].imshow(blocks[i].squeeze()) # cmap='gray' + ax[i].axis('off') + + LOGGER.info(f'Saving {f}... ({n}/{channels})') + plt.savefig(f, dpi=300, bbox_inches='tight') + plt.close() + np.save(str(f.with_suffix('.npy')), x[0].cpu().numpy()) # npy save diff --git a/ultralytics/yolo/v8/detect/train.py b/ultralytics/yolo/v8/detect/train.py index 2965089..ad49c8a 100644 --- a/ultralytics/yolo/v8/detect/train.py +++ b/ultralytics/yolo/v8/detect/train.py @@ -27,7 +27,7 @@ class DetectionTrainer(BaseTrainer): Args: img_path (str): Path to the folder containing images. mode (str): `train` mode or `val` mode, users are able to customize different augmentations for each mode. - batch_size (int, optional): Size of batches, this is for `rect`. Defaults to None. + batch (int, optional): Size of batches, this is for `rect`. Defaults to None. """ gs = max(int(de_parallel(self.model).stride.max() if self.model else 0), 32) return build_yolo_dataset(self.args, img_path, batch, self.data, mode=mode, rect=mode == 'val', stride=gs) diff --git a/ultralytics/yolo/v8/detect/val.py b/ultralytics/yolo/v8/detect/val.py index 907a530..c4dc972 100644 --- a/ultralytics/yolo/v8/detect/val.py +++ b/ultralytics/yolo/v8/detect/val.py @@ -177,7 +177,7 @@ class DetectionValidator(BaseValidator): Args: img_path (str): Path to the folder containing images. mode (str): `train` mode or `val` mode, users are able to customize different augmentations for each mode. - batch_size (int, optional): Size of batches, this is for `rect`. Defaults to None. + batch (int, optional): Size of batches, this is for `rect`. Defaults to None. """ gs = max(int(de_parallel(self.model).stride if self.model else 0), 32) return build_yolo_dataset(self.args, img_path, batch, self.data, mode=mode, stride=gs)