LoginSignup
0
0

Python で物体認識AIのYOLOv8を試してみた!〜基礎編〜

Posted at

はじめに

今回、試したのは画像認識AIの中でも、物体を認識できるYOLOv8を試してみました。
今回は、基礎編と題して、githubのページに記載の、インストールから基本的な操作についてご紹介します。

環境

Windows10
Python3.11.8
GPU:NVIDIA Geforce RTX3060
VSCode

使用ライブラリー

pytorch 2.2.1+cu118
ultralytics 8.1.25
opencv-python 4.9.0.80

#YOLOv8のインストール:
githubの以下のページに記載の流れでインストールします。
前提条件としてはPython3.8以上でPyTorchは1.8以上が必要です。
PyTorchをインストールした後、以下のpipコマンドでYOLOv8をインストールします。

pip install ultralytics

YouTubeでの解説:

上記のインストール方法から、サンプルプログラムの実行までをYoutubeで詳しく解説していますので、ぜひ、ご覧ください。

サンプルソース

以下のサイトではPythonでYOLOv8を使うサンプルプログラムが掲載されています。

YouTubeで紹介している1つ目の処理のプログラムソースです。

whisper0.py
from ultralytics import YOLO
from PIL import Image
import cv2

model = YOLO("yolov8s.pt")

# # from PIL
im1 = Image.open("sample1.jpg")
results = model.predict(source=im1, save=True)  # save plotted images

動画処理プログラム

Yotubeで紹介している、動画の物体認識プログラムです。
sampleというフォルダ内に、動画ファイルを保存して実行します。

whisper_excel.py
from ultralytics import YOLO
from PIL import Image
import cv2

model = YOLO("yolov8x.pt")

results = model.predict(source="sample", show=True,save=True) # Display preds. Accepts all YOLO predict arguments

最後に:

今回は、物体認識のYOLOv8のインストールと、基本的な使い方を紹介しました。
今後、プログラムで各種認識結果を受け取る方法も、ご紹介したいと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0