Tensorflow: Does object detection API returns detected object id - tensorflow

I am using the tensorflow object detection api on windows system and it has been working fine. I am using the pre-trained model as of now which is ssd_mobilenet_v1_coco_11_06_2017. It is easily detecting all the objects in a given input video. I wanted to record time of each object so lets say, if in a video a car enters at 00:05 and leaves at 00:15 which means that it was in for 10secs.
To achieve this, I was looking if there is anything like id of each detected object which the API returns so that I can start a timer from the code to calculate the time of an object. Is there any already built functionality for this in the API.?

Tensorflow Object detection does not provide such functionality, but you can user KFC algorithm(easily available using Open CV) to track the object.
https://www.docs.opencv.org/3.4.1/d2/dff/classcv_1_1TrackerKCF.html
or You can implement SORT above object detection API which uses Kalman Filter but easy to integrate.
https://github.com/abewley/sort/blob/master/sort.py

The Tensorflow Object Detection API does not currently track objects between frames.

Related

How to execute actions using Tensorflow Object Detection

First of all, I'm not from programming area, actually I'm graduating in Electromechanics, and I need to create an innovation project to get my degree.
My project uses a AI that identify types of recyclable materials, and for this I'm using Tensorflow Object Detection. I have already trained the software and I'm having good results with real time detections using Webcam.
The question is: I don't know how to get a single detected class (plastic for example) and make it execute actions like activating a DC motor.

How to apply object tracking on an object that shows different sides?

I have been working on a truck detection model using YOLOv4 darknet. The model performance is good. I have applied deep_sort object tracking to track the activity of the trucks in that region.
The problem with this approach is that the truck identity changes when it steers around showing a different side against the camera feed or is obstructed by another object.
Is there a way to make sure that truck ID does not change?
Link to a demo inference video
I have trained the model specifically for this video. Object detection works fine but tracking id changes.

Tensorflow Object Detection API model for use in TensorFlow.js

I am trying to use an object detection model, that was created using the TF Object Detection API, in TensorFlow.js.
I converted the model using:
tensorflowjs_converter --input_format=tf_saved_model inference_graph/saved_model inference_graph/web_model
It gets converted without any problems and loads in my javascript code.
Now I am a bit unsure about what my next steps should be.
I have to translate the Python into JavaScript, but certain areas I am unsure about.
With the object detection API in python, there are many steps; (1)preprocessing the image, such as convert to RGB, numpy array reshape, expand dimensions (I have an idea of how I would approach it) and (2) the run inference for single image function, I am not sure how I would go about it in tensorflow.js.
I tried to find some general information about deploying an object detection model in tensorflow.js, but I could not find much, except with pre-trained models.
Any information about this topic would be great!
Thanks!
as mentioned by #edkeveked you will need to perform similar input processing and output processing in JavaScript as is being done in Python. i can't say exactly what you will need to do since i am not familiar with the model. however, you can find an example using a specific object detection model here:
https://github.com/vabarbosa/tfjs-model-playground/blob/master/object-detector/demo/object-detector.js
see also
https://medium.com/codait/bring-machine-learning-to-the-browser-with-tensorflow-js-part-iii-62d2b09b10a3
You would need to replicate the same process in javascript before giving it to the model. In js, the image use by default the RGB channel, so there is no need to make that conversion again.

TF Lite object detection only returning 10 detections

I am using a custom object detection model with TensorFlow Lite on native Android. At this point I'm only detecting 2 custom objects. I am using the TensorFlow Object Detection API, and I have a pipeline in place that produces optimized .tflite files.
However, at inference time, the model only returns up to 10 individual detections. According to https://www.tensorflow.org/lite/models/object_detection/overview, this is expected. The problem is that my images have a relatively large object density. I need to be able to detect up to 30 individual objects per image/inference call.
If I change NUM_DETECTIONS in the sample Android app from the TF repo from 10 to, say, 20, I get a runtime exception due to shape mismatch. How can I produce .tflite files capable of yielding more than 10 object detection instances?
Thank you!
Unfortunately, since TFLite prefers static-shaped Input/Outputs, you would need to re-export a TFLite SSD graph with the required number of outputs. Instructions are here. While invoking object_detection/export_tflite_ssd_graph.py, you would need to pass in the parameter --max_detections=20. Then, your change of NUM_DETECTIONS should work as expected.

Realtime Single Object Tracking with TensorFlow.js

I'm putting my first steps in Machine Learning, I went through many TensorFlow.js tutorials already and I'm trying to achieve this: "Realtime Single Object Tracking/Detection"
Something like this -> input: webcam/video -> output: object bounding box
I know there are SSD and YOLO, and other libraries to predict & locate the objects. But the predicted time is very slow (in browser), I guessed it's because the Neural Network have to predict between so many objects.
https://github.com/ModelDepot/tfjs-yolo-tiny
https://github.com/tensorflow/models/tree/master/research/object_detection
What if I just want to track a single object? Would it be possible? Will the performance be better? Where should I start?
I've been thinking about extract the pre-trained class (object) from a SavedModel, then start training more from it. But there don't seems to be any instructions around Google.
I found some fantastic code by IBM, which I used in the video in this tweet: https://twitter.com/GantLaborde/status/1125735283343921152?s=20
I extracted that code to make a ReactJS component for detecting Rock/Paper/Scissors here: https://github.com/GantMan/rps_tfjs_demo/blob/master/src/AdvancedModel.js
If you'd like to play with the demo, it's at the bottom of this page: https://rps-tfjs.netlify.com/
All of this is open source and seems to work perfectly fast for detecting a single object in realtime.