GithubHelp home page GithubHelp logo

nvidia_jetson_smoker_detection's Introduction

Smoker Detection for Jetson Nano USB Camera

Generic badge Generic badge


Smoker Detection for Jetson Nano USB Camera

A basic project to deploy a smoker detection application on a Jetson Nano (4GB), using the Jetson-Interface libraries as well as the Roboflow Docker container with a model that I trained, but all running locally. The basics are as follows: The USB camera streams to the initial model to detect a person which then captures the image and sends to the pre-trained model running on the roboflow docker image and checks for the appearance of a cigarette. If a cigarette is detected the model writes "Potential Smoker" to the image and saves it in the Smoking folder for later viewing. If the person is not smoking, the image is deleted from the capture directory.

I am aware that this could be further optimized from every Nth frame check to further training the model on Roboflow. My intention was not for perfection but rather for demonstration that this and other CV projects can be developed and deployed on the Jetson architecture. Feel free to fork and build on making this even faster and more accurate. This project uses a containerized cigarette detection model trained on a roboflow platform using a public dataset (Model and Dataset).

Requirements

Below are the recommended hardware requirements for this project. I have selected the 128GB microSDXC based on the size of the libraries and dependencies.

  1. NVIDIA Jetson Nano Developer Kit (945-13450-0000-100)
  2. SanDisk Ultra microSDXC 128GB 100MB/s SDSQUNR 128G GN6MN

Getting Started

In order to get this project up and running it is assumed that you have already flashed and set up the Ubuntu desktop environment.

Check Swap space

free -m
sudo systemctl disable nvzramconfig

Create 4GB swap file

sudo fallocate -l 4G /mnt/4GB.swap
sudo chmod 600 /mnt/4GB.swap
sudo mkswap /mnt/4GB.swap

Append the following line to /etc/fstab

sudo su
echo "/mnt/4GB.swap swap swap defaults 0 0" >> /etc/fstab
exit

Update again and reboot

sudo apt-get update
sudo shutdown -r now

Set Up

Get an account on (RoboFlow.com), you will need this to use the inference call. Once you set up an account locate your API key.

  1. Get an API key from roboflow.com
  2. ***** Replace the "<-API KEY->" in the smoking_detection.py file with your API Key *****
  3. Do not forget to save the file after editing.
  4. Now you need to give the scripts the correct permissions to be able to run on the Jetson Nano.
  5. Navigate to the directory containing the (max.sh and the start_smoking_container.sh) files.
  6. Open a terminal in that directory and run the following commands.
  7. >> sudo chmod u+x installs.sh
    >> sudo chmod u+x max.sh
    >> sudo chmod u+x start_smoking_container.sh
  8. Now that your scripts can be ran start all of the required installs by running the following:
  9. >> sudo ./installs.sh
  10. When prompted with configuration file question: type "N" both times.
  11. You will be prompted to automatically restart the Docker Daemon, click "No".
  12. You may get asked if you want to install certain libraries etc, type Y and let run.
  13. When you get to the Models options window, please be sure to select (ssd-mobilenet-v2) Under the Object Detection heading.
  14. When you get to the Pytorch installation screen select it and Tab to "Ok".
  15. The overall time of implementation can vary depending on internet speeds and other factors. It usually takes around 30 minutes.
  16. Upon completion your Nano should reboot.

Start Up

Once the install finish and the Nano reboots you can test the application as follows:

  1. Log back into the device.
  2. Navigate to the root folder of the project.
  3. First we will boost the performance of the Nano.
  4. Open a terminal and enter the following:
  5. >> boost clocks
    >> sudo ./max.sh
  6. Now we will start the Smoking detection Docker Container:
  7. >> sudo ./start_Smoking_container.sh
  8. Now open another terminal in the same directory and enter the following:
  9. >> python3 smoking_detection.py
  10. The initial run may take a few minutes to load and start inferencing based on the Docker container as well as the 2 models the stream runs through. Remember initially we need to detect that a person is there, then we detect if that person has a cigarette.
  11. Please ensure network access is available for the initial run as the weights will need to be downloaded from the Roboflow servers. After that you should be good to go moving forward.
  12. Your display may go dark and freeze on the initial run as well, this is just because of the models and resources loading. Wait a minute and it will return to normal. This will not happen on subsequent runs.

Your display should resemble the images below. Be sure to check the "Smoking" directory for any captured images of smokers.

Smoker Detected Smoker Detected
A1 B2
Smoker Detected Smoker Detected
C3 D4

Process Diagram

Below is a simple flowchart depicting the flow of the project where you see the 2 distinct methods for inference on the Nvidia Jetson Nano.

D5

Troubleshooting/Errors

You may encounter a few errors upon running the "smoking_detection.py" script. If so here are the fixes potentially required.

  1. No Recognitions or Always showing "Potential Smoker":
  2. Fix: adjust up/Down the line 36 ( if float(fconf) >= float(0.978):) in the smoking_detection.py file.
  3. Error: "illegal instruction (core dumped)"
  4. There is a line in the installs.sh that tries to alleviate this issue, but it may have ebncountered permissions issues.
    The fix is to run ">> export OPENBLAS_CORETYPE=ARMV8"
    To avoid running this each time you reboot the nano run this >> echo 'export OPENBLAS_CORETYPE=ARMV8' >> ~/.bashrc
  5. Error: in the start_smoking_container.sh terminal you may see "Downloading wieghts for smoking-detection-o8042/2"
  6. The fix is to wait until the dowload completes and you may need to reboot the device.
    You may also need to stop and restart the container 2-3 times for the weights to take effect.
    For more information see: (Roboflow Inference Documentation)
  7. Error: "Folder does not exist"
  8. There is a line in the installs.sh that tries to alleviate this issue, but it may have ebncountered permissions issues.
    However you may have to manually create the "Captures" and "Smoking" directories in the same directory as the "smoking_detection.py" script.

Contact

Project Link: [https://github.com/mstatt/Nvidia_Jetson_Smoker_Detection]

Nano Certification URL: https://courses.nvidia.com/certificates/a19429d0545b4aa6b209074ed314e5ce

Project Video: https://www.youtube.com/watch?v=EPocYfeyTr8

(back to top)

License

nvidia_jetson_smoker_detection's People

Contributors

mstatt avatar

Stargazers

Nizamuddin Mohamed avatar

Watchers

 avatar

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.