A deep learning neural net model to detect drone/drones from a given picture using Using Fast R-CNN architecture via Keras-Retinanet Implementation. (Dataset and Pre-Trained model provided)
Live at: http://dronacharya.slapbot.me/
Me and my partner Nilesh participated in a Hackathon called, MoveHack which had one of the problem statement of Drone and UAV traffic management.
One of the key challenges of the problem statement was to detect any UAV or Drone from a given image.
I took the challenge by researching online of different techniques of detecting objects from a given picture, and with a prior of experience of using Fast R-CNN architecture in my workplace, I just went with it to see how it fares against drone detection.
Installation is divided into two parts:
sudo apt-get update
sudo apt-get install python3-dev python3-pip libcupti-dev
sudo apt-get install libsm6 libxrender1 libfontconfig1
Trained-Model
directory under name: drone-detection-v5.h5
from this link: https://drive.google.com/open?id=1nRMPUQcW9U6E3WjlP751s_77U9a0R5A9git clone https://github.com/slapbot/drone-detection
cd drone-detection
python -m venv drone-detection-env
source drone-detection-env/bin/activate
pip install --upgrade pip
pip install numpy==1.17.0
pip install -r requirements.txt
requirements.txt
python evaluate.py
to detect drones from one of the test image saved in the Dataset
folder.As you can see below the API is super intuitive and self-explaining to use.
from core import Core
c = Core()
image_filename = c.current_path + "/DataSets/Drones/testImages/351.jpg"
image = c.load_image_by_path(image_filename)
drawing_image = c.get_drawing_image(image)
processed_image, scale = c.pre_process_image(image)
c.set_model(c.get_model())
boxes, scores, labels = c.predict_with_graph_loaded_model(processed_image, scale)
detections = c.draw_boxes_in_image(drawing_image, boxes, scores)
c.visualize(drawing_image)
Create a virtual machine with these specifications. (You're open to use any other host provider or VM, its just what I did in the process.)
CPU 8 core 30 GB memory
server location: us-west1-b
GPU 1 Nvidia Tesla K80
sudo-apt get update
nano install_cuda.sh
#!/bin/bash
echo "Checking for CUDA and installing."
# Check for CUDA and try to install.
if ! dpkg-query -W cuda; then
# The 16.04 installer works with 16.10.
curl -O http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
dpkg -i ./cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
apt-get update
# apt-get install cuda -y
sudo apt-get install cuda-8-0
fi
sudo su
./install_cuda.sh
nvidia-smi
echo 'export CUDA_HOME=/usr/local/cuda' >> ~/.bashrc
echo 'export PATH=$PATH:$CUDA_HOME/bin' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=$CUDA_HOME/lib64' >> ~/.bashrc
source ~/.bashrc
git clone https://slapbot@bitbucket.org/slapbot/cudnn.git
cd cudnn
sudo dkpg -i libcudnn6_6.0.21-1+cuda8.0_amd64.deb
sudo apt-get install python3-dev python3-pip libcupti-dev
pip3 install --upgrade tensorflow-gpu==1.4.0
python3 -c "import tensorflow as tf; print(tf.__version__)"
git clone https://github.com/slapbot/drone-detection
cd drone-detection
git clone https://github.com/fizyr/keras-retinanet.git
cd keras-retinanet
pip3 install . --user
python3 setup.py build_ext --inplace
cd ..
python3 data_preparation.py
pip install opencv-python
pip install Pillow
python3 keras-retinanet/keras_retinanet/bin/train.py csv annotations.csv classes.csv --val-annotations=validation_annotations.csv
python3 keras-retinanet/keras_retinanet/bin/convert_model.py resnet50_csv_05.h5 resnet50_csv_05_inference.h5
Trained-Model
directory and follow the prediction instructions to get started with predicting!The API is super straightforward and intuitive to understand and consume,
taking a look at the evaluate.py
should give you a rough understanding of its functioning.
from core import Core
c = Core()
image_filename = c.current_path + "/DataSets/Drones/testImages/351.jpg"
image = c.load_image_by_path(image_filename)
drawing_image = c.get_drawing_image(image)
processed_image, scale = c.pre_process_image(image)
c.set_model(c.get_model())
boxes, scores, labels = c.predict_with_graph_loaded_model(processed_image, scale)
detections = c.draw_boxes_in_image(drawing_image, boxes, scores)
c.visualize(drawing_image)
boxes, scores, labels = c.predict_with_graph_loaded_model(processed_image, scale)
: returns you the boxes, scores and labels of the objects found (in our case labels are just used to do binary classification so there are only two labels.)boxes[0]
co-relates with scores[0]
and so on, depending on the score, you can say whether its a drone or not, after experimenting, I've figured that 0.5
is a good threshold value for tolerance.Prototyped in MoveHack - Was selected as top 10 overall solutions across all challenge themes among 7,500 individuals and 3,000 teams that globally competed for Hackathon.
Won the cash prize of ₹10,00,000 and received an invitation to attend the Global Mobility Summit 2018 at Vigyan Bhawan, Delhi by NITI AAYOG to meet major CEOs across automobiles, aviation, mobility organisations and receive the award by Prime Minister of India, Narendra Modi.