231 views|1 replies

51

Posts

0

Resources
The OP
 

"CMake Construction Practice-Project Development Volume" Practice Sharing 4-Handwritten Digital Recognition Library Based on onnxruntime [Copy link]

This post was last edited by CoderX9527 on 2024-11-5 17:02

Introduction

This is the last chapter of the book. It integrates the knowledge of previous modules, library searches, and calling third-party libraries, and writes a command line tool for handwritten digit recognition based on ONNX runtime.

ONNX runtime installation

The official address of ONNX runtime is as follows
ONNX Runtime is a cross-platform machine learning accelerator for inference and training. By using ONNX runtime for inference, you can achieve a faster customer experience and reduce costs, and support deep learning frameworks such as PyTorch, TensorFlow/Keras, and classic machine learning libraries such as sckit-learn, LightGBM, and XGBoost. ONNX Runtime is compatible with different hardware, drivers, and operating systems, and takes advantage of the hardware accelerators used and graphics optimization and conversion to provide the best performance.

Install and verify the library (latest version fails, older versions succeed)

Download the latest precompiled package onnxruntime-linux-x64-1.20.0.tgz from https://github.com/microsoft/onnxruntime/releases
Download the compressed package for the linux-x64 platform and unzip it to the following directory:
Compilation failed in ch009 directory: It should be related to the c++ version and compilation. Don't bother with it for now.

The lower version was compiled successfully

Download onnxruntime-linux-x64-1.10.0.tgz, the same as the author, and unzip it to the corresponding directory.
The running prompt is Load model failed, which is consistent with the description in the book.

Compilation and installation of zlib library

Compile

Create a build-release directory in the zlib source code path, enter it, then configure cmake and start compiling.
mkdir build-release
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --config Release

Install

cmake --install . failed, need to install with administrator privileges
sudo cmake --install . Installation successful

Compilation and installation of libpng library

Compile

Create a build-release directory in the source directory and compile in this directory
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --config Release

Install

cmake --install . Installation failed, administrator privileges are required
sudo cmake --install . Installation successful

Handwriting Library Example

This directory program is an application that calls the handwritten digit recognition library and depends on the above three libraries.

CMake Catalog Program

Setting project properties

The above command sets the project properties for the CMake catalog program.

Find the package onnxruntime

Here, the onnxruntime version is specified as 1.10.0. Users can modify it according to the actual version downloaded.
Line 17 searches for the onnxruntime package and specifies the version number as 1.10. This actually calls the cmake/Findonnxruntime.cmake file. Its contents are as follows:
Finally, set the two variables onnxruntime_INCLUDE_DIR and onnxruntime_LIBRARIES.

Find the package libpng

at line 18 of CMakeLists.txt.
It actually calls the cmake/Findlibpng.cmake file, which has the following content:
Note that it will continue to look for the libpng16.cmake module file in the system, that is, this file is a wrapper of the libpng16.cmake file, exporting the two variables libpng_LIBRARY and libpng_INCLUDE_DIR.
Note that the libpng16.cmake file path is /usr/local/lib/libpng/libpng16.cmake, which is installed by libpng above.

Generate error

An error occurred, saying that the png_shared interface target includes ZLIB: ZLIB was not found.

ZLIB: ZLIB solution

Modify /usr/local/lib/libpng/libpng16.cmake file
Open this file with administrator privileges and shield the two statements containing ZLIB:ZLIB, as shown in the following figure:
cmake configures and compiles successfully
mkdir build-debug
cd build-debug
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake --build . --config Debug

Running results - some are right and some are wrong

Command line runs ./recognize ../models/mnist.onnx ../2.png
2.png/3.png/4.png were identified successfully respectively.
2.png/3.png/4.png here are original pictures provided by the author.
The following are the images 8.png/9.png/0.png I provided. The image size is the same as 2.png, 111x131 pixels.
The running results are as follows: 0/8 are recognized correctly, and 9 are recognized incorrectly (recognized as 1).
I provided another bold 9_bold.png image, but the recognition result was still wrong, and it was recognized as 7.

This post is from Programming Basics
 

51

Posts

0

Resources
2
 
#Let’s talk# Why did the recognition of the two pictures 0/9 fail?
This post is from Programming Basics
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
Reference salary for a master's degree in research and development

A summary of the salaries of major domestic companies in 2005     Japan's SONY 10,000/month, only graduate students ...

Lora parameter calculation and RF transmission distance calculation formula and tools

This post was last edited by xulikai on 2019-10-20 10:36 This content is originally created by EEWORLD forum user xuli ...

[Raspberry Pi Pico Review]——by fxyc87

@fxyc87 - Unboxing + Download - Start Programming - Start compiling the program 2 - How to save the written progra ...

Circuit Learning Guide Fan Shigui

552280

What is the difference between SPI_SDR = 0 and SPI_SDR = 0X55 in output?

This post was last edited by Shenzhen Xiaohua on 2021-11-9 15:13 The problem is twofold: 1. How many square waves are o ...

How to generate bin format files in MDK

In the integrated development environment of Realview MDK , by default, debug files in *.axf format and executable files ...

40 "Millions" of Raspberry Pi Cars - ROS Learning (C Language Programming to Control the Turtle)

This post was last edited by lb8820265 on 2022-11-1 14:52 In the previous section, we introduced how to run the "tu ...

Free Space Path Loss (FSPL)

In telecommunications, free space path loss (FSPL) is the loss in electromagnetic wave signal strength due to a line-of- ...

Evaluation and Award: Mir STM32MP135 Entry-Level MPU Development Board

Thanks to the following netizens for sharing their evaluation of the MiR STM32MP135 entry-level MPU development board. T ...

【Follow me Season 2 Episode 2】+ Access the open source smart home platform HA via Wi-Fi using the MQTT protocol

This post was last edited by Wang Jiahui on 2024-9-9 23:32 This time, I mainly want to learn about HA through this even ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list