mlbo / Tengine_C_Classification_Demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tengine C Classification X86版本完整示例

环境

System: Ubuntu20.04

CMAKE: 3.16.3

准备

  1. 第0篇-Tengine X86版本编译中编译好的so和头文件复制到项目目录中的tengine目录
  2. Tengine/examples/common中部分文件放入common目录
  3. 模型仓库的mobilenet.tmfile模型放到models目录,cat.jpg图片放到images目录
  4. tm_classification.c文件放到src目录

此时目录结构应该是这样

├── images
│   └── cat.jpg
├── models
│   └── mobilenet.tmfile
├── src
│   ├── common
│   │   ├── common.h
│   │   ├── stb_image.h
│   │   ├── stb_image_write.h
│   │   ├── tengine_operations.c
│   │   └── tengine_operations.h
│   └── tm_classification.c
└── tengine
    ├── include
    │   └── tengine
    │       ├── c_api.h
    │       └── defines.h
    └── lib
        └── libtengine-lite.so

编写 CMakeLists.txt

cmake_minimum_required(VERSION 3.10)
project(tm_classification)

set(CMAKE_CXX_STANDARD 11)

include_directories(tengine/include/ src/common/)

add_library(tengine SHARED IMPORTED)
set_target_properties(tengine PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/tengine/lib/libtengine-lite.so)

add_executable(tm_classification src/tm_classification.c  "src/common/tengine_operations.c" )

target_link_libraries(tm_classification -lm tengine)

编译

mkdir build
cd build
cmake ..
make -j`nproc`

测试

./build/tm_classification -m ./models/mobilenet.tmfile -i ./images/cat.jpg 

输出

Image height not specified, use default 224
Image width not specified, use default  224
Scale value not specified, use default  0.0, 0.0, 0.0
Mean value not specified, use default   104.0, 116.7, 122.7
tengine-lite library version: 1.4-dev

model file : ./models/mobilenet.tmfile
image file : ./imgs/cat.jpg
img_h, img_w, scale[3], mean[3] : 224 224 , 0.017 0.017 0.017, 104.0 116.7 122.7
Repeat 1 times, thread 1, avg time 42.71 ms, max_time 42.71 ms, min_time 42.71 ms
--------------------------------------
8.574144, 282
7.880117, 277
7.812573, 278
7.286458, 263
6.357486, 281
--------------------------------------

参考

  1. Tengine 人脸检测X86版本
  2. https://github.com/OAID/Tengine

About


Languages

Language:C 90.8%Language:C++ 9.1%Language:CMake 0.1%Language:Shell 0.0%