Skip to content

smit25/Pedestrian-Detector-using-CNN-and-Sliding-Window

Repository files navigation

Pedestrian-Detector

LIBRARIES USED:

1)OS.

2)PYTORCH/KERAS.

3)PIL.

4)CV2.

5)MATPLOTLIB.

6)SCIKITLEARN (OPTIONAL).

7)NUMPY.

PURPOSE OF THIS PROJECT:

  1. Used by drones for detection of pedestrains.
  2. Useful for autopilot in cars.
  3. With added features and optimization, it can be used for individual recognition.

PIPELINE:

1)Loading the dataset using os library.

2)Preprocess the image using PIL and/or CV2.

3)convert the image to array using numpy and convert the array to tensor through torchvision.

4)train the model built using keras/pytorch.

6)pass the test image thourgh the trained model and generate heatmap using matplotlib.

7)apply threshold on the heatmap and make boxes around the region having potetial pedestrains.

8)group the boxes and generate the image.

FLOW OF THE PROJECT:

  1. Procure a dataset, either download a public dataset or make a datatset of your own. Make sure the dataset contains images of both Pedestrians and non-Pedestrians for training.

  2. Divide the dataset into trainig, cross-validation (if you have the number) and test, either by slicing the list or using test-train split from sci-kit learn.

  3. Convert the images to arrays ad then tensors using the appropriate functions, methods.

  4. Create a Convolution Neural Network Model for the dataset using Keras/Pytorch or any other suitable API for the training and testing.

  5. Train the model and save the weights.

  6. Select an image(test-image) on which the Pedestrian is to be detected and run it through the Convolution Model.

  7. The image will be scaled down in accordance with the depth and the kernel size of the CNN, and the resulting output will be tensor with each value of it being a probability. Make a copy of resulting tensor and apply threshold on the tensor(rudimentary Non-Max Suppression),i.e. all the tensor entries below the threshold are reassgned value 0 and those above the threshold are converted to 1.

  8. Generate a heatmap from the resulting tensor ( by reconverting array into image)

  9. Generate a heatmap with the threshold applied.

  10. Use PIL to draw rectangles and rescale according to the dimensions of the original image.

  11. Use cv2 library to group rectangles.

  12. Display the image.

ARCHITECTURE OF THE MODEL(summary of the same model using Keras API):

Layer (type) Output Shape Param #

conv2d_1 (Conv2D) (None, 48, 96, 16) 160


conv2d_2 (Conv2D) (None, 48, 96, 32) 4640


max_pooling2d_1(MaxPooling2) (None, 8, 16, 32) 0


dropout_1 (Dropout) (None, 8, 16, 32) 0


conv2d_3 (Conv2D) (None, 4, 8, 64) 92224


max_pooling2d_2(MaxPooling2) (None, 2, 4, 64) 0


conv2d_4 (Conv2D) (None, 1, 1, 64) 32832


dropout_2 (Dropout) (None, 1, 1, 64) 0


conv2d_5 (Conv2D) (None, 1, 1, 128) 8320


conv2d_6 (Conv2D) (None, 1, 1, 1) 129

=================================================================

Total params: 138,305

Trainable params: 138,305

Non-trainable params: 0