当前位置:网站首页>Experimental reproduction of image classification (reasoning only) based on caffe resnet-50 network
Experimental reproduction of image classification (reasoning only) based on caffe resnet-50 network
2022-07-26 03:41:00 【Huawei cloud developer Alliance】
Abstract : This experiment is mainly based on Caffe ResNet-50 Network to achieve image classification ( Reasoning only ) For example , Learn how to do it when you already have a pre training model , Deploy the model to shengteng AI Reasoning on the processor .
This article is shared from Huawei cloud community 《【CANN Training camp 】【2022 Season two 】【 Novice class 】 be based on Caffe ResNet-50 Network to achieve image classification ( Reasoning only ) Experimental recurrence of 》, author : StarTrek .
This experiment is mainly based on Caffe ResNet-50 Network to achieve image classification ( Reasoning only ) For example , Learn how to do it when you already have a pre training model , Deploy the model to shengteng AI Reasoning on the processor . The main tasks of this experiment are :
1、 take Caffe ResNet-50 The model file of the network is converted to the adaptive shengteng AI Offline model of the processor ( * .om file );
2、 Load the om file , Yes 2 Zhang * .jpg Synchronous reasoning of pictures , After getting the reasoning results respectively , Then deal with the reasoning results , Output top5 Category identification of confidence ;
3、 Replace the test image with your own image and recompile and run .
One 、 The use of ECS
First of all, in order to better let us understand and learn relevant knowledge of shengteng , Huawei CANN The training camp has given each student a certain amount of cloud server resources , A brief summary of the use of ECS is as follows :
The shared image provided this time is :Ubuntu 18.04( System ) + 5.1.RC2.alpha005(CANN Environment version )
Landing in huaweiyun -> Access control -> apply ESC Elastic cloud server -> Get the elastic public network IP-> Application SSH Remote access to ECs -> According to the normal ubuntu The terminal command of the system is used to operate the server
Resource link :
Remote terminal software recommendation MobaXterm:https://mobaxterm.mobatek.net/
How to use the software :MobaXterm Detailed use of the tutorial _xuanying_china The blog of -CSDN Blog _mobaxterm
After entering the terminal, it is root user , Need to go to HwHiAiUser user
Instructions :
cd /home/
su - HwHiAiUserhave access to ls perhaps ll Command to browse the existing files in the system at will .

Two 、 be based on Caffe ResNet-50 Network to achieve image classification ( Reasoning only ) experiment
After the preparatory work , Now you can start the formal experiment ! You can follow the readme The steps described in the document are operated step by step , Here is just a simple description of the experimental steps and experimental diagram .
Warehouse resource link :samples: CANN Samples - Gitee.com
1、 Download the sample code
clone sample The code in the warehouse
git clone https://gitee.com/ascend/samples.git
Enter into resnet50_imagenet_classification In the folder of the samples
cd samples/
cd cplusplus/level2_simple_inference/1_classification/resnet50_imagenet_classification
2、 obtain ResNet-50 Pre training model
First create a folder to store the model , And open the folder
mkdir caffe_model
cd caffe_modelDownload the pre training model directly through the command from the web page : Weight file (resnet50.caffemodel) And model files (resnet50.prototxt)
wegt https://modelzoo-train-atc.obs.cn-north-4.myhuaweicloud.com/003_Atc_Models/AE/ATC%20Model/resnet50/resnet50.prototxt
wegt https://modelzoo-train-atc.obs.cn-north-4.myhuaweicloud.com/003_Atc_Models/AE/ATC%20Model/resnet50/resnet50.caffemodel
3、 Model transformation
The pre training model downloaded above needs to be used first ATC The model conversion tool converts the model into shengteng AI Offline model supported by processor (.om)
Official documents ATC Tool learning resources : Shengteng community - Official website - shengteng Wanli Let intelligence be everywhere
technological process :
First, switch to the sample directory ( Then the above operation is the upper level directory )
cd ../Then run the model transformation tool
atc --model=caffe_model/resnet50.prototxt --weight=caffe_model/resnet50.caffemodel --framework=0 --output=model/resnet50 --soc_version=Ascend310 --input_format=NCHW --input_fp16_nodes=data --output_type=FP32 --out_nodes=prob:0
open model The folder can be seen resnet50.om The conversion has been completed

4、 Download the test image
Get into data Folder , And download two ImageNet There are pictures of categories in the dataset
cd ../data/
wget https://c7xcode.obs.cn-north-4.myhuaweicloud.com/models/aclsample/dog1_1024_683.jpg
wget https://c7xcode.obs.cn-north-4.myhuaweicloud.com/models/aclsample/dog2_1024_683.jpg

Two pictures of the test


