0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ncnnでYoloV5 Segmentationを動かしてみる

Last updated at Posted at 2023-12-22

概要

ncnnで、オブジェクト認識と領域分割を同時に行う、yolov5のsegmentationを動かしてみる。
Screenshot from 2023-11-19 11-57-08.png

環境構築

構築手順に入る前に、まずPCに以下のバージョンのUbuntuをインストールした環境で、構築しました。

M5UnitV2のクロスコンパイル環境を構築する手順

Ubuntu 22.04.3 LTS(x64)
OpenCV ver 0.4.4
ncnn ver 231027

yolov5-seg-ncnnのダウンロード

GitHubからyolov5-seg-ncnnのコードをダウンロードします。

$ git clone https://github.com/FeiGeChuanShu/yolov5-seg-ncnn/
$ cd yolov5-seg-ncnn/demo/

CMakeLists.txt ファイルの作成

cmakeでコンパイルするために、CMakeLists.txtを編集します。

gedit CMakeLists.txt
CMakeLists.txt

SET(CMAKE_BUILD_TYPE "Release")

SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")

if(TARGET_COMPILER STREQUAL "arm")
    message(STATUS "TARGET_COMPILE STREQUAL arm")
    SET(CMAKE_CXX_COMPILER arm-none-linux-gnueabihf-g++)
    SET(CMAKE_C_COMPILER arm-none-linux-gnueabihf-gcc)
    SET(NCNN_INSTALL_DIR /opt/external/ncnn/install/arm/)
    SET(ZBAR_INSTALL_DIR /opt/external/zbar-0.10/build/arm)
    SET(OpenCV_DIR /opt/external/opencv/build/arm)
else()
    message(STATUS "TARGET_COMPILE STREQUAL X64")
    SET(NCNN_INSTALL_DIR /opt/external/ncnn/install/x64/)
    SET(ZBAR_INSTALL_DIR /opt/external/zbar-0.10/build/x64/)
    SET(OpenCV_DIR /opt/external/opencv/build/x64) 
endif()


PROJECT(yolov5_seg_ncnn)
cmake_minimum_required(VERSION 3.5)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)

if(OpenCV_FOUND)
 message(OPENCV_VERSION)
 message(STATUS "OpenCV_LIBS: ${OpenCV_LIBS}")
 message(STATUS "OpenCV_INCLUDE_DIRS: ${OpenCV_INCLUDE_DIRS}")
endif(OpenCV_FOUND)

find_package(OpenCV REQUIRED)

link_directories(${OpenCV_LIBRARY_DIRS})

include_directories(${OpenCV_INCLUDE_DIRS} )
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${NCNN_INSTALL_DIR}/include/ncnn)

add_executable(yolov5_seg_ncnn src/yolov5_seg.cpp)
target_link_libraries(yolov5_seg_ncnn ${OpenCV_LIBRARIES})
target_link_libraries(yolov5_seg_ncnn ${NCNN_INSTALL_DIR}/lib/libncnn.a -fopenmp)


学習モデルのダウンロード

yolov5-seg-ncnnのGitHubのリンクから、学習モデルをダウンロードします。
Screenshot from 2023-11-19 12-20-25.png

modelsフォルダに学習モデルを格納します。

$ ls ./models/
yolov5l-seg.bin    yolov5n-seg.bin    yolov5s-seg.bin    yolov5x-seg.bin
yolov5l-seg.param  yolov5n-seg.param  yolov5s-seg.param  yolov5x-seg.param

ビルド

プログラムをコンパイルして実行します。

$ cmake .
$ make
$ cd bin
$ $ ./yolov5_seg_ncnn ../imgs/horses.jpg 
17 = 0.92679 at 433.87 211.55 161.45 x 136.20
17 = 0.92614 at 1.04 189.29 313.97 x 220.81
17 = 0.89329 at 229.17 195.04 188.68 x 168.41
17 = 0.75586 at 364.89 207.97 92.22 x 114.62
17 = 0.63761 at 0.36 186.01 153.85 x 99.18

参考資料

この記事を作成するにあたり、以下のウェブサイトを参考にしました。

FeiGeChuanShu/yolov5-seg-ncnn

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?