- Stream Anamoly Detection - People (Flask: 5000)
- Annotation IoU check (Django: 8000)
- Compare Faces (Django: 9000)
- Stream live yolo-indexing (Flask: 7000)
- Stream live Textbox++ (Flask: 5080)
- Stream live yolo-indexing with Textbox++/ Integrated (Flask: 6000)
- Web Application as User Interface ( :3000)
- Go API ( :8080)
- MongoDB ( :27017)
- Dockerized containers - ReactJS, NodeJS, Go API
- CropFace to run in backend using Cron
- Compare Face Frontend
- Download Youtube Video and divide it
- Annotation function
- Seeing Live Camera Feed
- Running yolo/Textbox++ for IoU in Django (Port:8000)
- Running Yolo-indexing /Textbox++/ Integrated Yolo-Indexing and Textbox++/ yolo-indexing-peoplematching on Flask (Port:5000)
- Running Compare Faces in the backend in Django (Port:9000)
-
yolo-indexing and textbox++ are already integrated, add peoplematching component to obtain final flask application
-
Django and CompareDjango are run on 8000 and 9000 ports
-
Finally, the frontend should function and backends with 8000,9000 and 5000 ports should function
- ReactJs for Frontend (3000)
- NodeJs for Backend (4000)
- Django to run the Machine learning algorithms in the background (8000)
- Golang for running GO API's to connect the application with the Database (8080)
- MongoDB as NoSQL Database (27017)
- OpenCV for drawing boxes and checking IoU and for dividing the video into frames
- DarkFlow for running yolo9000
- tensorflow, numpy, keras for assisting the machine learning application
- matplotlib is being used for testing images (display of images)
- Vanilla Js for functions and bits of React code
- face_recognition library for detecting faces
- face_recognition library for comparing faces
- OpenCV haarcascades for detecting faces
- Flask for livestreaming (5000)
- Docker
- AWS EC2
- AWS S3
- Mongo Atlas
- Localtunnel
Resources : https://docs.docker.com/docker-for-mac/ https://docs.docker.com/compose/gettingstarted/ https://medium.com/travis-on-docker/how-to-dockerize-your-go-golang-app-542af15c27a2
- Once the frontend/Webapp is comlpetely dockerized
- Need to check with Django/CompareDjango/CropFaces/LiveStreamingOutput/PeopleAnomalyDetection
- Need to make sure that the dockerized application still functions the way it is supposed with all the integrations done
- Verify all features worked on are avaiable in the final version
- brew install ruby
- echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
- gem install localtunnel
- lt -h "http://serverless.social" -p Important
- Try using nginx for serving static folder
Important
-
docker stop CONTAINERID
-
lsof -P | grep ':4000' | awk '{print $2}' | xargs kill -9
-
Problem with API_Go : Until a static IP Address for the mongodb server is not found, for each system the user has to build the API_Go container by changing the IP Address to their Computer IP in a. HandleUsers/UserFunc.go b. HandleImages/ImageFunc.go
-
- To build: docker build -t -Name- .
Start MongoDB
- Local: docker run -d -p 27017-27019:27017-27019 --name mongodb mongo
if error occurs saying container already running
-
Local: docker run -d -p 27017-27019:27017-27019 --name CONTAINER ID mongo
-
Important : Make sure mongo is running on :27017 before running GO API
To run GO API
-
To build: docker build -t anirudhrv1234/goapi .
-
Remote: docker run --rm -it -p 8080:8080 anirudhrv1234/goapi
-
Local: docker run --rm -p 8080:8080 anirudhrv1234/goapi
To run NodeServer (Node JS)
- Local: docker run -p 4000:4000 anirudhrv1234/nodeserver
To run Client (React JS)
-
To build: docker build -t anirudhrv1234/reactjs .
-
Local: docker run -p 3000:3000 anirudhrv1234/reactjs
Commands to run a Docker app (GENERAL):
To make directory :
- mkdir test
- cd test
To make the app :
- touch myapp.py
- open myapp.py
- -Copy & Paste the required code
To define the requirements/dependencies :
- touch requirements.txt
- open requirements.txt
- -Copy & Paste the required dependencies
To create Dockerfile
- touch Dockerfile
- open Dockerfile
- -Copy & Paste the system configuration
To create docker-compose.yml
- touch docker-compose.yml
- open docker-compose.yml
- -Copy & Paste the required configuration
Run the App
- docker-compose up
To delete images
- docker system prune
A security system which helps in detecting people from a given set in real time
Explanation of module :
- A person's photo can be uploaded using the web app provided through the frontend
- The user's have to be signed in to access this feature
- Once the picture has been uploaded, periodically cropjustface.py is run in order to update the database
- Once the database is updated, the person can be tracked
- The streamingserver i.e the Flask app which process the video and shows the output live process and tracks the person
- The person is first identified using the yolo algorithm
- Then from the cropped person's body, the face is retrieved using face_recognition library
- It is then compared with every other person in the database and checked for similarities
- If a similarity exists, then the person will be bound with a green box
- Else, the person will be bound with a red box
The process of Recognising people is done with two separate steps :
- Cropping out the face from the body of a person which yolo has recognised
- Comparing a given face with the faces already stored in the backend
1. Cropping out the face from the body of a person which yolo has recognised
- The boxes which have the label "people" are stored in the backend and periodically a script is run to find the faces of the people in those boxes (The boxes bound the body of the person)
- The boxes around the people help in increasing the accuracy and decreasing the workload on the algorithm to recognise just faces as it has to go through less complex structures in images
- cropjustface.py is run through the database to provide the images of just faces a. This uses haarcascade_frontalface_default.xml set of weights b. The weights are pre-trained and it can recognise faces and puts a bounding box around it
- These face images are stored separately
2. Comparing a given face with the faces already stored in the backend
- When a particular image is being uploaded onto the webapp to check for similarities
- The image goes through the NodeServer and is stored in the backend
- The Django server then reads the URL where the image is stored and processes by using cropjustface algorithm to retrieve just the face.
- This image is then checked with every other face stored in the backend
- Each set of image is compared using the face_recognition library and an encodings matrix is formed
- The similarities between the encoding matrices of the User image and the backend image is calculated
- If the similarity is above a certain threshold / if the difference between the matrices below a certain threshold
- Then, the images are said to be similar and a True boolean value is returned
- All the URLs of the images which are similar are sent to the front end
- These URLs are read in the frontend and displayed on the webApp
Resources
- https://github.com/ageitgey/face_recognition
- http://dlib.net/
- https://github.com/opencv/opencv/tree/master/data/haarcascades
starter code :
- https://towardsdatascience.com/face-detection-in-2-minutes-using-opencv-python-90f89d7c0f81
- https://github.com/12345k/Two-Face-Comparison
Streaming Output (Changes to this need to be made)
- Using a flask backend to stream data from a security camera
- Displaying it live on a url
- Further changes and modifications can be made to the frames
Process of measuring IoU
- Each bounding box with label : "people" is considered (Iterated through)
- The bounding box is checked with all the ground truths for IoU
- The maximum IoU is considered for that bounding box (non-max suppression)
- The above process is repeated for each bounding box detected by the YOLO algorithm
- To add the possibility that people in the ground truth are completely ignored by the yolo algorithm a.The difference between the number of people detected by yolo and the number of people annotated for ground truth is considered b.This is added as extra 0's to the list of the IoU's
- The average of all the maximum IoU's of each bounding box and the additional 0's is taken for overall IoU for an image
- The average of all the IoU's for each image is taken as the average IoU for the dataset (~400 images)
- check code in CheckIoU/iou.py for source code
Tracking People / Object Indexing :
- Initialise detected people to 0
- When the processing of the frames start, each box that is detected by the yolo algorithm is compared to all previous detected boxes. As we initialised detected people people to 0,
- All the newly detected boxes are considered as new people and the people count is increased, and each box is indexed with a unique number (here, just the people count)
- During the next Iteration of the processing, all the detected boxes are compared to previously detected boxes and the IoU between the boxes is calculated,
- If there is a high IoU between a previous box and the current box being processed, we consider that the same person has moved from the previous frame, hence the IoU is high and the new box is given the index of the previous detected box
- When we repeat the above steps, it tracks people's movements through and the frames and hence we can tracking people when they are in front of a particular camera
- When a newly detected box has 0 IoU with all the previously detected boxes, we classify that as a new person, increase the people count and index the person
- If an old box has no overlaps with any of the new boxes, it is discarded
NOTE: The assumption taken here is that, when people move from one position in front of the camera to another or if there is a continuous movement of the people, as the video is divided into frames, the person under consideration will move slowly between these frames and the box around them also moves slowly with them. Therefore, if we can measure the IoU of the boxes between frames, we can figure out which boxes are moving and where they are moving and which direction they are moving. This gives us an idea of the traffic in front of the camera and also gives us valuable data regarding how long a person or a group of people stay in front of the camera. As an example,
- If we detect around 4 people who have the same index being in the coverage of the camera for a very long time, we can raise an alert
- If we know the daily traffic in front of a camera and the number of people abruptly increases / abruptly decreases we can raise an alert
- If we detect objects like a suitcase being in front of a camera for too long, we can raise an alert as the algorithm gets to know, it is the same suitcase as a result of the object indexing
Draw backs of the algorithm :
- The algorithm is too sensitive to change and the yolo algorithm does not provide the required accuracy to make the algorithm work perfectly.
- When there are crowded areas and the boxes overlap when detection happens, there are chances that the index of the person jumps between people
Improving the algorithm :
- A better object detection algorithm might improve the performance of the object tracking
- To make the algorithm a lot less sensitive to change and have a better more strict policy to change the index of a person
- Finding a better metric than IoU to find if a box is moving between frames
Downloading and processing video :
- If a video is already available, place it in the main folder or download a video from YouTube(Y2 downloader or In-House application)
- Run the dividevideo.py to split the video into frames at random intervals between 2-5 seconds (considering 30 fps)
- The divided frames will be available in the Dividedframes folder
Annotation System :
- The user signs up into the system by giving email,username,name and password
- Once the signUp is successful, the user is redirected to the upload page
- The user can upload upto 99 images at once and click viewimages
- Upon succeful upload of the images, the user is redirected to the EditPage
- EditPage contains the NavigationBar and the WorkingArea
- The user can draw boxes around the subject of interest and click save
- Upon clicking save, the coordinates of the boxes drawn will be saved in the backend
- The User has two options to check the IoU :
a. Check IoU at each image :
- The user can click on Check ml output yolo to check the IoU for that particular file
- Continue this process for each image and the individual IoU's will be saved in the IoU folder in IoU.txt
- Download/DownloadAll depending on the nature of output needed I.Download will only download the annotations II.DownloadAll will download the images,mloutputs,annotations,IoU and any aditional data present b. Continue the annotations for all images and check IoU together
- The user can just keep annotating images to have a smooth workflow
- DownloadAll once the annotations are done
- Place the images and the output in the checkIoU folder
- Run iou.py to check the IoU of all images and store it in the IoU folder in IoU.txt
- The output of the machine learning algorithms can be seen by running checkmloutput.py, images will be stored in the mlimages folder
System Architecture system_architecture.jpeg
IOU
- For people label on dataset collected from mainly Indian sources : 0.3005834618310959
- Number of images in test data : 381
Steps to run the application (may involve downloading mongo,go libraries and setting up django environment)
-
clone the git
-
Download both weights from :
-
https://drive.google.com/drive/folders/1pW4mKNOzOIf0Edyr4BppwnLpddCQ6Qch?usp=sharing
-
https://drive.google.com/open?id=1JupZYcQO7Jh5aiRQLwNzYZaX0uYGULdK
-
Place the weights in the Django/mlbackend folder with the other .py files
Reactjs : 3000
- cd Client
- npm install
- npm start
Go API: 8080
- cd API_Go
- go run main.go
Django: 8000
- cd django
- cd mlbackend
- python3 manage.py runserver
Django: 9000
- cd django
- cd mlbackend
- python3 manage.py runserver : 9000
NodeServer: 4000
- cd NodeServer
- node server.js
Flask : 5000 python3 Lstreamoutput.py
if npm build is failing, install by : npm install
For building yolo9000 :
- pip install Cython
- git clone https://github.com/thtrieu/darkflow.git
- cd darkflow
- python3 setup.py build_ext --inplace
- pip install . anywhere in the system
To get mongo working :
- use GoDB
- db.createCollection("ImageNames")
- db.createCollection("UserData")
Surveillance_System
- Install DarkNet
- Install Cython
- Download both weights from :
https://drive.google.com/drive/folders/1pW4mKNOzOIf0Edyr4BppwnLpddCQ6Qch?usp=sharing
https://drive.google.com/open?id=1JupZYcQO7Jh5aiRQLwNzYZaX0uYGULdK
- Can either Clone the directory or download the ZIP file from the above link.
- Run FinalYearNoteBook.ipynb and see the project.
- Edit the directory in the notebook according to your system.