Git Product home page Git Product logo

nd131-openvino-fundamentals-project-starter's Introduction

Deploy a People Counter App at the Edge

Details
Programming Language: Python 3.5 or 3.6

people-counter-python

Table of contents

  1. What it does
  2. How it Works
  3. Requirements
      3.1 Hardware
      3.2 Software
  4. Setup
      4.1 Install Intel® Distribution of OpenVINO™ toolkit
      4.2 Install Nodejs and its dependencies
      4.3 Install npm
  5. Run the application
      5.1 Step 1 - Start the Mosca server
      5.2 Step 2 - Start the GUI
      5.3 Step 3 - FFmpeg Server
      5.4 Step 4 - Run the code
        5.41 Setup the environment
        5.41 Running on the CPU
        5.41 Running on the Intel® Neural Compute Stick
        5.41 Using a camera stream instead of a video file
  6. A Note on Running Locally

What it Does

The people counter application will demonstrate how to create a smart video IoT solution using Intel® hardware and software tools. The app will detect people in a designated area, providing the number of people in the frame, average duration of people in frame, and total count.

How it Works

The counter will use the Inference Engine included in the Intel® Distribution of OpenVINO™ Toolkit. The model used should be able to identify people in a video frame. The app should count the number of people in the current frame, the duration that a person is in the frame (time elapsed between entering and exiting a frame) and the total count of people. It then sends the data to a local web server using the Paho MQTT Python package.

You will choose a model to use and convert it with the Model Optimizer.

architectural diagram

Requirements

Hardware

  • 6th to 10th generation Intel® Core™ processor with Iris® Pro graphics or Intel® HD Graphics.
  • OR use of Intel® Neural Compute Stick 2 (NCS2)
  • OR Udacity classroom workspace for the related course

Software

  • Intel® Distribution of OpenVINO™ toolkit 2019 R3 release
  • Node v6.17.1
  • Npm v3.10.10
  • CMake
  • MQTT Mosca server

Setup

Install Intel® Distribution of OpenVINO™ toolkit

Utilize the classroom workspace, or refer to the relevant instructions for your operating system for this step.

Install Nodejs and its dependencies

Utilize the classroom workspace, or refer to the relevant instructions for your operating system for this step.

Install npm

There are three components that need to be running in separate terminals for this application to work:

  • MQTT Mosca server
  • Node.js* Web server
  • FFmpeg server

From the main directory:

  • For MQTT/Mosca server:

    cd webservice/server
    npm install
    
  • For Web server:

    cd ../ui
    npm install
    

    Note: If any configuration errors occur in mosca server or Web server while using npm install, use the below commands:

    sudo npm install npm -g 
    rm -rf node_modules
    npm cache clean
    npm config set registry "http://registry.npmjs.org"
    npm install
    

What model to use

It is up to you to decide on what model to use for the application. You need to find a model not already converted to Intermediate Representation format (i.e. not one of the Intel® Pre-Trained Models), convert it, and utilize the converted model in your application.

Note that you may need to do additional processing of the output to handle incorrect detections, such as adjusting confidence threshold or accounting for 1-2 frames where the model fails to see a person already counted and would otherwise double count.

If you are otherwise unable to find a suitable model after attempting and successfully converting at least three other models, you can document in your write-up what the models were, how you converted them, and why they failed, and then utilize any of the Intel® Pre-Trained Models that may perform better.

Run the application

From the main directory:

Step 1 - Start the Mosca server

cd webservice/server/node-server
node ./server.js

You should see the following message, if successful:

Mosca server started.

Step 2 - Start the GUI

Open new terminal and run below commands.

cd webservice/ui
npm run dev

You should see the following message in the terminal.

webpack: Compiled successfully

Step 3 - FFmpeg Server

Open new terminal and run the below commands.

sudo ffserver -f ./ffmpeg/server.conf

Step 4 - Run the code

Open a new terminal to run the code.

Setup the environment

