Xnor’s Software Developer Kit (SDK) Tutorial

This tutorial is designed for the Linux Desktop with AVX2 CPU support. Tutorials for running Xnor Bundles in embedded environments for our various hardware targets will be coming soon.

Setting up an Xnor Environment

Xnor requires a Linux machine and AVX2. To check whether your machine has AVX2, run the following command:

grep -c -i avx2 /proc/cpuinfo

If the result is 0, you will need to switch machines or wait for the next release of the SDK, which will operate without AVX2. Subscribe to the Forum for release schedule updates. If the result is anything else, you have AVX2 on your device and you will be able to run xnornet.

Make sure you have the latest version of the SDK, v0.9. Check what version you have in the file called README.txt.

If you are running an earlier version, you can go to AI2GO/SDK to download the latest.

Now that you know that you have the latest version of the SDK and your machine is compatible, you can set up your environment following the steps below:

Unzip the SDK:

cd ~/Downloads
unzip <sdk zip file name>.zip
cd xnor-sdk-linux-x86_64

You are now ready to use Xnor’s SDK.

SDK Structure

The SDK contains the following folders and files:

docs/

Contains documentation

include/

Header file for running in C - xnornet.h

lib/

Contains XBs organized by hardware target

samples/

Contains the code samples needed to get started

LICENSE.txt

Legal notices regarding the use of this software.

README.txt

Information about the SDK.

Python Tutorial

Run a Person Detection Sample in Python

In order to run, you will need to install a few open-source packages. We’ve simplified this process for you by providing scripts that install everything you need, following the steps below:

Navigate to the python samples folder:

cd samples
cd python

Execute the install script:

chmod +x ../install_dependencies_ubuntu.sh
../install_dependencies_ubuntu.sh

Finally, you will need to install an Xnor model to use. We recommend starting with the person-pet-vehicle-detector.

Install the person-pet-vehicle-detector for Python:

python3 -m pip install --user ../../lib/person-pet-vehicle-detector/xnornet*.whl

Now you’re ready to run an object detector!

Run a demo of object detection on live video. You’ll need a working webcam for this demo to work:

python3 gstreamer_live_overlay_object_detector.py

Switch Python Models and Detect Different Objects

If you want to try out a different object detector, a variety of other models can be found at AI2GO. Look for any model called a Detector.

Once you’ve downloaded a new Xnor Model, you can use it with the same scripts you have been using before. All you need to do is install a different xnornet wheel. Follow the steps below to do so:

This command will uninstall our existing person-pet-vehicle-detector model:

python3 -m pip uninstall xnornet

Now unzip your new model:

unzip ~/Downloads/*detector*.zip

This command will install our the new model:

python3 -m pip install --user ~/Downloads/*detector*/xnornet*.whl

Now you’ll see different behavior from the same script:

python3 gstreamer_live_overlay_object_detector.py

Try with any of the object detectors on AI2GO!

C Tutorial

Run a Person Detection Sample in C

If your application will be using C or any C-based languages such as C++ or Objective-C, you’ll want to try out our C samples. Follow the steps below to do so:

Start by navigating to the C samples directory:

cd ~/Downloads/xnor-sdk-linux-x86_64
cd samples
cd c

Next, install dependencies (you can skip this step if you already installed the dependencies for Python):

../install_dependencies_ubuntu.sh

Next, compile the executable files from the source files we have provided:

make

The executable files will be located in the ./build folder. Try running the live object detector:

./build/gstreamer_live_overlay_object_detector

Switch C Models and Detect Different Objects

If you want to try out a different object detector, a variety of other models can be found at AI2GO. Look for any model called a Detector.

Once you’ve downloaded a new Xnor model, you can use it with the same executables you have already compiled! You only need to replace the libxnornet.so in your build folder, following the steps below:

Now unzip your new model:

unzip ~/Downloads/*detector*.zip

Copy the desired model into the build folder. This command will install an emotion classification model (and overwrite the existing object detector):

cp ~/Downloads/*detector*/libxnornet.so ./build/libxnornet.so

Now you can run the same object detector with different results:

./build/gstreamer_live_overlay_object_detector

What’s Next?

  • Try some of the samples to see how to use camera input.

  • Head over to AI2GO to get more model bundles.

  • C Quickstart for learning how to use the C API.

  • Python Quickstart for learning how to use the python API