Detecting the parking slot occupancy can help us by providing the exact location of the place which is empty for parking and save our time. For this purpose, we can use Image Detection to get the location of the parking space which is empty for parking. Since there are many online models available for the detection of vehicles, like MaskRCNN, YOLO, etc, on the basis of our requirement we can use any of these. Requirements can be based on precision, accuracy or F1-scores which means every model has its own benefit. YOLO is very faster and can detect the object in a very small period of time but on the other hand it has a lower accuracy score. MaskRCNN is slower than YOLO but its accuracy score is greater than YOLO. For our purpose the slower model will work if it is giving us better accuracy. Thus we have used MaskRCNN for detecting the vehicle/empty parking slots.
For processing the video frames in real-time we need a good system that can handle at least 60 frames per minute.
~CPU: Intel i7 7700K (The letter K after the number denotes that the processor is designed for performance. It also means the chip is “unlocked,” where its clock speed can be overclocked by a user thus it is a must. And higher the number after 7xxx means better the processor)
~GPU: if you are planning to run your model on GPU then, use Nvidia GTX 1050Ti at least or you can go higher to GTX 2080Ti. NOTE:- For this task the GPUs are a must, the computation power of CPU is not enough for us.
~RAM: 8 GB with SSD (take 16GB as swap) or 16GB with HDD (16GB swap)
Enabling GPU processing:
Since we are processing the video, it requires high computation power thus the CPU is not enough for us and we use GPUs to do our work.For enabling the GPU just follow the below steps.
->Detect and install the Nvidia-GPU driver.
->Install CUDA (this is the Nvidia’s library/API package for programming in GPU)
->Install cuDNN (it is the library for deep neural networks built using CUDA).
Installing Nvidia_GPU in Ubuntu
-Type the following command in terminal it will give you the information about your GPU.
-This must show an output similar to this,
-Go to this link to download the driver for the corresponding GPU. search the driver and download it.
-For Ubuntu, it will give you a .run file, type the following command to make the script runnable.
sudo apt-get install gcc
sudo apt-get install make
-Disable the default Nouveau NVIDIA driver, type the following commands in terminal:
sudo bash -c "echo blacklist nouveau > /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
sudo bash -c "echo options nouveau modeset=0 >> /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
-To check if both commands have run in the right way just type the following command:
-The output should be like
Options nouveau set to 0
-Now run the following command
sudo update-initramfs -u
-Now install the Nvidia driver which we have downloaded with the command
->Activate your virtualenv (if you’re using a virtual environment for your project)
->Open python shell and Type the command :
import tensorflow as tf
->must give output like
How parking detection is working
It will use Mask R- CNN( it is a deep neural model that efficiently detects objects in an image while simultaneously generating a high-quality segmentation mask for each instance ) for detecting the vehicles in the parking slots. If there is an empty space in the parking area then it will detect it and show a green square otherwise it will show a red box for filled space. On the upper side of the screen, it will show the number of parking slots that are empty.
Approach to make it work:
->We will firstly take a video or image from the CCTV-Camera installed in the parking space.
->Building parking slots (custom bounding boxes where cars must be parked.
Make boxes based on the parking area with coordinates:
def get_car_boxes(boxes, class_ids):
car_boxes = 
for i, box in enumerate(boxes):
# If the detected object isn't a car / truck, skip it
if class_ids[i] in [3, 8, 6]:
#The class MaskRCNNConfig is used for configuring the MaskRCNN model:
# Configuration that will be used by the Mask-RCNN library
NAME = "coco_pretrained_model_config"
IMAGES_PER_GPU = Number of Images/Frames per GPU per TIME.
GPU_COUNT = Maximum number of GPU we wanna use(it will only use available GPU’s)
NUM_CLASSES = total number of classes which can be classified by the model, there are 80+1(background)
DETECTION_MIN_CONFIDENCE = Minimum confidence for classification
#There are some static variables which are used in our model they are #as follows:
ROOT_DIR = Root directory of the project
MODEL_DIR = Directory to save logs and trained model
COCO_MODEL_PATH = Local path to trained weights file
IMAGE_DIR = Directory of images to run detection on
VIDEO_SOURCE = Video file or camera to process - set this to 0 to use your webcam instead of a video file
# Now Let’s Create a Mask-RCNN model in inference mode
config = tensorflow.ConfigProto()
config.inter_op_parallelism_threads = 1 # number of threads we wanna apply
model = MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=MaskRCNNConfig())
#Loading pre-trained model