You must configure the environment to use the Intel® Distribution of OpenVINO™ toolkit one time per session by running the following command:

source /opt/intel/openvino/bin/setupvars.sh -pyver 3.5

You should also be able to run the application with Python 3.6, although newer versions of Python will not work with the app.

Running on the CPU

When running Intel® Distribution of OpenVINO™ toolkit Python applications on the CPU, the CPU extension library is required. This can be found at:

/opt/intel/openvino/deployment_tools/inference_engine/lib/intel64/

Depending on whether you are using Linux or Mac, the filename will be either libcpu_extension_sse4.so or libcpu_extension.dylib, respectively. (The Linux filename may be different if you are using a AVX architecture)

Though by default application runs on CPU, this can also be explicitly specified by -d CPU command-line argument:

python main.py -i resources/Pedestrian_Detect_2_1_1.mp4 -m your-model.xml -d CPU -pt 0.6 | ffmpeg -v warning -f rawvideo -pixel_format bgr24 -video_size 768x432 -framerate 24 -i - http://0.0.0.0:3004/fac.ffm

If you are in the classroom workspace, use the “Open App” button to view the output. If working locally, to see the output on a web based interface, open the link http://0.0.0.0:3004 in a browser.

Running on the Intel® Neural Compute Stick

To run on the Intel® Neural Compute Stick, use the -d MYRIAD command-line argument:

python3.5 main.py -d MYRIAD -i resources/Pedestrian_Detect_2_1_1.mp4 -m your-model.xml -pt 0.6 | ffmpeg -v warning -f rawvideo -pixel_format bgr24 -video_size 768x432 -framerate 24 -i - http://0.0.0.0:3004/fac.ffm

To see the output on a web based interface, open the link http://0.0.0.0:3004 in a browser.

Note: The Intel® Neural Compute Stick can only run FP16 models at this time. The model that is passed to the application, through the -m <path_to_model> command-line argument, must be of data type FP16.

Using a camera stream instead of a video file

To get the input video from the camera, use the -i CAM command-line argument. Specify the resolution of the camera using the -video_size command line argument.

For example:

python main.py -i CAM -m your-model.xml -d CPU -pt 0.6 | ffmpeg -v warning -f rawvideo -pixel_format bgr24 -video_size 768x432 -framerate 24 -i - http://0.0.0.0:3004/fac.ffm

To see the output on a web based interface, open the link http://0.0.0.0:3004 in a browser.

Note: User has to give -video_size command line argument according to the input as it is used to specify the resolution of the video or image file.

A Note on Running Locally

The servers herein are configured to utilize the Udacity classroom workspace. As such, to run on your local machine, you will need to change the below file:

webservice/ui/src/constants/constants.js

The CAMERA_FEED_SERVER and MQTT_SERVER both use the workspace configuration. You can change each of these as follows:

CAMERA_FEED_SERVER: "http://localhost:3004"
...
MQTT_SERVER: "ws://localhost:3002"

nd131-openvino-fundamentals-project-starter's People

Contributors

abhiojha8 avatar chrvasq avatar mvirgo avatar rishit-dagli avatar ronny-udacity avatar sudkul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nd131-openvino-fundamentals-project-starter's Issues

Running locally in Mac OS Catalina

Dear Udacity team,

Following the guide provided for running the project locally in Mac, the ffmpeg older release can be compiled but not used. After some time searching, I found out the following workaround in order to have the possibility to locally develop the project:

https://trac.ffmpeg.org/ticket/8073

In the bottom of the page, where the solution is provided, it states that additional CFLAGS shall be provided in the case of MAC OS > 10.15 when make is called. Therefore the part of the mac-setup.md dedicated to FFMPEG shall, in my humble opinion, modified to accommodate this issue as follows:

git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
git checkout 2ca65fc7b74444edd51d5803a2c1e05a801a6023
./configure
make -j4 CFLAGS="-fno-stack-check"

