Object detectors usually just give out confidence scores with the detections and they usually are not the measurement of how sure a model is in classifying or localizing that object. In this approach we are trying to gain a measurement of how sure a model is in estimating the probability that an object belongs to a certain class of interest (i.e. semantic uncertainity).
For each element of the anticipated anchors
We compute the log-likelihood of the data
A low negative log-likelihood represents a low uncertainty the detected object belongs to the respective known class.
-
Clone repo and install
requirements.txt
in a Python>=3.7.0 environment, including PyTorch>=1.7.git clone https://github.com/visionrd-ai/uncertainty-yolo # clone cd uncertainty-yolo pip install -r requirements.txt # install
-
For this repo, we have used YOLOv5 by Ultralytics. You can head over to their repo if you face any issues with the installation.
detect.py
runs inference on a variety of sources, downloading pre-trained models automatically from the latest YOLOv5 release and saving results to runs/detect
.
python detect.py --source 0 # webcam
img.jpg # image
vid.mp4 # video
screen # screenshot
path/ # directory
'path/*.jpg' # glob
'https://youtu.be/Zgi9g1ksQHc' # YouTube
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream
We have cloned the code from YOLOv5 and added our approach into it. We only modified detect.py
and utils/general.py
. We modified the non_max_suppression
function in order to return the probabilities of all classes with every bounding box. We then added a custom calculate_uncertainty
function to calculate uncertainties and then plot them with confidences and bounding boxes.
In order to improve this work, prior probabilities of the same object can be used to calculate uncertainties.
We are working to normalize the measure of uncertainties so that they can be compared object-wise as well as class-wise during inference.
This approach can also be used for scenarios extraction i.e to track the instances/objects where the model will fail. Some examples of advanced use cases of the above mentioned approach are given below:
An unusual pickup truck is being detected by the model but it is uncertain on it.
An unusual bike carrying sacks is being detected by the model but it is uncertain on it.
It is indispensable for companies working in autonomous driving to capture uncertainties to make their autonomous vehicles safe for public use. Consider an autonomous vehicle operating in an Asian environment where it encounters a rickshaw or a tricycle etc. which are quite comman in Asian environments but are very rare in western environments where most of the models are trained. The models will become uncertain and there will be a huge risk of failure. This failure is very dangerous for companies in autonomous sector therefore we see companies like Bosch, Audi etc. investing heavily in gathering data from Asian and African environments.
- We thank Ultralytics for their awesome work on YOLOv5.
- Uncertainty for Identifying Open-Set Errors in Visual Object Detection
Please follow and visit us VisionRD!