Counting Pedestrians Using TensorFlow's Object Detection

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Counting Pedestrians Using TensorFlow's Object Detection



I am new to machine learning field and based on what I have seen on youtube and read on internet I conjectured that it might be possible to count pedestrians in a video using tensorflow's object detection API.



Consequently, I did some research on tensorflow and read documentation about how to install tensorflow and then finally downloaded tensorflow and installed it. Using the sample files provided on github I adapted the code related to object_detection notebook provided here ->https://github.com/tensorflow/models/tree/master/research/object_detection.



I executed the adapted code on the videos that I collected while making changes to visualization_utils.py script so as to report number of objects that cross a defined region of interest on the screen. That is I collected bounding boxes dimensions (left,right,top, bottom) of person class and counted all the detection's that crossed the defined region of interest (imagine a set of two virtual vertical lines on video frame with left and right pixel value and then comparing detected bounding box's left & right values with predefined values). However, when I use this procedure I am missing on lot of pedestrians even though they are detected by the program. That is the program correctly classifies them as persons but sometimes they don't meet the criteria that I defined for counting and as such they are not counted. I want to know if there is a better way of counting unique pedestrians using the code rather than using the simplistic method that I am trying to develop. Is the approach that I am using the right one ? Could there be other better approaches ? Would appreciate any kind of help.



Please go easy on me as I am not a machine learning expert and just a novice.





You can find source code of the TensorFlow Object Counting API that is an open source framework built on top of TensorFlow that makes it easy to develop object counting systems: github.com/ahmetozlu/tensorflow_object_counting_api
– Ozlu
Jul 5 at 20:42






2 Answers
2



You are using a pretrained model which is trained to identify people in general. I think you're saying that some people are pedestrians whereas some other people are not pedestrians, for example, someone standing waiting at the light is a pedestrian, but someone standing in their garden behind the street is not a pedestrian.



If I'm right, then you've reached the limitations of what you'll get with this model and you will probably have to train a model yourself to do what you want.



Since you're new to ML building your own dataset and training your own model probably sounds like a tall order, there's a learning curve to be sure. So I'll suggest the easiest way forward. That is, use the object detection model to identify people, then train a new binary classification model (about the easiest model to train) to identify if a particular person is a pedestrian or not (you will create a dataset of images and 1/0 values to identify them as pedestrian or not). I suggest this because a boolean classification model is about as easy a model as you can get and there are dozens of tutorials you can follow. Here's a good one:



https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/neural_network.ipynb



A few things to note when doing this:



My last bullet-point illustrates a problem with the idea as it's I've proposed it. The best solution would be to alter the object detection network to ouput both a bounding box per-person, and also a pedestrian/non pedestrian classification with it; or to only train the model to identify pedestrians, specifically, in the first place. I mention this as more optimal, but I consider it a more advanced task than my first suggestion, and a more complex dataset to manage. It's probably not the first thing you want to tackle as you learn your way around ML.





How can I modify the object detection program to count unique persons across a sequence of frames ? My input to object detection program is a video file not an image file and I am using opencv library to read the input video and then pass it on frame by frame to tensor flow. The video has about 350000 frames at 30 frames/sec. The same person appears in several frames and therefore if I start counting everytime tensorflow detects a person then I end up counting the same person multiple times because he appears in more than one frame. I hope I am explaining it properly.
– Ravindra Gudishala
Mar 27 at 17:33





OpenCV has some realtime object tracking features. You might want to dig deeper into what OpenCV currently provides. Building an object identification and tracking application from the ground up is certainly doable, but non trivial. I think it would take me somewhere on the order of a year to build something like that from scratch. pyimagesearch.com/2017/09/18/…
– David Parks
Mar 27 at 17:37





In building such a model, my first inclination would be to identify two objects between frames as the same or different. A triplet embedding approach (face recognition) seems like a reasonable place to start: medium.com/@ageitgey/…
– David Parks
Mar 27 at 17:38





OpenCV does provide a tracker but I am not sure how to set up the workflow that would allow me to track an object using OpenCv while I simultaneously detect/classify what kind of object it is .
– Ravindra Gudishala
Mar 27 at 19:03





I also believe that the object detection script provided by Google in the sample folder is already capable of tracking objects across frames. But the question is how do I tap into it to identify unique objects. May be I need to do more research. David, thank you very much for all your good suggestions.
– Ravindra Gudishala
Mar 27 at 19:10



Pedestrian Counting with TensorFlow (quicdemo)



The pipeline of the tracker that is developed with OpenCV and TensorFlow!



Pedestrian Counting and Vehicle Counting Sample Projects are available in this repo! It provides a TensorFlow Object Counting API is an open source framework built on top of TensorFlow that makes it easy to develop object counting systems!



You can watch the demo video of Pedestrian Counting and Vehicle Counting projects!






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

How to scale/resize CVPixelBufferRef in objective C, iOS