Unable to run the Webservices UI on WSL

I completed all the previous steps mentioned in the instructions. Though during installing npm, I had to downgrade Nodejs as suggested by the command sudo aptitude install npm (I was unable to install npm any other way) and then I installed nodejs-legacy, again using aptitude to make sure to not to disturb any packages.

After that, I was successfully able to Start the Mosca server but encountered this error during running npm install under /webservices/ui

npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: [email protected]

and if I try to run npm run dev, I get

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'run', 'dev' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle [email protected]: [email protected]
6 silly lifecycle [email protected]: no script for predev, continuing
7 info lifecycle [email protected]: [email protected]
8 verbose lifecycle [email protected]: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]: PATH: /usr/share/npm/bin/node-gyp-bin:/home/zack/nd131-openvino-fundamentals-project-starter/webservice/ui/node_modules/.bin:/home/zack/bin:/home/zack/.local/bin:/opt/intel/openvino_2020.1.023/deployment_tools/model_optimizer:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files (x86)/Common Files/Intel/Shared Libraries/redist/intel64_win/compiler:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/Program Files (x86)/Brackets/command:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/Microsoft SQL Server/130/Tools/Binn/:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin:/mnt/c/Users/Gehlo/AppData/Local/Programs/Python/Python36/Scripts/:/mnt/c/Users/Gehlo/AppData/Local/Programs/Python/Python36/:/mnt/c/Users/Gehlo/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/Gehlo/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/Gehlo/AppData/Local/GitHubDesktop/bin:/snap/bin
10 verbose lifecycle [email protected]: CWD: /home/zack/nd131-openvino-fundamentals-project-starter/webservice/ui
11 silly lifecycle [email protected]: Args: [ '-c',
11 silly lifecycle 'cross-env NODE_ENV=development webpack-dev-server --history-api-fallback --watch --hot --inline' ]
12 silly lifecycle [email protected]: Returned: code: 1 signal: null
13 info lifecycle [email protected]: Failed to exec dev script
14 verbose stack Error: [email protected] dev: cross-env NODE_ENV=development webpack-dev-server --history-api-fallback --watch --hot --inline
14 verbose stack Exit status 1
14 verbose stack at EventEmitter. (/usr/share/npm/lib/utils/lifecycle.js:232:16)
14 verbose stack at emitTwo (events.js:87:13)
14 verbose stack at EventEmitter.emit (events.js:172:7)
14 verbose stack at ChildProcess. (/usr/share/npm/lib/utils/spawn.js:24:14)
14 verbose stack at emitTwo (events.js:87:13)
14 verbose stack at ChildProcess.emit (events.js:172:7)
14 verbose stack at maybeClose (internal/child_process.js:821:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
15 verbose pkgid [email protected]
16 verbose cwd /home/zack/nd131-openvino-fundamentals-project-starter/webservice/ui
17 error Linux 4.4.0-19041-Microsoft
18 error argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "dev"
19 error node v4.2.6
20 error npm v3.5.2
21 error code ELIFECYCLE
22 error [email protected] dev: cross-env NODE_ENV=development webpack-dev-server --history-api-fallback --watch --hot --inline
22 error Exit status 1
23 error Failed at the [email protected] dev script 'cross-env NODE_ENV=development webpack-dev-server --history-api-fallback --watch --hot --inline'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the intel-people-counter-app package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error cross-env NODE_ENV=development webpack-dev-server --history-api-fallback --watch --hot --inline
23 error You can get information on how to open an issue for this project with:
23 error npm bugs intel-people-counter-app
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls intel-people-counter-app
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]

Should provide a dockerised example of the starter

It's great to have the starter for local dev, but it would be even better to have a Dockerised version of the starter.

Using Docker will mean that the project is a bit more robust regardless of platform and will massively speed up deployment to new systems, like deploying to Raspberry Pi.

Currently working on Dockersing the starter for my own projects and will raise a PR when ready.

🙌

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.