コンテンツへスキップ

Interactive Object Detection: Gradio & Ultralytics YOLO11 🚀

インタラクティブ物体検出入門

This Gradio interface provides an easy and interactive way to perform object detection using the Ultralytics YOLO11 model. Users can upload images and adjust parameters like confidence threshold and intersection-over-union (IoU) threshold to get real-time detection results.



見るんだ: Gradio Integration with Ultralytics YOLO11

なぜオブジェクト検出にGradioを使うのか?

  • ユーザーフレンドリーなインターフェース:Gradioは、ユーザーが画像をアップロードし、コーディングなしで検出結果を視覚化するための簡単なプラットフォームを提供します。
  • リアルタイム調整:信頼度やIoUしきい値などのパラメータをその場で調整できるため、検出結果の即時フィードバックと最適化が可能です。
  • 幅広いアクセシビリティ:グラディオのウェブ・インターフェースは、誰でもアクセスできるため、デモンストレーションや教育目的、迅速な実験に最適なツールです。

Gradioのスクリーンショット

グラディオのインストール方法

pip install gradio

インターフェースの使い方

  1. 画像のアップロードUpload Image'をクリックして、オブジェクト検出用の画像ファイルを選択します。
  2. パラメータを調整する:
    • 信頼しきい値:オブジェクトを検出するための最小信頼レベルを設定するスライダ。
    • IoUしきい値:異なるオブジェクトを区別するためのIoUしきい値を設定するスライダー。
  3. 結果を表示します:検出されたオブジェクトとそのラベルを含む処理された画像が表示されます。

使用例

  • サンプル画像1:デフォルトの閾値でのバス検出。
  • サンプル画像2:デフォルトの閾値でスポーツ画像を検出。

使用例

This section provides the Python code used to create the Gradio interface with the Ultralytics YOLO11 model. Supports classification tasks, detection tasks, segmentation tasks, and key point tasks.

import gradio as gr
import PIL.Image as Image

from ultralytics import ASSETS, YOLO

model = YOLO("yolo11n.pt")


def predict_image(img, conf_threshold, iou_threshold):
    """Predicts objects in an image using a YOLO11 model with adjustable confidence and IOU thresholds."""
    results = model.predict(
        source=img,
        conf=conf_threshold,
        iou=iou_threshold,
        show_labels=True,
        show_conf=True,
        imgsz=640,
    )

    for r in results:
        im_array = r.plot()
        im = Image.fromarray(im_array[..., ::-1])

    return im


iface = gr.Interface(
    fn=predict_image,
    inputs=[
        gr.Image(type="pil", label="Upload Image"),
        gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
        gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
    ],
    outputs=gr.Image(type="pil", label="Result"),
    title="Ultralytics Gradio",
    description="Upload images for inference. The Ultralytics YOLO11n model is used by default.",
    examples=[
        [ASSETS / "bus.jpg", 0.25, 0.45],
        [ASSETS / "zidane.jpg", 0.25, 0.45],
    ],
)

if __name__ == "__main__":
    iface.launch()

パラメータの説明

パラメータ名タイプ説明
imgImage物体検出を行う画像。
conf_thresholdfloat物体を検出するための信頼閾値。
iou_thresholdfloat物体分離のための交差-結合閾値。

グラディオ・インターフェース・コンポーネント

コンポーネント説明
画像入力検出のために画像をアップロードする。
スライダー信頼度とIoUのしきい値を調整する。
画像出力検出結果を表示するには

よくあるご質問

How do I use Gradio with Ultralytics YOLO11 for object detection?

To use Gradio with Ultralytics YOLO11 for object detection, you can follow these steps:

  1. グラディオをインストールする: コマンドを使用する pip install gradio.
  2. インターフェイスを作成する: Python 、Gradioインターフェースを初期化するスクリプトを記述する。詳細はドキュメントにあるコード例を参照してください。
  3. アップロードと調整:画像をアップロードし、Gradioのインターフェイス上で信頼度とIoUのしきい値を調整すると、リアルタイムのオブジェクト検出結果が得られます。

参考のために最小限のコード・スニペットを示す:

import gradio as gr

from ultralytics import YOLO

model = YOLO("yolo11n.pt")


def predict_image(img, conf_threshold, iou_threshold):
    results = model.predict(
        source=img,
        conf=conf_threshold,
        iou=iou_threshold,
        show_labels=True,
        show_conf=True,
    )
    return results[0].plot() if results else None


iface = gr.Interface(
    fn=predict_image,
    inputs=[
        gr.Image(type="pil", label="Upload Image"),
        gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
        gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
    ],
    outputs=gr.Image(type="pil", label="Result"),
    title="Ultralytics Gradio YOLO11",
    description="Upload images for YOLO11 object detection.",
)
iface.launch()

What are the benefits of using Gradio for Ultralytics YOLO11 object detection?

Using Gradio for Ultralytics YOLO11 object detection offers several benefits:

  • ユーザーフレンドリーなインターフェース:Gradioは、ユーザーがコーディング作業なしで画像をアップロードし、検出結果を視覚化するための直感的なインターフェイスを提供します。
  • リアルタイム調整:信頼度やIoUしきい値などの検出パラメータを動的に調整し、その効果を即座に確認できます。
  • アクセシビリティウェブ・インターフェイスは誰でもアクセス可能で、簡単な実験や教育目的、デモンストレーションに便利です。

詳しくはこちらのブログ記事をご覧いただきたい。

Can I use Gradio and Ultralytics YOLO11 together for educational purposes?

Yes, Gradio and Ultralytics YOLO11 can be utilized together for educational purposes effectively. Gradio's intuitive web interface makes it easy for students and educators to interact with state-of-the-art deep learning models like Ultralytics YOLO11 without needing advanced programming skills. This setup is ideal for demonstrating key concepts in object detection and computer vision, as Gradio provides immediate visual feedback which helps in understanding the impact of different parameters on the detection performance.

How do I adjust the confidence and IoU thresholds in the Gradio interface for YOLO11?

In the Gradio interface for YOLO11, you can adjust the confidence and IoU thresholds using the sliders provided. These thresholds help control the prediction accuracy and object separation:

  • 信頼しきい値:オブジェクトを検出するための最小信頼レベルを決定します。スライドして必要な信頼度を増減する。
  • IoUしきい値:重なり合っているオブジェクトを区別するための、交差と統合のしきい値を設定します。この値を調整することで、オブジェクトの分離を精密にすることができます。

これらのパラメータの詳細については、パラメータの説明セクションをご覧ください。

What are some practical applications of using Ultralytics YOLO11 with Gradio?

Practical applications of combining Ultralytics YOLO11 with Gradio include:

  • リアルタイム物体検出デモンストレーション:オブジェクト検出がリアルタイムでどのように機能するかを紹介するのに最適です。
  • 教育ツール:物体検出やコンピュータビジョンの概念を教える学術的な場面で役立つ。
  • プロトタイプ開発:物体検出アプリケーションのプロトタイプを迅速に開発し、テストするために効率的です。
  • コミュニティとコラボレーション:フィードバックやコラボレーションのために、コミュニティとモデルを簡単に共有できるようにする。

同様の使用例については、Ultralytics ブログをご覧ください。

Providing this information within the documentation will help in enhancing the usability and accessibility of Ultralytics YOLO11, making it more approachable for users at all levels of expertise.

📅 Created 8 months ago ✏️ Updated 22 days ago

コメント