更新git
This commit is contained in:
parent
ffc10af708
commit
19e019181c
166
CONTRIBUTING.md
Normal file
166
CONTRIBUTING.md
Normal file
@ -0,0 +1,166 @@
|
||||
---
|
||||
comments: true
|
||||
description: Learn how to contribute to Ultralytics YOLO open-source repositories. Follow guidelines for pull requests, code of conduct, and bug reporting.
|
||||
keywords: Ultralytics, YOLO, open-source, contribution, pull request, code of conduct, bug reporting, GitHub, CLA, Google-style docstrings
|
||||
---
|
||||
|
||||
# Contributing to Ultralytics Open-Source Projects
|
||||
|
||||
Welcome! We're thrilled that you're considering contributing to our [Ultralytics](https://www.ultralytics.com/) [open-source](https://github.com/ultralytics) projects. Your involvement not only helps enhance the quality of our repositories but also benefits the entire community. This guide provides clear guidelines and best practices to help you get started.
|
||||
|
||||
<a href="https://github.com/ultralytics/ultralytics/graphs/contributors">
|
||||
<img width="100%" src="https://github.com/ultralytics/assets/raw/main/im/image-contributors.png" alt="Ultralytics open-source contributors"></a>
|
||||
|
||||
## Table of Contents
|
||||
|
||||
1. [Code of Conduct](#code-of-conduct)
|
||||
2. [Contributing via Pull Requests](#contributing-via-pull-requests)
|
||||
- [CLA Signing](#cla-signing)
|
||||
- [Google-Style Docstrings](#google-style-docstrings)
|
||||
- [GitHub Actions CI Tests](#github-actions-ci-tests)
|
||||
3. [Reporting Bugs](#reporting-bugs)
|
||||
4. [License](#license)
|
||||
5. [Conclusion](#conclusion)
|
||||
6. [FAQ](#faq)
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
To ensure a welcoming and inclusive environment for everyone, all contributors must adhere to our [Code of Conduct](https://docs.ultralytics.com/help/code_of_conduct/). Respect, kindness, and professionalism are at the heart of our community.
|
||||
|
||||
## Contributing via Pull Requests
|
||||
|
||||
We greatly appreciate contributions in the form of pull requests. To make the review process as smooth as possible, please follow these steps:
|
||||
|
||||
1. **[Fork the repository](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo):** Start by forking the Ultralytics YOLO repository to your GitHub account.
|
||||
|
||||
2. **[Create a branch](https://docs.github.com/en/desktop/making-changes-in-a-branch/managing-branches-in-github-desktop):** Create a new branch in your forked repository with a clear, descriptive name that reflects your changes.
|
||||
|
||||
3. **Make your changes:** Ensure your code adheres to the project's style guidelines and does not introduce any new errors or warnings.
|
||||
|
||||
4. **[Test your changes](https://github.com/ultralytics/ultralytics/tree/main/tests):** Before submitting, test your changes locally to confirm they work as expected and don't cause any new issues.
|
||||
|
||||
5. **[Commit your changes](https://docs.github.com/en/desktop/making-changes-in-a-branch/committing-and-reviewing-changes-to-your-project-in-github-desktop):** Commit your changes with a concise and descriptive commit message. If your changes address a specific issue, include the issue number in your commit message.
|
||||
|
||||
6. **[Create a pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request):** Submit a pull request from your forked repository to the main Ultralytics YOLO repository. Provide a clear and detailed explanation of your changes and how they improve the project.
|
||||
|
||||
### CLA Signing
|
||||
|
||||
Before we can merge your pull request, you must sign our [Contributor License Agreement (CLA)](https://docs.ultralytics.com/help/CLA/). This legal agreement ensures that your contributions are properly licensed, allowing the project to continue being distributed under the AGPL-3.0 license.
|
||||
|
||||
After submitting your pull request, the CLA bot will guide you through the signing process. To sign the CLA, simply add a comment in your PR stating:
|
||||
|
||||
```
|
||||
I have read the CLA Document and I sign the CLA
|
||||
```
|
||||
|
||||
### Google-Style Docstrings
|
||||
|
||||
When adding new functions or classes, please include [Google-style docstrings](https://google.github.io/styleguide/pyguide.html). These docstrings provide clear, standardized documentation that helps other developers understand and maintain your code.
|
||||
|
||||
#### Example
|
||||
|
||||
This example illustrates a Google-style docstring. Ensure that both input and output `types` are always enclosed in parentheses, e.g., `(bool)`.
|
||||
|
||||
```python
|
||||
def example_function(arg1, arg2=4):
|
||||
"""
|
||||
Example function demonstrating Google-style docstrings.
|
||||
|
||||
Args:
|
||||
arg1 (int): The first argument.
|
||||
arg2 (int): The second argument, with a default value of 4.
|
||||
|
||||
Returns:
|
||||
(bool): True if successful, False otherwise.
|
||||
|
||||
Examples:
|
||||
>>> result = example_function(1, 2) # returns False
|
||||
"""
|
||||
if arg1 == arg2:
|
||||
return True
|
||||
return False
|
||||
```
|
||||
|
||||
#### Example with type hints
|
||||
|
||||
This example includes both a Google-style docstring and type hints for arguments and returns, though using either independently is also acceptable.
|
||||
|
||||
```python
|
||||
def example_function(arg1: int, arg2: int = 4) -> bool:
|
||||
"""
|
||||
Example function demonstrating Google-style docstrings.
|
||||
|
||||
Args:
|
||||
arg1: The first argument.
|
||||
arg2: The second argument, with a default value of 4.
|
||||
|
||||
Returns:
|
||||
True if successful, False otherwise.
|
||||
|
||||
Examples:
|
||||
>>> result = example_function(1, 2) # returns False
|
||||
"""
|
||||
if arg1 == arg2:
|
||||
return True
|
||||
return False
|
||||
```
|
||||
|
||||
#### Example Single-line
|
||||
|
||||
For smaller or simpler functions, a single-line docstring may be sufficient. The docstring must use three double-quotes, be a complete sentence, start with a capital letter, and end with a period.
|
||||
|
||||
```python
|
||||
def example_small_function(arg1: int, arg2: int = 4) -> bool:
|
||||
"""Example function with a single-line docstring."""
|
||||
return arg1 == arg2
|
||||
```
|
||||
|
||||
### GitHub Actions CI Tests
|
||||
|
||||
All pull requests must pass the GitHub Actions [Continuous Integration](https://docs.ultralytics.com/help/CI/) (CI) tests before they can be merged. These tests include linting, unit tests, and other checks to ensure that your changes meet the project's quality standards. Review the CI output and address any issues that arise.
|
||||
|
||||
## Reporting Bugs
|
||||
|
||||
We highly value bug reports as they help us maintain the quality of our projects. When reporting a bug, please provide a [Minimum Reproducible Example](https://docs.ultralytics.com/help/minimum_reproducible_example/)—a simple, clear code example that consistently reproduces the issue. This allows us to quickly identify and resolve the problem.
|
||||
|
||||
## License
|
||||
|
||||
Ultralytics uses the [GNU Affero General Public License v3.0 (AGPL-3.0)](https://github.com/ultralytics/ultralytics/blob/main/LICENSE) for its repositories. This license promotes openness, transparency, and collaborative improvement in software development. It ensures that all users have the freedom to use, modify, and share the software, fostering a strong community of collaboration and innovation.
|
||||
|
||||
We encourage all contributors to familiarize themselves with the terms of the AGPL-3.0 license to contribute effectively and ethically to the Ultralytics open-source community.
|
||||
|
||||
## Conclusion
|
||||
|
||||
Thank you for your interest in contributing to [Ultralytics](https://www.ultralytics.com/) [open-source](https://github.com/ultralytics) YOLO projects. Your participation is essential in shaping the future of our software and building a vibrant community of innovation and collaboration. Whether you're enhancing code, reporting bugs, or suggesting new features, your contributions are invaluable.
|
||||
|
||||
We're excited to see your ideas come to life and appreciate your commitment to advancing object detection technology. Together, let's continue to grow and innovate in this exciting open-source journey. Happy coding! 🚀🌟
|
||||
|
||||
## FAQ
|
||||
|
||||
### Why should I contribute to Ultralytics YOLO open-source repositories?
|
||||
|
||||
Contributing to Ultralytics YOLO open-source repositories improves the software, making it more robust and feature-rich for the entire community. Contributions can include code enhancements, bug fixes, documentation improvements, and new feature implementations. Additionally, contributing allows you to collaborate with other skilled developers and experts in the field, enhancing your own skills and reputation. For details on how to get started, refer to the [Contributing via Pull Requests](#contributing-via-pull-requests) section.
|
||||
|
||||
### How do I sign the Contributor License Agreement (CLA) for Ultralytics YOLO?
|
||||
|
||||
To sign the Contributor License Agreement (CLA), follow the instructions provided by the CLA bot after submitting your pull request. This process ensures that your contributions are properly licensed under the AGPL-3.0 license, maintaining the legal integrity of the open-source project. Add a comment in your pull request stating:
|
||||
|
||||
```
|
||||
I have read the CLA Document and I sign the CLA.
|
||||
```
|
||||
|
||||
For more information, see the [CLA Signing](#cla-signing) section.
|
||||
|
||||
### What are Google-style docstrings, and why are they required for Ultralytics YOLO contributions?
|
||||
|
||||
Google-style docstrings provide clear, concise documentation for functions and classes, improving code readability and maintainability. These docstrings outline the function's purpose, arguments, and return values with specific formatting rules. When contributing to Ultralytics YOLO, following Google-style docstrings ensures that your additions are well-documented and easily understood. For examples and guidelines, visit the [Google-Style Docstrings](#google-style-docstrings) section.
|
||||
|
||||
### How can I ensure my changes pass the GitHub Actions CI tests?
|
||||
|
||||
Before your pull request can be merged, it must pass all GitHub Actions Continuous Integration (CI) tests. These tests include linting, unit tests, and other checks to ensure the code meets
|
||||
|
||||
the project's quality standards. Review the CI output and fix any issues. For detailed information on the CI process and troubleshooting tips, see the [GitHub Actions CI Tests](#github-actions-ci-tests) section.
|
||||
|
||||
### How do I report a bug in Ultralytics YOLO repositories?
|
||||
|
||||
To report a bug, provide a clear and concise [Minimum Reproducible Example](https://docs.ultralytics.com/help/minimum_reproducible_example/) along with your bug report. This helps developers quickly identify and fix the issue. Ensure your example is minimal yet sufficient to replicate the problem. For more detailed steps on reporting bugs, refer to the [Reporting Bugs](#reporting-bugs) section.
|
283
README.md
Normal file
283
README.md
Normal file
@ -0,0 +1,283 @@
|
||||
<div align="center">
|
||||
<p>
|
||||
<a href="https://www.ultralytics.com/events/yolovision" target="_blank">
|
||||
<img width="100%" src="https://raw.githubusercontent.com/ultralytics/assets/main/yolov8/banner-yolov8.png" alt="YOLO Vision banner"></a>
|
||||
</p>
|
||||
|
||||
[中文](https://docs.ultralytics.com/zh) | [한국어](https://docs.ultralytics.com/ko) | [日本語](https://docs.ultralytics.com/ja) | [Русский](https://docs.ultralytics.com/ru) | [Deutsch](https://docs.ultralytics.com/de) | [Français](https://docs.ultralytics.com/fr) | [Español](https://docs.ultralytics.com/es) | [Português](https://docs.ultralytics.com/pt) | [Türkçe](https://docs.ultralytics.com/tr) | [Tiếng Việt](https://docs.ultralytics.com/vi) | [العربية](https://docs.ultralytics.com/ar) <br>
|
||||
|
||||
<div>
|
||||
<a href="https://github.com/ultralytics/ultralytics/actions/workflows/ci.yaml"><img src="https://github.com/ultralytics/ultralytics/actions/workflows/ci.yaml/badge.svg" alt="Ultralytics CI"></a>
|
||||
<a href="https://pepy.tech/projects/ultralytics"><img src="https://static.pepy.tech/badge/ultralytics" alt="Ultralytics Downloads"></a>
|
||||
<a href="https://zenodo.org/badge/latestdoi/264818686"><img src="https://zenodo.org/badge/264818686.svg" alt="Ultralytics YOLO Citation"></a>
|
||||
<a href="https://discord.com/invite/ultralytics"><img alt="Ultralytics Discord" src="https://img.shields.io/discord/1089800235347353640?logo=discord&logoColor=white&label=Discord&color=blue"></a>
|
||||
<a href="https://community.ultralytics.com/"><img alt="Ultralytics Forums" src="https://img.shields.io/discourse/users?server=https%3A%2F%2Fcommunity.ultralytics.com&logo=discourse&label=Forums&color=blue"></a>
|
||||
<a href="https://reddit.com/r/ultralytics"><img alt="Ultralytics Reddit" src="https://img.shields.io/reddit/subreddit-subscribers/ultralytics?style=flat&logo=reddit&logoColor=white&label=Reddit&color=blue"></a>
|
||||
<br>
|
||||
<a href="https://console.paperspace.com/github/ultralytics/ultralytics"><img src="https://assets.paperspace.io/img/gradient-badge.svg" alt="Run Ultralytics on Gradient"></a>
|
||||
<a href="https://colab.research.google.com/github/ultralytics/ultralytics/blob/main/examples/tutorial.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open Ultralytics In Colab"></a>
|
||||
<a href="https://www.kaggle.com/models/ultralytics/yolo11"><img src="https://kaggle.com/static/images/open-in-kaggle.svg" alt="Open Ultralytics In Kaggle"></a>
|
||||
<a href="https://mybinder.org/v2/gh/ultralytics/ultralytics/HEAD?labpath=examples%2Ftutorial.ipynb"><img src="https://mybinder.org/badge_logo.svg" alt="Open Ultralytics In Binder"></a>
|
||||
</div>
|
||||
<br>
|
||||
|
||||
[Ultralytics](https://www.ultralytics.com/) [YOLO11](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. YOLO11 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 YOLO. Please browse the Ultralytics <a href="https://docs.ultralytics.com/">Docs</a> for details, raise an issue on <a href="https://github.com/ultralytics/ultralytics/issues/new/choose">GitHub</a> for support, questions, or discussions, become a member of the Ultralytics <a href="https://discord.com/invite/ultralytics">Discord</a>, <a href="https://reddit.com/r/ultralytics">Reddit</a> and <a href="https://community.ultralytics.com/">Forums</a>!
|
||||
|
||||
To request an Enterprise License please complete the form at [Ultralytics Licensing](https://www.ultralytics.com/license).
|
||||
|
||||
<a href="https://docs.ultralytics.com/models/yolo11/" target="_blank">
|
||||
<img width="100%" src="https://raw.githubusercontent.com/ultralytics/assets/refs/heads/main/yolo/performance-comparison.png" alt="YOLO11 performance plots">
|
||||
</a>
|
||||
|
||||
<div align="center">
|
||||
<a href="https://github.com/ultralytics"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-github.png" width="2%" alt="Ultralytics GitHub"></a>
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="2%" alt="space">
|
||||
<a href="https://www.linkedin.com/company/ultralytics/"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-linkedin.png" width="2%" alt="Ultralytics LinkedIn"></a>
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="2%" alt="space">
|
||||
<a href="https://twitter.com/ultralytics"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-twitter.png" width="2%" alt="Ultralytics Twitter"></a>
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="2%" alt="space">
|
||||
<a href="https://youtube.com/ultralytics?sub_confirmation=1"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-youtube.png" width="2%" alt="Ultralytics YouTube"></a>
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="2%" alt="space">
|
||||
<a href="https://www.tiktok.com/@ultralytics"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-tiktok.png" width="2%" alt="Ultralytics TikTok"></a>
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="2%" alt="space">
|
||||
<a href="https://ultralytics.com/bilibili"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-bilibili.png" width="2%" alt="Ultralytics BiliBili"></a>
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="2%" alt="space">
|
||||
<a href="https://discord.com/invite/ultralytics"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-discord.png" width="2%" alt="Ultralytics Discord"></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
## <div align="center">Documentation</div>
|
||||
|
||||
See below for a quickstart install and usage examples, and see our [Docs](https://docs.ultralytics.com/) for full documentation on training, validation, prediction and deployment.
|
||||
|
||||
<details open>
|
||||
<summary>Install</summary>
|
||||
|
||||
Pip install the ultralytics package including all [requirements](https://github.com/ultralytics/ultralytics/blob/main/pyproject.toml) in a [**Python>=3.8**](https://www.python.org/) environment with [**PyTorch>=1.8**](https://pytorch.org/get-started/locally/).
|
||||
|
||||
[![PyPI - Version](https://img.shields.io/pypi/v/ultralytics?logo=pypi&logoColor=white)](https://pypi.org/project/ultralytics/) [![Ultralytics Downloads](https://static.pepy.tech/badge/ultralytics)](https://www.pepy.tech/projects/ultralytics) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics?logo=python&logoColor=gold)](https://pypi.org/project/ultralytics/)
|
||||
|
||||
```bash
|
||||
pip install ultralytics
|
||||
```
|
||||
|
||||
For alternative installation methods including [Conda](https://anaconda.org/conda-forge/ultralytics), [Docker](https://hub.docker.com/r/ultralytics/ultralytics), and Git, please refer to the [Quickstart Guide](https://docs.ultralytics.com/quickstart/).
|
||||
|
||||
[![Conda Version](https://img.shields.io/conda/vn/conda-forge/ultralytics?logo=condaforge)](https://anaconda.org/conda-forge/ultralytics) [![Docker Image Version](https://img.shields.io/docker/v/ultralytics/ultralytics?sort=semver&logo=docker)](https://hub.docker.com/r/ultralytics/ultralytics) [![Ultralytics Docker Pulls](https://img.shields.io/docker/pulls/ultralytics/ultralytics?logo=docker)](https://hub.docker.com/r/ultralytics/ultralytics)
|
||||
|
||||
</details>
|
||||
|
||||
<details open>
|
||||
<summary>Usage</summary>
|
||||
|
||||
### CLI
|
||||
|
||||
YOLO may be used directly in the Command Line Interface (CLI) with a `yolo` command:
|
||||
|
||||
```bash
|
||||
yolo predict model=yolo11n.pt source='https://ultralytics.com/images/bus.jpg'
|
||||
```
|
||||
|
||||
`yolo` can be used for a variety of tasks and modes and accepts additional arguments, i.e. `imgsz=640`. See the YOLO [CLI Docs](https://docs.ultralytics.com/usage/cli/) for examples.
|
||||
|
||||
### Python
|
||||
|
||||
YOLO may also be used directly in a Python environment, and accepts the same [arguments](https://docs.ultralytics.com/usage/cfg/) as in the CLI example above:
|
||||
|
||||
```python
|
||||
from ultralytics import YOLO
|
||||
|
||||
# Load a model
|
||||
model = YOLO("yolo11n.pt")
|
||||
|
||||
# Train the model
|
||||
train_results = model.train(
|
||||
data="coco8.yaml", # path to dataset YAML
|
||||
epochs=100, # number of training epochs
|
||||
imgsz=640, # training image size
|
||||
device="cpu", # device to run on, i.e. device=0 or device=0,1,2,3 or device=cpu
|
||||
)
|
||||
|
||||
# Evaluate model performance on the validation set
|
||||
metrics = model.val()
|
||||
|
||||
# Perform object detection on an image
|
||||
results = model("path/to/image.jpg")
|
||||
results[0].show()
|
||||
|
||||
# Export the model to ONNX format
|
||||
path = model.export(format="onnx") # return path to exported model
|
||||
```
|
||||
|
||||
See YOLO [Python Docs](https://docs.ultralytics.com/usage/python/) for more examples.
|
||||
|
||||
</details>
|
||||
|
||||
## <div align="center">Models</div>
|
||||
|
||||
YOLO11 [Detect](https://docs.ultralytics.com/tasks/detect/), [Segment](https://docs.ultralytics.com/tasks/segment/) and [Pose](https://docs.ultralytics.com/tasks/pose/) models pretrained on the [COCO](https://docs.ultralytics.com/datasets/detect/coco/) dataset are available here, as well as YOLO11 [Classify](https://docs.ultralytics.com/tasks/classify/) models pretrained on the [ImageNet](https://docs.ultralytics.com/datasets/classify/imagenet/) dataset. [Track](https://docs.ultralytics.com/modes/track/) mode is available for all Detect, Segment and Pose models. All [Models](https://docs.ultralytics.com/models/) download automatically from the latest Ultralytics [release](https://github.com/ultralytics/assets/releases) on first use.
|
||||
|
||||
<a href="https://docs.ultralytics.com/tasks/" target="_blank">
|
||||
<img width="100%" src="https://github.com/ultralytics/docs/releases/download/0/ultralytics-yolov8-tasks-banner.avif" alt="Ultralytics YOLO supported tasks">
|
||||
</a>
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<details open><summary>Detection (COCO)</summary>
|
||||
|
||||
See [Detection Docs](https://docs.ultralytics.com/tasks/detect/) for usage examples with these models trained on [COCO](https://docs.ultralytics.com/datasets/detect/coco/), which include 80 pre-trained classes.
|
||||
|
||||
| Model | size<br><sup>(pixels) | mAP<sup>val<br>50-95 | Speed<br><sup>CPU ONNX<br>(ms) | Speed<br><sup>T4 TensorRT10<br>(ms) | params<br><sup>(M) | FLOPs<br><sup>(B) |
|
||||
| ------------------------------------------------------------------------------------ | --------------------- | -------------------- | ------------------------------ | ----------------------------------- | ------------------ | ----------------- |
|
||||
| [YOLO11n](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.pt) | 640 | 39.5 | 56.1 ± 0.8 | 1.5 ± 0.0 | 2.6 | 6.5 |
|
||||
| [YOLO11s](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s.pt) | 640 | 47.0 | 90.0 ± 1.2 | 2.5 ± 0.0 | 9.4 | 21.5 |
|
||||
| [YOLO11m](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11m.pt) | 640 | 51.5 | 183.2 ± 2.0 | 4.7 ± 0.1 | 20.1 | 68.0 |
|
||||
| [YOLO11l](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l.pt) | 640 | 53.4 | 238.6 ± 1.4 | 6.2 ± 0.1 | 25.3 | 86.9 |
|
||||
| [YOLO11x](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x.pt) | 640 | 54.7 | 462.8 ± 6.7 | 11.3 ± 0.2 | 56.9 | 194.9 |
|
||||
|
||||
- **mAP<sup>val</sup>** values are for single-model single-scale on [COCO val2017](https://cocodataset.org/) dataset. <br>Reproduce by `yolo val detect data=coco.yaml device=0`
|
||||
- **Speed** averaged over COCO val images using an [Amazon EC2 P4d](https://aws.amazon.com/ec2/instance-types/p4/) instance. <br>Reproduce by `yolo val detect data=coco.yaml batch=1 device=0|cpu`
|
||||
|
||||
</details>
|
||||
|
||||
<details><summary>Segmentation (COCO)</summary>
|
||||
|
||||
See [Segmentation Docs](https://docs.ultralytics.com/tasks/segment/) for usage examples with these models trained on [COCO-Seg](https://docs.ultralytics.com/datasets/segment/coco/), which include 80 pre-trained classes.
|
||||
|
||||
| Model | size<br><sup>(pixels) | mAP<sup>box<br>50-95 | mAP<sup>mask<br>50-95 | Speed<br><sup>CPU ONNX<br>(ms) | Speed<br><sup>T4 TensorRT10<br>(ms) | params<br><sup>(M) | FLOPs<br><sup>(B) |
|
||||
| -------------------------------------------------------------------------------------------- | --------------------- | -------------------- | --------------------- | ------------------------------ | ----------------------------------- | ------------------ | ----------------- |
|
||||
| [YOLO11n-seg](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n-seg.pt) | 640 | 38.9 | 32.0 | 65.9 ± 1.1 | 1.8 ± 0.0 | 2.9 | 10.4 |
|
||||
| [YOLO11s-seg](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s-seg.pt) | 640 | 46.6 | 37.8 | 117.6 ± 4.9 | 2.9 ± 0.0 | 10.1 | 35.5 |
|
||||
| [YOLO11m-seg](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11m-seg.pt) | 640 | 51.5 | 41.5 | 281.6 ± 1.2 | 6.3 ± 0.1 | 22.4 | 123.3 |
|
||||
| [YOLO11l-seg](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l-seg.pt) | 640 | 53.4 | 42.9 | 344.2 ± 3.2 | 7.8 ± 0.2 | 27.6 | 142.2 |
|
||||
| [YOLO11x-seg](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x-seg.pt) | 640 | 54.7 | 43.8 | 664.5 ± 3.2 | 15.8 ± 0.7 | 62.1 | 319.0 |
|
||||
|
||||
- **mAP<sup>val</sup>** values are for single-model single-scale on [COCO val2017](https://cocodataset.org/) dataset. <br>Reproduce by `yolo val segment data=coco.yaml device=0`
|
||||
- **Speed** averaged over COCO val images using an [Amazon EC2 P4d](https://aws.amazon.com/ec2/instance-types/p4/) instance. <br>Reproduce by `yolo val segment data=coco.yaml batch=1 device=0|cpu`
|
||||
|
||||
</details>
|
||||
|
||||
<details><summary>Classification (ImageNet)</summary>
|
||||
|
||||
See [Classification Docs](https://docs.ultralytics.com/tasks/classify/) for usage examples with these models trained on [ImageNet](https://docs.ultralytics.com/datasets/classify/imagenet/), which include 1000 pretrained classes.
|
||||
|
||||
| Model | size<br><sup>(pixels) | acc<br><sup>top1 | acc<br><sup>top5 | Speed<br><sup>CPU ONNX<br>(ms) | Speed<br><sup>T4 TensorRT10<br>(ms) | params<br><sup>(M) | FLOPs<br><sup>(B) at 640 |
|
||||
| -------------------------------------------------------------------------------------------- | --------------------- | ---------------- | ---------------- | ------------------------------ | ----------------------------------- | ------------------ | ------------------------ |
|
||||
| [YOLO11n-cls](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n-cls.pt) | 224 | 70.0 | 89.4 | 5.0 ± 0.3 | 1.1 ± 0.0 | 1.6 | 3.3 |
|
||||
| [YOLO11s-cls](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s-cls.pt) | 224 | 75.4 | 92.7 | 7.9 ± 0.2 | 1.3 ± 0.0 | 5.5 | 12.1 |
|
||||
| [YOLO11m-cls](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11m-cls.pt) | 224 | 77.3 | 93.9 | 17.2 ± 0.4 | 2.0 ± 0.0 | 10.4 | 39.3 |
|
||||
| [YOLO11l-cls](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l-cls.pt) | 224 | 78.3 | 94.3 | 23.2 ± 0.3 | 2.8 ± 0.0 | 12.9 | 49.4 |
|
||||
| [YOLO11x-cls](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x-cls.pt) | 224 | 79.5 | 94.9 | 41.4 ± 0.9 | 3.8 ± 0.0 | 28.4 | 110.4 |
|
||||
|
||||
- **acc** values are model accuracies on the [ImageNet](https://www.image-net.org/) dataset validation set. <br>Reproduce by `yolo val classify data=path/to/ImageNet device=0`
|
||||
- **Speed** averaged over ImageNet val images using an [Amazon EC2 P4d](https://aws.amazon.com/ec2/instance-types/p4/) instance. <br>Reproduce by `yolo val classify data=path/to/ImageNet batch=1 device=0|cpu`
|
||||
|
||||
</details>
|
||||
|
||||
<details><summary>Pose (COCO)</summary>
|
||||
|
||||
See [Pose Docs](https://docs.ultralytics.com/tasks/pose/) for usage examples with these models trained on [COCO-Pose](https://docs.ultralytics.com/datasets/pose/coco/), which include 1 pre-trained class, person.
|
||||
|
||||
| Model | size<br><sup>(pixels) | mAP<sup>pose<br>50-95 | mAP<sup>pose<br>50 | Speed<br><sup>CPU ONNX<br>(ms) | Speed<br><sup>T4 TensorRT10<br>(ms) | params<br><sup>(M) | FLOPs<br><sup>(B) |
|
||||
| ---------------------------------------------------------------------------------------------- | --------------------- | --------------------- | ------------------ | ------------------------------ | ----------------------------------- | ------------------ | ----------------- |
|
||||
| [YOLO11n-pose](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n-pose.pt) | 640 | 50.0 | 81.0 | 52.4 ± 0.5 | 1.7 ± 0.0 | 2.9 | 7.6 |
|
||||
| [YOLO11s-pose](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s-pose.pt) | 640 | 58.9 | 86.3 | 90.5 ± 0.6 | 2.6 ± 0.0 | 9.9 | 23.2 |
|
||||
| [YOLO11m-pose](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11m-pose.pt) | 640 | 64.9 | 89.4 | 187.3 ± 0.8 | 4.9 ± 0.1 | 20.9 | 71.7 |
|
||||
| [YOLO11l-pose](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l-pose.pt) | 640 | 66.1 | 89.9 | 247.7 ± 1.1 | 6.4 ± 0.1 | 26.2 | 90.7 |
|
||||
| [YOLO11x-pose](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x-pose.pt) | 640 | 69.5 | 91.1 | 488.0 ± 13.9 | 12.1 ± 0.2 | 58.8 | 203.3 |
|
||||
|
||||
- **mAP<sup>val</sup>** values are for single-model single-scale on [COCO Keypoints val2017](https://cocodataset.org/) dataset. <br>Reproduce by `yolo val pose data=coco-pose.yaml device=0`
|
||||
- **Speed** averaged over COCO val images using an [Amazon EC2 P4d](https://aws.amazon.com/ec2/instance-types/p4/) instance. <br>Reproduce by `yolo val pose data=coco-pose.yaml batch=1 device=0|cpu`
|
||||
|
||||
</details>
|
||||
|
||||
<details><summary>OBB (DOTAv1)</summary>
|
||||
|
||||
See [OBB Docs](https://docs.ultralytics.com/tasks/obb/) for usage examples with these models trained on [DOTAv1](https://docs.ultralytics.com/datasets/obb/dota-v2/#dota-v10/), which include 15 pre-trained classes.
|
||||
|
||||
| Model | size<br><sup>(pixels) | mAP<sup>test<br>50 | Speed<br><sup>CPU ONNX<br>(ms) | Speed<br><sup>T4 TensorRT10<br>(ms) | params<br><sup>(M) | FLOPs<br><sup>(B) |
|
||||
| -------------------------------------------------------------------------------------------- | --------------------- | ------------------ | ------------------------------ | ----------------------------------- | ------------------ | ----------------- |
|
||||
| [YOLO11n-obb](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n-obb.pt) | 1024 | 78.4 | 117.6 ± 0.8 | 4.4 ± 0.0 | 2.7 | 17.2 |
|
||||
| [YOLO11s-obb](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s-obb.pt) | 1024 | 79.5 | 219.4 ± 4.0 | 5.1 ± 0.0 | 9.7 | 57.5 |
|
||||
| [YOLO11m-obb](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11m-obb.pt) | 1024 | 80.9 | 562.8 ± 2.9 | 10.1 ± 0.4 | 20.9 | 183.5 |
|
||||
| [YOLO11l-obb](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l-obb.pt) | 1024 | 81.0 | 712.5 ± 5.0 | 13.5 ± 0.6 | 26.2 | 232.0 |
|
||||
| [YOLO11x-obb](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x-obb.pt) | 1024 | 81.3 | 1408.6 ± 7.7 | 28.6 ± 1.0 | 58.8 | 520.2 |
|
||||
|
||||
- **mAP<sup>test</sup>** values are for single-model multiscale on [DOTAv1](https://captain-whu.github.io/DOTA/index.html) dataset. <br>Reproduce by `yolo val obb data=DOTAv1.yaml device=0 split=test` and submit merged results to [DOTA evaluation](https://captain-whu.github.io/DOTA/evaluation.html).
|
||||
- **Speed** averaged over DOTAv1 val images using an [Amazon EC2 P4d](https://aws.amazon.com/ec2/instance-types/p4/) instance. <br>Reproduce by `yolo val obb data=DOTAv1.yaml batch=1 device=0|cpu`
|
||||
|
||||
</details>
|
||||
|
||||
## <div align="center">Integrations</div>
|
||||
|
||||
Our key integrations with leading AI platforms extend the functionality of Ultralytics' offerings, enhancing tasks like dataset labeling, training, visualization, and model management. Discover how Ultralytics, in collaboration with [W&B](https://docs.wandb.ai/guides/integrations/ultralytics/), [Comet](https://bit.ly/yolov8-readme-comet), [Roboflow](https://roboflow.com/?ref=ultralytics) and [OpenVINO](https://docs.ultralytics.com/integrations/openvino/), can optimize your AI workflow.
|
||||
|
||||
<a href="https://www.ultralytics.com/hub" target="_blank">
|
||||
<img width="100%" src="https://github.com/ultralytics/assets/raw/main/yolov8/banner-integrations.png" alt="Ultralytics active learning integrations">
|
||||
</a>
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<div align="center">
|
||||
<a href="https://www.ultralytics.com/hub">
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/partners/logo-ultralytics-hub.png" width="10%" alt="Ultralytics HUB logo"></a>
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="15%" height="0" alt="space">
|
||||
<a href="https://docs.wandb.ai/guides/integrations/ultralytics/">
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/partners/logo-wb.png" width="10%" alt="ClearML logo"></a>
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="15%" height="0" alt="space">
|
||||
<a href="https://bit.ly/yolov8-readme-comet">
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/partners/logo-comet.png" width="10%" alt="Comet ML logo"></a>
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="15%" height="0" alt="space">
|
||||
<a href="https://bit.ly/yolov5-neuralmagic">
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/partners/logo-neuralmagic.png" width="10%" alt="NeuralMagic logo"></a>
|
||||
</div>
|
||||
|
||||
| Ultralytics HUB 🚀 | W&B | Comet ⭐ NEW | Neural Magic |
|
||||
| :--------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------: |
|
||||
| Streamline YOLO workflows: Label, train, and deploy effortlessly with [Ultralytics HUB](https://www.ultralytics.com/hub). Try now! | Track experiments, hyperparameters, and results with [Weights & Biases](https://docs.wandb.ai/guides/integrations/ultralytics/) | Free forever, [Comet](https://bit.ly/yolov5-readme-comet) lets you save YOLO11 models, resume training, and interactively visualize and debug predictions | Run YOLO11 inference up to 6x faster with [Neural Magic DeepSparse](https://bit.ly/yolov5-neuralmagic) |
|
||||
|
||||
## <div align="center">Ultralytics HUB</div>
|
||||
|
||||
Experience seamless AI with [Ultralytics HUB](https://www.ultralytics.com/hub) ⭐, the all-in-one solution for data visualization, YOLO11 🚀 model training and deployment, without any coding. Transform images into actionable insights and bring your AI visions to life with ease using our cutting-edge platform and user-friendly [Ultralytics App](https://www.ultralytics.com/app-install). Start your journey for **Free** now!
|
||||
|
||||
<a href="https://www.ultralytics.com/hub" target="_blank">
|
||||
<img width="100%" src="https://github.com/ultralytics/assets/raw/main/im/ultralytics-hub.png" alt="Ultralytics HUB preview image"></a>
|
||||
|
||||
## <div align="center">Contribute</div>
|
||||
|
||||
We love your input! Ultralytics YOLO 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://www.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!
|
||||
|
||||
<!-- SVG image from https://opencollective.com/ultralytics/contributors.svg?width=990 -->
|
||||
|
||||
<a href="https://github.com/ultralytics/ultralytics/graphs/contributors">
|
||||
<img width="100%" src="https://github.com/ultralytics/assets/raw/main/im/image-contributors.png" alt="Ultralytics open-source contributors"></a>
|
||||
|
||||
## <div align="center">License</div>
|
||||
|
||||
Ultralytics offers two licensing options to accommodate diverse use cases:
|
||||
|
||||
- **AGPL-3.0 License**: This [OSI-approved](https://opensource.org/license) open-source license is ideal for students and enthusiasts, promoting open collaboration and knowledge sharing. See the [LICENSE](https://github.com/ultralytics/ultralytics/blob/main/LICENSE) file for more details.
|
||||
- **Enterprise License**: Designed for commercial use, this license permits seamless integration of Ultralytics software and AI models into commercial goods and services, bypassing the open-source requirements of AGPL-3.0. If your scenario involves embedding our solutions into a commercial offering, reach out through [Ultralytics Licensing](https://www.ultralytics.com/license).
|
||||
|
||||
## <div align="center">Contact</div>
|
||||
|
||||
For Ultralytics bug reports and feature requests please visit [GitHub Issues](https://github.com/ultralytics/ultralytics/issues). Become a member of the Ultralytics [Discord](https://discord.com/invite/ultralytics), [Reddit](https://www.reddit.com/r/ultralytics/), or [Forums](https://community.ultralytics.com/) for asking questions, sharing projects, learning discussions, or for help with all things Ultralytics!
|
||||
|
||||
<br>
|
||||
<div align="center">
|
||||
<a href="https://github.com/ultralytics"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-github.png" width="3%" alt="Ultralytics GitHub"></a>
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
|
||||
<a href="https://www.linkedin.com/company/ultralytics/"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-linkedin.png" width="3%" alt="Ultralytics LinkedIn"></a>
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
|
||||
<a href="https://twitter.com/ultralytics"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-twitter.png" width="3%" alt="Ultralytics Twitter"></a>
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
|
||||
<a href="https://youtube.com/ultralytics?sub_confirmation=1"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-youtube.png" width="3%" alt="Ultralytics YouTube"></a>
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
|
||||
<a href="https://www.tiktok.com/@ultralytics"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-tiktok.png" width="3%" alt="Ultralytics TikTok"></a>
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
|
||||
<a href="https://ultralytics.com/bilibili"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-bilibili.png" width="3%" alt="Ultralytics BiliBili"></a>
|
||||
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
|
||||
<a href="https://discord.com/invite/ultralytics"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-discord.png" width="3%" alt="Ultralytics Discord"></a>
|
||||
</div>
|
95
json2txt.py
Normal file
95
json2txt.py
Normal file
@ -0,0 +1,95 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import json
|
||||
import os
|
||||
import argparse
|
||||
from tqdm import tqdm
|
||||
import chardet
|
||||
|
||||
# 預定義標籤類別與對應編號
|
||||
PREDEFINED_CLASSES = {
|
||||
"T7H": 0,
|
||||
"T8H": 1,
|
||||
"T10H": 2,
|
||||
"T15H": 3,
|
||||
"PH00": 4,
|
||||
"PH0": 5,
|
||||
"3/32": 6,
|
||||
"1/8": 7
|
||||
}
|
||||
|
||||
|
||||
def read_json_file(file_path):
|
||||
with open(file_path, "rb") as f:
|
||||
raw_data = f.read()
|
||||
detected_encoding = chardet.detect(raw_data)['encoding']
|
||||
with open(file_path, "r", encoding=detected_encoding, errors="ignore") as f:
|
||||
return json.load(f)
|
||||
|
||||
def convert_label_json(json_dir, save_dir, classes):
|
||||
json_paths = os.listdir(json_dir)
|
||||
os.makedirs(save_dir, exist_ok=True) # 確保目錄存在
|
||||
for json_path in tqdm(json_paths, desc="Converting JSON files"):
|
||||
json_path_full = os.path.join(json_dir, json_path)
|
||||
try:
|
||||
json_dict = read_json_file(json_path_full)
|
||||
h, w = json_dict['imageHeight'], json_dict['imageWidth']
|
||||
except (KeyError, json.JSONDecodeError) as e:
|
||||
print(f"Error reading file '{json_path}': {e}")
|
||||
continue
|
||||
|
||||
# Save txt path
|
||||
txt_path = os.path.join(save_dir, json_path.replace('.json', '.txt'))
|
||||
os.makedirs(os.path.dirname(txt_path), exist_ok=True)
|
||||
with open(txt_path, 'w') as txt_file:
|
||||
for shape_dict in json_dict['shapes']:
|
||||
try:
|
||||
label = shape_dict['label']
|
||||
label_index = classes.get(label, None) # 查找標籤對應的編號
|
||||
if label_index is None:
|
||||
print(f"Label '{label}' not in predefined classes.")
|
||||
continue
|
||||
points = shape_dict['points']
|
||||
except ValueError as e:
|
||||
print(f"Error processing shape in file '{json_path}': {e}")
|
||||
continue
|
||||
|
||||
points_nor_list = []
|
||||
for point in points:
|
||||
points_nor_list.append(point[0] / w)
|
||||
points_nor_list.append(point[1] / h)
|
||||
|
||||
points_nor_list = list(map(lambda x: str(x), points_nor_list))
|
||||
points_nor_str = ' '.join(points_nor_list)
|
||||
|
||||
label_str = str(label_index) + ' ' + points_nor_str + '\n'
|
||||
txt_file.writelines(label_str)
|
||||
|
||||
def extract_labels(json_dir):
|
||||
labels = set()
|
||||
json_paths = os.listdir(json_dir)
|
||||
print(f"Found {len(json_paths)} JSON files to process.")
|
||||
for json_path in json_paths:
|
||||
json_path_full = os.path.join(json_dir, json_path)
|
||||
try:
|
||||
json_dict = read_json_file(json_path_full)
|
||||
for shape_dict in json_dict['shapes']:
|
||||
labels.add(shape_dict['label'])
|
||||
except (KeyError, json.JSONDecodeError) as e:
|
||||
print(f"Error reading file '{json_path}': {e}")
|
||||
print(f"Extracted labels: {labels}")
|
||||
return list(labels)
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description='json convert to txt params')
|
||||
parser.add_argument('--json-dir', type=str, default='E:/code/image_segmentation/labelme_json_dir/', help='json path dir')
|
||||
parser.add_argument('--save-dir', type=str, default='E:/code/image_segmentation/labelme_txt_dir/', help='txt save dir')
|
||||
args = parser.parse_args()
|
||||
|
||||
json_dir = args.json_dir
|
||||
save_dir = args.save_dir
|
||||
|
||||
# 使用預定義類別
|
||||
predefined_classes = PREDEFINED_CLASSES
|
||||
|
||||
# 進行轉換
|
||||
convert_label_json(json_dir, save_dir, predefined_classes)
|
32
predict.py
Normal file
32
predict.py
Normal file
@ -0,0 +1,32 @@
|
||||
from ultralytics import YOLO
|
||||
from tkinter import Tk, filedialog
|
||||
|
||||
# 載入模型
|
||||
model = YOLO('E:/code/image_segmentation/runs/segment/train14/weights/best.pt')
|
||||
|
||||
# 使用 tkinter 開啟檔案選擇對話框
|
||||
def select_files():
|
||||
root = Tk()
|
||||
root.withdraw() # 隱藏主視窗
|
||||
file_paths = filedialog.askopenfilenames(
|
||||
title="Select Images",
|
||||
filetypes=[("Image files", "*.bmp;*.png;*.jpg;*.jpeg")]
|
||||
)
|
||||
return file_paths
|
||||
|
||||
# 選擇影像檔案
|
||||
image_paths = select_files()
|
||||
if not image_paths:
|
||||
print("No files selected.")
|
||||
else:
|
||||
# 執行推論
|
||||
for image_path in image_paths:
|
||||
results = model(
|
||||
source=image_path, # 輸入圖片路徑
|
||||
save=True, # 儲存推論結果
|
||||
device='0', # 使用 GPU 若發生錯誤改成CPU
|
||||
# max_det=8, # 每個類別只保留一個檢測結果
|
||||
# iou=0.1, # 降低 IOU 閾值,進一步減少重複檢測
|
||||
# conf=0.7 # 可以根據需要調整置信度閾值
|
||||
)
|
||||
print("Inference completed!")
|
66
predict_mask.py
Normal file
66
predict_mask.py
Normal file
@ -0,0 +1,66 @@
|
||||
from ultralytics import YOLO
|
||||
import os
|
||||
from tkinter import Tk, filedialog
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
# 載入模型
|
||||
model = YOLO('E:/code/image_segmentation/runs/segment/train14/weights/best.pt')
|
||||
|
||||
# 使用 tkinter 開啟檔案選擇對話框
|
||||
def select_files():
|
||||
root = Tk()
|
||||
root.withdraw() # 隱藏主視窗
|
||||
file_paths = filedialog.askopenfilenames(
|
||||
title="Select Images",
|
||||
filetypes=[("Image files", "*.bmp;*.png;*.jpg;*.jpeg")]
|
||||
)
|
||||
return file_paths
|
||||
|
||||
# 選擇影像檔案
|
||||
image_paths = select_files()
|
||||
if not image_paths:
|
||||
print("No files selected.")
|
||||
else:
|
||||
# 執行推論
|
||||
for image_path in image_paths:
|
||||
# 推論
|
||||
results = model(
|
||||
source=image_path,
|
||||
device='0', # 使用 GPU 若發生錯誤改成CPU
|
||||
max_det=8,
|
||||
iou=0.1,
|
||||
conf=0.7
|
||||
)
|
||||
|
||||
# 取得圖片名稱和目錄
|
||||
img_name = os.path.basename(image_path)
|
||||
output_dir = os.path.join(os.path.dirname(image_path), "segmented_results")
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
|
||||
# 處理每張圖片的結果
|
||||
for result in results:
|
||||
original_image = result.orig_img
|
||||
masks = result.masks.data.cpu().numpy() if result.masks else None
|
||||
|
||||
if masks is not None:
|
||||
# 初始化遮罩影像
|
||||
mask_image = np.zeros_like(original_image)
|
||||
|
||||
for mask in masks:
|
||||
mask = mask.astype(np.uint8) * 255
|
||||
|
||||
# 調整遮罩大小與原始影像一致
|
||||
mask_resized = cv2.resize(mask, (original_image.shape[1], original_image.shape[0]))
|
||||
|
||||
# 將單通道遮罩轉換為三通道
|
||||
mask_colored = cv2.merge([mask_resized, mask_resized, mask_resized])
|
||||
|
||||
# 疊加遮罩到影像
|
||||
mask_image = cv2.addWeighted(mask_image, 1, mask_colored, 1, 0)
|
||||
|
||||
# 保存結果
|
||||
output_path = os.path.join(output_dir, f"segmented_{img_name}")
|
||||
cv2.imwrite(output_path, mask_image)
|
||||
print(f"Saved segmented result to: {output_path}")
|
||||
print("Inference completed!")
|
187
pyproject.toml
Normal file
187
pyproject.toml
Normal file
@ -0,0 +1,187 @@
|
||||
# Ultralytics YOLO 🚀, AGPL-3.0 license
|
||||
|
||||
# Overview:
|
||||
# This pyproject.toml file manages the build, packaging, and distribution of the Ultralytics library.
|
||||
# It defines essential project metadata, dependencies, and settings used to develop and deploy the library.
|
||||
|
||||
# Key Sections:
|
||||
# - [build-system]: Specifies the build requirements and backend (e.g., setuptools, wheel).
|
||||
# - [project]: Includes details like name, version, description, authors, dependencies and more.
|
||||
# - [project.optional-dependencies]: Provides additional, optional packages for extended features.
|
||||
# - [tool.*]: Configures settings for various tools (pytest, yapf, etc.) used in the project.
|
||||
|
||||
# Installation:
|
||||
# The Ultralytics library can be installed using the command: 'pip install ultralytics'
|
||||
# For development purposes, you can install the package in editable mode with: 'pip install -e .'
|
||||
# This approach allows for real-time code modifications without the need for re-installation.
|
||||
|
||||
# Documentation:
|
||||
# For comprehensive documentation and usage instructions, visit: https://docs.ultralytics.com
|
||||
|
||||
[build-system]
|
||||
requires = ["setuptools>=70.0.0", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
# Project settings -----------------------------------------------------------------------------------------------------
|
||||
[project]
|
||||
name = "ultralytics"
|
||||
dynamic = ["version"]
|
||||
description = "Ultralytics YOLO 🚀 for SOTA object detection, multi-object tracking, instance segmentation, pose estimation and image classification."
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.8"
|
||||
license = { "text" = "AGPL-3.0" }
|
||||
keywords = ["machine-learning", "deep-learning", "computer-vision", "ML", "DL", "AI", "YOLO", "YOLOv3", "YOLOv5", "YOLOv8", "YOLOv9", "YOLOv10", "YOLO11", "HUB", "Ultralytics"]
|
||||
authors = [
|
||||
{ name = "Glenn Jocher", email = "glenn.jocher@ultralytics.com" },
|
||||
{ name = "Jing Qiu", email = "jing.qiu@ultralytics.com" },
|
||||
]
|
||||
maintainers = [
|
||||
{ name = "Ultralytics", email = "hello@ultralytics.com" },
|
||||
]
|
||||
classifiers = [
|
||||
"Development Status :: 4 - Beta",
|
||||
"Intended Audience :: Developers",
|
||||
"Intended Audience :: Education",
|
||||
"Intended Audience :: Science/Research",
|
||||
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Programming Language :: Python :: 3.11",
|
||||
"Programming Language :: Python :: 3.12",
|
||||
"Topic :: Software Development",
|
||||
"Topic :: Scientific/Engineering",
|
||||
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
||||
"Topic :: Scientific/Engineering :: Image Recognition",
|
||||
"Operating System :: POSIX :: Linux",
|
||||
"Operating System :: MacOS",
|
||||
"Operating System :: Microsoft :: Windows",
|
||||
]
|
||||
|
||||
# Required dependencies ------------------------------------------------------------------------------------------------
|
||||
dependencies = [
|
||||
"numpy>=1.23.0",
|
||||
"numpy<2.0.0; sys_platform == 'darwin'", # macOS OpenVINO errors https://github.com/ultralytics/ultralytics/pull/17221
|
||||
"matplotlib>=3.3.0",
|
||||
"opencv-python>=4.6.0",
|
||||
"pillow>=7.1.2",
|
||||
"pyyaml>=5.3.1",
|
||||
"requests>=2.23.0",
|
||||
"scipy>=1.4.1",
|
||||
"torch>=1.8.0",
|
||||
"torch>=1.8.0,!=2.4.0; sys_platform == 'win32'", # Windows CPU errors w/ 2.4.0 https://github.com/ultralytics/ultralytics/issues/15049
|
||||
"torchvision>=0.9.0",
|
||||
"tqdm>=4.64.0", # progress bars
|
||||
"psutil", # system utilization
|
||||
"py-cpuinfo", # display CPU info
|
||||
"pandas>=1.1.4",
|
||||
"seaborn>=0.11.0", # plotting
|
||||
"ultralytics-thop>=2.0.0", # FLOPs computation https://github.com/ultralytics/thop
|
||||
]
|
||||
|
||||
# Optional dependencies ------------------------------------------------------------------------------------------------
|
||||
[project.optional-dependencies]
|
||||
dev = [
|
||||
"ipython",
|
||||
"pytest",
|
||||
"pytest-cov",
|
||||
"coverage[toml]",
|
||||
"mkdocs>=1.6.0",
|
||||
"mkdocs-material>=9.5.9",
|
||||
"mkdocstrings[python]",
|
||||
"mkdocs-jupyter", # notebooks
|
||||
"mkdocs-redirects", # 301 redirects
|
||||
"mkdocs-ultralytics-plugin>=0.1.8", # for meta descriptions and images, dates and authors
|
||||
"mkdocs-macros-plugin>=1.0.5" # duplicating content (i.e. export tables) in multiple places
|
||||
]
|
||||
export = [
|
||||
"onnx>=1.12.0", # ONNX export
|
||||
"coremltools>=7.0; platform_system != 'Windows' and python_version <= '3.11'", # CoreML supported on macOS and Linux
|
||||
"scikit-learn>=1.3.2; platform_system != 'Windows' and python_version <= '3.11'", # CoreML k-means quantization
|
||||
"openvino>=2024.0.0", # OpenVINO export
|
||||
"tensorflow>=2.0.0", # TF bug https://github.com/ultralytics/ultralytics/issues/5161
|
||||
"tensorflowjs>=3.9.0", # TF.js export, automatically installs tensorflow
|
||||
"tensorstore>=0.1.63; platform_machine == 'aarch64' and python_version >= '3.9'", # for TF Raspberry Pi exports
|
||||
"keras", # not installed automatically by tensorflow>=2.16
|
||||
"flatbuffers>=23.5.26,<100; platform_machine == 'aarch64'", # update old 'flatbuffers' included inside tensorflow package
|
||||
"numpy==1.23.5; platform_machine == 'aarch64'", # fix error: `np.bool` was a deprecated alias for the builtin `bool` when using TensorRT models on NVIDIA Jetson
|
||||
"h5py!=3.11.0; platform_machine == 'aarch64'", # fix h5py build issues due to missing aarch64 wheels in 3.11 release
|
||||
]
|
||||
solutions = [
|
||||
"shapely>=2.0.0", # shapely for point and polygon data matching
|
||||
"streamlit", # for live inference on web browser i.e `yolo streamlit-predict`
|
||||
]
|
||||
logging = [
|
||||
"comet", # https://docs.ultralytics.com/integrations/comet/
|
||||
"tensorboard>=2.13.0",
|
||||
"dvclive>=2.12.0",
|
||||
]
|
||||
extra = [
|
||||
"hub-sdk>=0.0.12", # Ultralytics HUB
|
||||
"ipython", # interactive notebook
|
||||
"albumentations>=1.4.6", # training augmentations
|
||||
"pycocotools>=2.0.7", # COCO mAP
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
"Homepage" = "https://ultralytics.com"
|
||||
"Source" = "https://github.com/ultralytics/ultralytics"
|
||||
"Documentation" = "https://docs.ultralytics.com"
|
||||
"Bug Reports" = "https://github.com/ultralytics/ultralytics/issues"
|
||||
"Changelog" = "https://github.com/ultralytics/ultralytics/releases"
|
||||
|
||||
[project.scripts]
|
||||
yolo = "ultralytics.cfg:entrypoint"
|
||||
ultralytics = "ultralytics.cfg:entrypoint"
|
||||
|
||||
# Tools settings -------------------------------------------------------------------------------------------------------
|
||||
[tool.setuptools] # configuration specific to the `setuptools` build backend.
|
||||
packages = { find = { where = ["."], include = ["ultralytics", "ultralytics.*"] } }
|
||||
package-data = { "ultralytics" = ["**/*.yaml", "../tests/*.py"], "ultralytics.assets" = ["*.jpg"] }
|
||||
|
||||
[tool.setuptools.dynamic]
|
||||
version = { attr = "ultralytics.__version__" }
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
addopts = "--doctest-modules --durations=30 --color=yes"
|
||||
markers = [
|
||||
"slow: skip slow tests unless --slow is set",
|
||||
]
|
||||
norecursedirs = [".git", "dist", "build"]
|
||||
|
||||
[tool.coverage.run]
|
||||
source = ["ultralytics/"]
|
||||
data_file = "tests/.coverage"
|
||||
omit = ["ultralytics/utils/callbacks/*"]
|
||||
|
||||
[tool.isort]
|
||||
line_length = 120
|
||||
multi_line_output = 0
|
||||
|
||||
[tool.yapf]
|
||||
based_on_style = "pep8"
|
||||
spaces_before_comment = 2
|
||||
column_limit = 120
|
||||
coalesce_brackets = true
|
||||
spaces_around_power_operator = true
|
||||
space_between_ending_comma_and_closing_bracket = true
|
||||
split_before_closing_bracket = false
|
||||
split_before_first_argument = false
|
||||
|
||||
[tool.ruff]
|
||||
line-length = 120
|
||||
|
||||
[tool.ruff.format]
|
||||
docstring-code-format = true
|
||||
|
||||
[tool.docformatter]
|
||||
wrap-summaries = 120
|
||||
wrap-descriptions = 120
|
||||
pre-summary-newline = true
|
||||
close-quotes-on-newline = true
|
||||
in-place = true
|
||||
|
||||
[tool.codespell]
|
||||
ignore-words-list = "crate,nd,ned,strack,dota,ane,segway,fo,gool,winn,commend,bloc,nam,afterall"
|
||||
skip = '*.pt,*.pth,*.torchscript,*.onnx,*.tflite,*.pb,*.bin,*.param,*.mlmodel,*.engine,*.npy,*.data*,*.csv,*pnnx*,*venv*,*translat*,__pycache__*,*.ico,*.jpg,*.png,*.mp4,*.mov,/runs,/.git,./docs/??/*.md,./docs/mkdocs_??.yml'
|
49
rotate_image.py
Normal file
49
rotate_image.py
Normal file
@ -0,0 +1,49 @@
|
||||
import cv2
|
||||
import os
|
||||
|
||||
|
||||
def rotate_image(image, angle):
|
||||
"""Rotate an image by a specific angle."""
|
||||
(h, w) = image.shape[:2]
|
||||
center = (w // 2, h // 2)
|
||||
M = cv2.getRotationMatrix2D(center, angle, 1.0)
|
||||
rotated = cv2.warpAffine(image, M, (w, h))
|
||||
return rotated
|
||||
|
||||
|
||||
def main():
|
||||
folder_path = r"E:\code\image_segmentation\pic"
|
||||
start_idx = 101 # Start index for naming rotated images
|
||||
|
||||
# Ensure the folder exists
|
||||
if not os.path.exists(folder_path):
|
||||
print(f"Folder '{folder_path}' does not exist.")
|
||||
return
|
||||
|
||||
for filename in os.listdir(folder_path):
|
||||
if filename.endswith(".bmp"):
|
||||
base_name = os.path.splitext(filename)[0]
|
||||
try:
|
||||
image_idx = int(base_name) # Convert filename to an integer
|
||||
except ValueError:
|
||||
print(f"Skipping invalid filename: {filename}")
|
||||
continue
|
||||
|
||||
# Load the image
|
||||
file_path = os.path.join(folder_path, filename)
|
||||
image = cv2.imread(file_path)
|
||||
if image is None:
|
||||
print(f"Failed to read image: {file_path}")
|
||||
continue
|
||||
|
||||
# Rotate and save images
|
||||
for angle, offset in zip([90, 180, 270], [100, 200, 300]):
|
||||
rotated_image = rotate_image(image, angle)
|
||||
new_name = f"{image_idx + offset}.bmp"
|
||||
new_path = os.path.join(folder_path, new_name)
|
||||
cv2.imwrite(new_path, rotated_image)
|
||||
print(f"Saved rotated image: {new_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
73
split_data.py
Normal file
73
split_data.py
Normal file
@ -0,0 +1,73 @@
|
||||
import os
|
||||
import shutil
|
||||
import random
|
||||
|
||||
# 設定資料夾路徑
|
||||
image_dir = r"E:\code\image_segmentation\pic"
|
||||
label_dir = r"E:\code\image_segmentation\labelme_txt_dir"
|
||||
output_dir = r"E:\code\image_segmentation\YOLODataset"
|
||||
|
||||
# 設定輸出子資料夾
|
||||
image_output_dir = os.path.join(output_dir, "images")
|
||||
label_output_dir = os.path.join(output_dir, "labels")
|
||||
subsets = ["train", "test", "val"]
|
||||
|
||||
# 清空輸出資料夾
|
||||
for subset in subsets:
|
||||
image_subset_dir = os.path.join(image_output_dir, subset)
|
||||
label_subset_dir = os.path.join(label_output_dir, subset)
|
||||
|
||||
# 若資料夾存在,則清空
|
||||
if os.path.exists(image_subset_dir):
|
||||
shutil.rmtree(image_subset_dir)
|
||||
if os.path.exists(label_subset_dir):
|
||||
shutil.rmtree(label_subset_dir)
|
||||
|
||||
# 重新建立空資料夾
|
||||
os.makedirs(image_subset_dir, exist_ok=True)
|
||||
os.makedirs(label_subset_dir, exist_ok=True)
|
||||
|
||||
# 設定比例
|
||||
train_ratio = 0.8
|
||||
test_ratio = 0.1
|
||||
val_ratio = 0.1
|
||||
|
||||
# 獲取所有影像檔案名稱
|
||||
image_files = [f for f in os.listdir(image_dir) if f.endswith((".jpg", ".png", ".bmp"))]
|
||||
|
||||
# 確保每個影像都有對應的標籤檔
|
||||
image_files = [f for f in image_files if os.path.exists(os.path.join(label_dir, f.replace(".bmp", ".txt").replace(".jpg", ".txt").replace(".png", ".txt")))]
|
||||
|
||||
# 隨機打亂影像檔案列表
|
||||
random.shuffle(image_files)
|
||||
|
||||
# 計算分配數量
|
||||
total_files = len(image_files)
|
||||
train_count = int(total_files * train_ratio)
|
||||
test_count = int(total_files * test_ratio)
|
||||
val_count = total_files - train_count - test_count # 剩下的分到 val
|
||||
|
||||
# 分配影像到子集
|
||||
train_files = image_files[:train_count]
|
||||
test_files = image_files[train_count:train_count + test_count]
|
||||
val_files = image_files[train_count + test_count:]
|
||||
|
||||
# 定義一個函式來處理檔案複製
|
||||
def copy_files(files, subset):
|
||||
for file in files:
|
||||
# 複製影像檔案
|
||||
image_src = os.path.join(image_dir, file)
|
||||
image_dest = os.path.join(image_output_dir, subset, file)
|
||||
shutil.copy(image_src, image_dest)
|
||||
|
||||
# 複製對應的標籤檔案
|
||||
label_src = os.path.join(label_dir, file.replace(".bmp", ".txt").replace(".jpg", ".txt").replace(".png", ".txt"))
|
||||
label_dest = os.path.join(label_output_dir, subset, file.replace(".bmp", ".txt").replace(".jpg", ".txt").replace(".png", ".txt"))
|
||||
shutil.copy(label_src, label_dest)
|
||||
|
||||
# 執行檔案複製
|
||||
copy_files(train_files, "train")
|
||||
copy_files(test_files, "test")
|
||||
copy_files(val_files, "val")
|
||||
|
||||
print("Dataset split completed! Existing files in the output directory were cleared.")
|
Loading…
Reference in New Issue
Block a user