Link to this sectionUltralyticsのインストール#
Ultralyticsでは、pip、conda、Dockerなど、さまざまなインストール方法を提供しています。YOLOは、最新の安定版であればultralytics pipパッケージ経由でインストールでき、最新バージョンが必要な場合はUltralytics GitHubリポジトリをクローンすることでインストール可能です。Dockerを利用すれば、パッケージを隔離されたコンテナ内で実行でき、ローカル環境へのインストールを避けることができます。
Watch: Ultralytics YOLO Quick Start Guide
Install or update the ultralytics package using pip by running pip install -U ultralytics. For more details on the ultralytics package, visit the Python Package Index (PyPI).
# Install or upgrade the ultralytics package from PyPI
pip install -U ultralyticsultralyticsはUltralytics GitHubリポジトリから直接インストールすることも可能です。最新の開発バージョンを使用したい場合に便利です。Gitコマンドラインツールがインストールされていることを確認してから、以下のコマンドを実行してください。
# Install the ultralytics package from GitHub
pip install git+https://github.com/ultralytics/ultralytics.git@main依存関係のリストについては、ultralyticsのpyproject.tomlファイルを参照してください。上記のすべての例で、必要なすべての依存関係がインストールされます。
Link to this sectionヘッドレスサーバーへのインストール#
For server environments without a display (e.g., cloud VMs, Docker containers, CI/CD pipelines), use the ultralytics-opencv-headless package. This is identical to the standard ultralytics package but depends on opencv-python-headless instead of opencv-python, avoiding unnecessary GUI dependencies and potential libGL errors.
pip install ultralytics-opencv-headlessどちらのパッケージも同じ機能とAPIを提供します。ヘッドレス版は、ディスプレイライブラリを必要とするOpenCVのGUIコンポーネントを除外しているだけです。
Link to this section高度なインストール#
標準的なインストール方法でほとんどのユースケースをカバーできますが、開発やカスタム構成のために、より調整されたセットアップが必要になる場合があります。
永続的なカスタム変更が必要な場合は、Ultralyticsリポジトリをフォークし、pyproject.tomlやその他のコードを変更して、そのフォークからインストールすることができます。
- フォーク: Ultralytics GitHubリポジトリを自身のGitHubアカウントにフォークします。
- クローン: フォークしたリポジトリをローカルにクローンします。
git clone https://github.com/YOUR_USERNAME/ultralytics.git cd ultralytics - ブランチ作成: 変更のために新しいブランチを作成します。
git checkout -b my-custom-branch - 修正: 必要に応じて
pyproject.tomlやその他のファイルを修正します。 - コミットとプッシュ: 変更をコミットしてプッシュします。
git add . git commit -m "My custom changes" git push origin my-custom-branch - インストール:
git+https構文を使用して、ブランチを指定し、pip経由でインストールします。pip install git+https://github.com/YOUR_USERNAME/ultralytics.git@my-custom-branch
Link to this sectionCLIでUltralyticsを使用する#
Ultralyticsコマンドラインインターフェース(CLI)を使用すると、Python環境を必要とせず、シンプルなワンラインコマンドで操作できます。CLIはカスタマイズやPythonコードを必要としません。yoloコマンドを使用して、ターミナルからすべてのタスクを実行できます。コマンドラインでのYOLOの利用方法については、CLIガイドをご覧ください。
Ultralyticsのyoloコマンドは以下の構文を使用します。
yolo TASK MODE ARGSTASK(オプション)は(detect, segment, semantic, classify, pose, obb)のいずれかです。MODE(必須)は(train, val, predict, export, track, benchmark)のいずれかです。ARGS(optional) arearg=valuepairs likeimgsz=640that override defaults.
すべてのARGSについては、完全な構成ガイドを参照するか、yolo cfg CLIコマンドを使用してください。
引数はarg=valueのペアで渡し、等号=で分割し、スペースで区切る必要があります。引数のプレフィックスに--を使用したり、引数の間にカンマ,を使用したりしないでください。
yolo predict model=yolo26n.pt imgsz=640 conf=0.25✅yolo predict model yolo26n.pt imgsz 640 conf 0.25❌ (=がありません)yolo predict model=yolo26n.pt, imgsz=640, conf=0.25❌ (,を使用しないでください)yolo predict --model yolo26n.pt --imgsz 640 --conf 0.25❌ (--を使用しないでください)yolo solution model=yolo26n.pt imgsz=640 conf=0.25❌ (usesolutions, notsolution)
Link to this sectionPythonでUltralyticsを使用する#
Ultralytics YOLO Pythonインターフェースは、Pythonプロジェクトへのシームレスな統合を提供し、モデルのロード、実行、出力の処理を容易にします。シンプルさを追求した設計のPythonインターフェースにより、ユーザーは物体検出、インスタンスセグメンテーション、セマンティックセグメンテーション、分類を迅速に実装できます。これにより、YOLO Pythonインターフェースは、これらの機能をPythonプロジェクトに組み込むための非常に貴重なツールとなります。
例えば、わずか数行のコードで、モデルのロード、学習、パフォーマンスの評価、ONNX形式へのエクスポートが可能です。Pythonプロジェクト内でのYOLOの使用方法について詳しくは、Pythonガイドをご覧ください。
from ultralytics import YOLO
# Create a new YOLO model from scratch
model = YOLO("yolo26n.yaml")
# Load a pretrained YOLO model (recommended for training)
model = YOLO("yolo26n.pt")
# Train the model using the 'coco8.yaml' dataset for 3 epochs
results = model.train(data="coco8.yaml", epochs=3)
# Evaluate the model's performance on the validation set
results = model.val()
# Perform object detection on an image using the model
results = model("https://ultralytics.com/images/bus.jpg")
# Export the model to ONNX format
success = model.export(format="onnx")Link to this sectionUltralyticsの設定#
Ultralyticsライブラリには、実験をきめ細かく制御するためのSettingsManagerが含まれており、ユーザーは簡単に設定にアクセスし変更できます。環境のユーザー設定ディレクトリ内のJSONファイルに保存されるこれらの設定は、Python環境内またはコマンドラインインターフェース(CLI)経由で表示や変更が可能です。
Link to this section設定の確認#
現在の設定構成を確認するには、以下のようにします。
Use Python to view your settings by importing the settings object from the ultralytics module. Print and return settings with these commands:
from ultralytics import settings
# View all settings
print(settings)
# Return a specific setting
value = settings["runs_dir"]Link to this section設定の変更#
Ultralyticsでは、以下の方法で設定を簡単に変更できます。
In Python, use the update method on the settings object:
from ultralytics import settings
# Update a setting
settings.update({"runs_dir": "/path/to/runs"})
# Update multiple settings
settings.update({"runs_dir": "/path/to/runs", "tensorboard": False})
# Reset settings to default values
settings.reset()Link to this section設定の理解#
以下の表は、Ultralytics内の調整可能な設定の概要であり、値の例、データ型、説明が含まれています。
| 名前 | 値の例 | データ型 | 説明 |
|---|---|---|---|
settings_version | '0.0.6' | str | Ultralytics settings version (distinct from the Ultralytics pip version) |
datasets_dir | '/path/to/datasets' | str | データセットが保存されるディレクトリ |
weights_dir | '/path/to/weights' | str | モデルの重みが保存されるディレクトリ |
runs_dir | '/path/to/runs' | str | 実験の実行結果が保存されるディレクトリ |
uuid | 'a1b2c3d4' | str | 現在の設定に対する一意の識別子 |
sync | True | bool | Option to sync analytics and crashes to Ultralytics Platform |
api_key | '' | str | Ultralytics Platform API Key |
clearml | True | bool | Option to use ClearML logging |
comet | True | bool | Option to use Comet ML for experiment tracking and visualization |
dvc | True | bool | Option to use DVC for experiment tracking and version control |
hub | True | bool | Option to use Ultralytics Platform integration |
mlflow | True | bool | Option to use MLFlow for experiment tracking |
neptune | True | bool | Option to use Neptune for experiment tracking |
raytune | True | bool | Option to use Ray Tune for hyperparameter tuning |
tensorboard | False | bool | Option to use TensorBoard for visualization |
wandb | False | bool | Option to use Weights & Biases logging |
vscode_msg | True | bool | When a VS Code terminal is detected, enables a prompt to download the Ultralytics-Snippets extension. |
プロジェクトや実験を進める中で、最適な設定を維持するためにこれらの設定を随時見直してください。
Link to this sectionよくある質問 (FAQ)#
Link to this sectionpipを使用してUltralyticsをインストールする方法は?#
pipを使用したUltralyticsのインストールは以下の通りです。
pip install -U ultralyticsThis installs the latest stable release of the ultralytics package from PyPI. To install the development version directly from GitHub:
pip install git+https://github.com/ultralytics/ultralytics.gitシステムにGitコマンドラインツールがインストールされていることを確認してください。
Link to this sectioncondaを使用してUltralytics YOLOをインストールできますか?#
はい、condaを使用してUltralytics YOLOをインストールするには以下を実行します。
conda install -c conda-forge ultralyticsこの方法はpipの優れた代替手段であり、他のパッケージとの互換性を確保します。CUDA環境の場合は、競合を解決するためにultralytics、pytorch、およびpytorch-cudaを一緒にインストールしてください。
conda install -c pytorch -c nvidia -c conda-forge pytorch torchvision pytorch-cuda=11.8 ultralytics詳細な手順については、Condaクイックスタートガイドを参照してください。
Link to this sectionDockerを使用してUltralytics YOLOを実行する利点は何ですか?#
DockerはUltralytics YOLOに対して分離された一貫性のある環境を提供し、システム間でのスムーズな動作を保証してローカルインストールの複雑さを回避します。公式DockerイメージはDocker Hubで入手可能であり、GPU、CPU、ARM64、NVIDIA Jetson、およびConda用バリエーションがあります。最新イメージを取得して実行するには以下を実行します。
# Pull the latest ultralytics image from Docker Hub
sudo docker pull ultralytics/ultralytics:latest
# Run the ultralytics image in a container with GPU support
sudo docker run -it --ipc=host --runtime=nvidia --gpus all ultralytics/ultralytics:latest詳細なDockerの手順については、Dockerクイックスタートガイドを参照してください。
Link to this section開発用にUltralyticsリポジトリをクローンする方法は?#
Ultralyticsリポジトリをクローンし、開発環境をセットアップするには以下を実行します。
# Clone the ultralytics repository
git clone https://github.com/ultralytics/ultralytics
# Navigate to the cloned directory
cd ultralytics
# Install the package in editable mode for development
pip install -e .これにより、プロジェクトへの貢献や最新のソースコードを用いた実験が可能になります。詳細はUltralytics GitHubリポジトリをご覧ください。
Link to this sectionUltralytics YOLO CLIを使用すべき理由は?#
Ultralytics YOLO CLIは、Pythonコードなしで物体検出タスクの実行を簡素化し、ターミナルから直接トレーニング、検証、予測のための1行コマンドを可能にします。基本構文は以下の通りです。
yolo TASK MODE ARGS例えば、検出モデルをトレーニングするには以下を実行します。
yolo train data=coco8.yaml model=yolo26n.pt epochs=10 lr0=0.01その他のコマンドや使用例については、完全なCLIガイドをご覧ください。