Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

This sample provides reference for you to learn the Ascend AI Software Stack and cannot be used for commercial purposes.

This sample works with CANN 3.3.0 and later versions, and supports Atlas 200 DK and Atlas 300.

Sample of Hand Detection in Image

Function: detect the presence of a hand in a scene with the Hand_detection.om model.

Input: an image

Output: an images with bounding box for the detected hand in the scene

Prerequisites

Before deploying this sample, ensure that:

Software Preparation

  • Make sure you log in to the operating environment (HwHiAiUser)

    ssh HwHiAiUser@xxx.xxx.xxx.xxx
    

    Icon-note.gif NOTE

    Replace xxx.xxx.xxx.xxx with the IP address of the operating environment. The IP address of Atlas 200 DK is 192.168.1.2 when it is connected over the USB port, and that of Atlas 300 is the corresponding public network IP address.

1. Obtain the source package.

cd $HOME
git clone https://github.com/Ascend/samples.git

2. Install Dependencies

Only if required libraries are not installed

pip3 install Pillow
pip3 install opencv-python

3. Obtain the Protobuf model and test images

Ensure you are in the project directory (hand_detection_picture/) and run the following commands in the table to obtain the hand detection model used in the application.

cd $HOME/samples/python/contrib/hand_detection_picture/
Model How to Obtain
Hand_detection.pb wget --no-check-certificate 'https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/003_Atc_Models/AE/ATC%20Model/hand_detection_picture/Hand_detection.pb' -O model/Hand_detection.pb
hand.jpg wget --no-check-certificate 'https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/003_Atc_Models/AE/ATC%20Model/hand_detection_picture/hand.jpg' -O data/hand.jpg
verify.jpg wget --no-check-certificate 'https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/003_Atc_Models/AE/ATC%20Model/hand_detection_picture/verify.jpg' -O data/verify.jpg

4. Convert the original model to a DaVinci model

Note: Ensure that the environment variables have been configured in Environment Preparation and Dependency Installation.

  1. Set the LD_LIBRARY_PATH environment variable.

    The LD_LIBRARY_PATH environment variable conflicts with the sample when Ascend Tensor Compiler (ATC) is used. Therefore, you need to set this environment variable separately in the command line to facilitate modification.

    export LD_LIBRARY_PATH=${install_path}/compiler/lib64
    
  2. Go to the project directory (hand_detection) and run the model conversion command to convert the model:

    atc --model=model/Hand_detection.pb --framework=3 --output=model/Hand_detection --soc_version=Ascend310 --input_shape="image_tensor:1,300,300,3" --input_format=NHWC --output_type=FP32
    

Sample Running

Run on single test image (hand.jpg)

cd $HOME/samples/python/contrib/hand_detection_picture/src
python3 hand_detection.py

See output/output.jpg to see detection result

Result Checking

After the execution is complete, the inference result is displayed on the CLI of the operating environment.