5、 Picture format conversion
The downloaded picture is JPEG Format , It needs to be converted into a binary file suitable for the format required by the model input (.bin)
stay data Under the table of contents , perform transferPic.py Script , take *.jpg Convert to *.bin, At the same time, change the picture from 1024 * 683 The resolution of is scaled to 224 * 224.
python3 ../script/transferPic.py
6、 Compile operation
Get into “cplusplus/level2_simple_inference/1_classification/resnet50_imagenet_classification” Sample catalog
cd ../Set temporary environment variables , Configures the header file and library file path that the compiler depends on
export DDK_PATH=$HOME/Ascend/ascend-toolkit/latest
export NPU_HOST_LIB=$DDK_PATH/acllib/lib64/stub
establish build Folder , Prepare to compile the code file
mkdir -p build/intermediates/host

Get into build Folder , compile .cpp file
cd build/intermediates/host
cmake ../../../src -DCMAKE_CXX_COMPILER=g++ -DCMAKE_SKIP_RPATH=TRUE
make

It can be found in the sample directory (cplusplus/level2_simple_inference/1_classification/resnet50_imagenet_classification) Under the out Found the compiled executable in the folder main file , Next, let's run main file
cd ../../../out/
./main
3、 ... and 、 Replace image data for testing
Here I found two pictures casually on the Internet ( A goldfish label-1, A golden retriever label-207), You can find several pictures at will , As long as it is JPG Format pictures can be , The best type of things in the picture is ImageNet Types in dataset labels .
1、 Add pictures and convert formats
You can download it directly to your local computer , Then drag the file directly to MobaXterm In the ECS file list of the software , For convenience, first find the previous one in the list data Folder , Then directly drag it to the folder .


Follow the previous operation (5、 Picture format conversion ) Re convert the image file format , stay data Run in directory
python3 ../script/transferPic.py
2、 modify sample_process.cpp Source code , Add the path of the two new pictures
stay testFile Add the two newly added and converted ones to the list bin Format file path , The path can be written according to the first two , But don't forget the comma separation between different file paths

3、 Recompile source
Just follow the previous steps (6、 Compile operation ), It should be noted that , If the server has been restarted , The previously set compilation temporary environment will be lost , You need to set the temporary environment variables again ( Configures the header file and library file path that the compiler depends on ), Then you can go to build/intermediates/host Run directly under the file make Recompile, , The compiler will automatically compile the modified source file and overwrite .

4、 Reasoning
Rerun the compiled main File can (6、 The last step in compiling and running ), Note the path of the file , Need to be in out Run under folder , because main The file is saved here .

Finally, we can see
The label is 1 It's goldfish , In the first picture, the probability of goldfish is 99.7070%
The label is 207 It's a golden retriever , In the second picture, the probability of golden retriever is 99.5605%
Click to follow , The first time to learn about Huawei's new cloud technology ~
边栏推荐
- Performance comparison of ext4, NTFS, XFS, Btrfs, ZFS, f2fs and ReiserFS
- Matlab paper illustration drawing template issue 39 - stairs
- 深度学习之DAT
- [class and object instances in kotlin]
- Uncaught TypeError: $(...).onmouseenter is not a function js错误,解决办法:
- 2022-07-21 第四小组 修身课 学习笔记(every day)
- Usage of tf.variable() function in tensorflow
- Offline data warehouse from 0 to 1 - phase I resource purchase configuration
- WAF details
- Multi merchant mall system function disassembly lecture 15 - platform side member label
猜你喜欢

Configuration and use of virtualservice, gateway and destinationrule of istio III

研发了 5 年的时序数据库,到底要解决什么问题?

day03_ 1_ Idea tutorial

Multi merchant mall system function disassembly lecture 15 - platform side member label

通用测试用例写作规范

How Lora wireless gateway can quickly realize end-to-cloud transmission

Bing(必应)搜索,为什么用户越来越多?

A 4W word redis interview tutorial

Why are more and more users of Bing search?

Visio:甘特图如何合并单元格?解决方案:覆盖单元格
随机推荐
[STL]优先级队列priority_queue
C语言函数(2)
URDF syntax explanation
KBPC1510-ASEMI大芯片15A整流桥KBPC1510
2020 AF-RCNN: An anchor-free convolutional neural network for multi-categoriesagricultural pest det
The B2B2C multi merchant system has rich functions and is very easy to open
线性回归原理推导
Dtcloud the next day
Moco V2: further upgrade of Moco series
Network model and protocol
div设置高度不生效
Leetcode-462. make the array elements equal with the minimum number of moves
Data elements
大厂面试都面试些啥,看了不亏(一)
QT notes - temporary floating window
Leetcode-202. happy number
Illustration leetcode - 5. Longest palindrome substring (difficulty: medium)
研发了 5 年的时序数据库,到底要解决什么问题?
Why are more and more users of Bing search?
PHP连接mysql数据库,数据库连接静态工具类,简化连接。