Setting Up
You can follow along this tutorial by running this notebook on Google Colab First, install fastdup with:bash
Python
0.906.
Download Dataset
We will be using thecoco minitrain dataset for this tutorial.
coco-minitrainis a curated mini training set (25K images ≈ 20% of train2017) from the original COCO dataset.
Let’s download the images and .csv annotations of the coco-minitrain dataset.
Load annotations
We will use a simple converter to convert the COCO format JSON annotation file into the fastdup annotation dataframe. This converter is applicable to any dataset which uses COCO format.| img_filename | bbox_x | bbox_y | bbox_w | bbox_h | label | ext | split | |
|---|---|---|---|---|---|---|---|---|
| 0 | 000000131075.jpg | 20 | 55 | 313 | 326 | tv | 0 | train |
| 1 | 000000131075.jpg | 176 | 381 | 286 | 136 | laptop | 0 | train |
| 2 | 000000131075.jpg | 369 | 361 | 72 | 73 | laptop | 0 | train |
Run fastdup
Get class statistics
Class distribution
The dataset contains 25k images and 183k objects, an average of 7.3 objects per image. Interestingly, we see a highly unbalanced class distribution, where all 80 coco classes are present here, but there is a strong balance towards the person class, that accounts for over 56k instances (30.6%). Car and Chair classes also contain over 8k instances each, while at the bottom of the list the toaster and hair drier classes contain as few as 40 instances. UsingPlotly we get a useful interactive histogram.
Find outliers and duplicates for specific classes
Similarity Clusters
First we visualize the general lists of duplicates and outliers, by default it is sorted by the number of elements:
Sorting by the largest objects
A few notable examples
Further down the gallery, a few examples of objects that might be erroneous or mislabeled.
- In the red cup image, we see individual cups in the sleeve that are barely visible get a small bounding box that captures only the lip of the cup. For many cases, this kind of annotation is not useful.
- In the cake image we can see the same object, annotated three times, each time with a different label (fork, knife and spoon) - in reality, it is very hard to tell what it actually is.
Showing galleries for a specific object class
Now we’ll slice the gallery according specific classes - let’s look at the ‘person’ class
Visualizing outliers
Find size and shape issues
Objects come in various shapes and sizes, and some times objects might be incorrectly labeled or too small to be useful. We will now find the smallest, narrowest and widest objects, and asses their usefulness.| img_filename | bbox_x | bbox_y | bbox_w | bbox_h | label | ext | split | fastdup_id | error_code | is_valid | area | aspect | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| fd_index | |||||||||||||
| 16444 | 000000535145.jpg | 185 | 227 | 10 | 10 | apple | 0 | train | 16444 | VALID | True | 100 | 1.0 |
| 44855 | 000000553446.jpg | 332 | 229 | 10 | 10 | sports ball | 0 | train | 44855 | VALID | True | 100 | 1.0 |
| 32115 | 000000283323.jpg | 138 | 200 | 10 | 10 | car | 0 | train | 32115 | VALID | True | 100 | 1.0 |
| img_filename | bbox_x | bbox_y | bbox_w | bbox_h | label | ext | split | fastdup_id | error_code | is_valid | area | aspect | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| fd_index | |||||||||||||
| 134869 | 000000093298.jpg | 230 | 1 | 16 | 419 | kite | 0 | train | 134869 | VALID | True | 6704 | 0.038186 |
| 3642 | 000000002444.jpg | 1 | 136 | 11 | 263 | person | 0 | train | 3642 | VALID | True | 2893 | 0.041825 |
| 164218 | 000000116502.jpg | 222 | 63 | 16 | 318 | spoon | 0 | train | 164218 | VALID | True | 5088 | 0.050314 |
| img_filename | bbox_x | bbox_y | bbox_w | bbox_h | label | ext | split | fastdup_id | error_code | is_valid | area | aspect | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| fd_index | |||||||||||||
| 77844 | 000000444692.jpg | 0 | 177 | 640 | 19 | bench | 0 | train | 77844 | VALID | True | 12160 | 33.684211 |
| 77850 | 000000444692.jpg | 1 | 58 | 638 | 15 | bench | 0 | train | 77850 | VALID | True | 9570 | 42.533333 |
| 173220 | 000000516740.jpg | 17 | 197 | 601 | 13 | train | 0 | train | 173220 | VALID | True | 7813 | 46.230769 |
Objects that didn’t make the cut:
Let’s look at objects deemed invalid by fastdup. These are either objects that are too small to be useful in our analysis (smaller than 10px), have bouding boxes with illeagal values (negative or beyond image boundaries), or are part of images that are missing. We can tell which is which by theerror_code column in our dataframe.
| img_filename | bbox_x | bbox_y | bbox_w | bbox_h | label | ext | split | fastdup_id | error_code | is_valid | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 000000262162.jpg | 437 | 244 | 19 | 9 | mouse | 0 | train | 16 | ERROR_BAD_BOUNDING_BOX | False |
| 1 | 000000524325.jpg | 137 | 332 | 8 | 11 | person | 0 | train | 60 | ERROR_BAD_BOUNDING_BOX | False |
| 2 | 000000524325.jpg | 177 | 294 | 5 | 11 | person | 0 | train | 65 | ERROR_BAD_BOUNDING_BOX | False |
Distribution of error codes:
A simplevalue_counts will tell us the distribution of the errors. We have found 18,592 (!) bounding boxes that are either too small or go beyond image boundaries. This is 10% of the data! Filtering them would both save us gruesome debugging of training errors and failures and help up provide the model with useful size objects.
Find possible mislabels
The fastdup similarity search and gallery is a strong tool for finding objects that are possibly mislabeled. By finding each object’s nearest neighbors and their classes, we can find objects with classes contradicting their neighbors’ - a strong sign for mislabels. Let’s visualize one of the more popular classes - ‘chair’:
In the images above we see the many mislabeled ‘chair’ bounding boxes. There are multiple ‘person’ labeled as ‘chair’.
This would be a good opportunity to go over the labeling definitions for both classes, and find cases where mix-ups can occur.
A next step could be a deeper dive into all images labeled as either chair or couch, with a lower value of clustering threshold (the ccthreshold parameter in .run()).
Summary
👍 We have shown multiple annotation issues for the mini-coco 25k image dataset First, we looked at the class distribution, showing that some classes contain only a few dozen objects, which are not enough for reliable results. Then we used fastdup to run an analysis and visualize both duplicate and outlier images, sorting according to various metrics - object size, similarity cluster image count, and mean cluster similarity score, surfacing all sorts of objects that could be removed to improve results. Afterwards, we analyzed the bounding boxes for size and aspect ratio issues, and found over 18k object bounding boxes that are too small to be useful for most cases. Finally, for finding mis-labels we looked into the most similar images in a specific class, and uncovered a common mixup between chair and couch classes. This is just a taste of fastdup label capabilities, which will be covered in further tutorials. Looking for finding mislabels at scale? Sign up for fastdup enterprise.