If you're running fastdup for the first time, we recommend to run this tutorial on Google Colab.
Or if you're feeling adventurous, feel free to install on your machine and proceed. For a detailed list of installation options and supported platforms, see our installation guide.
In most cases you can install fastdup with:
pip install fastdup
To verify the installation, run:
import fastdup fastdup.__version__
This should show the version of fastdup you've installed.
This tutorial runs on version
We'll use the Oxford-IIIT Pet Dataset which contains 7,300 images of cats and dogs from 37 breeds.
Let's download and unzip the images with:
wget https://thor.robots.ox.ac.uk/~vgg/data/pets/images.tar.gz tar xvf images.tar.gz
Once done you should end up with a folder
images/ in your root directory.
It only takes 3 lines of code to run fastdup:
import fastdup fd = fastdup.create(work_dir="fastdup_work_dir/", input_dir="images/") fd.run()
work_dir- Path to store the artifacts generated from the run.
input_dir- Path to the images.
fastdup will start analyzing the dataset for potential issues. How long it takes to complete the run depends on your computing power.
On Google Colab (free version with 2 CPU cores) it take a little over 3 minutes to complete the run!
Once the run finishes, we can visualize all the issues found.
This is one of the most common issues with image dataset. The images could be broken or corrupted. fastdup keeps track of all invalid images it encounters during the run.
To view the details of the invalid images, simply run:
which outputs a
Broken images is something we did not expect to see especially with a curated dataset like the Oxford IIT Pet Dataset. But this shows how easily you can detect them with fastdup with just one line of code.
Let's now visualize if there are any duplicates with:
Under the hood
The above gallery shows duplicate pairs computed using the
cosinedistance. A distance of
1.0indicate the image pair is an exact duplicate.
TIP: You can specify
num_imagesas a parameter to
fd.vis.duplicates_galleryto see more or less image pairs. For example:
Similar to duplicate pairs, you can visualize potential outliers in your dataset with:
As you can see, not all images in the outliers report are true outliers. The images appear on the report simply because it looks different from other images in the dataset (distance wise).
As a curator, you'd need to verify if they are true outliers by inspecting the report.
fastdup also lets you visualize images from your dataset using statistical metrics.
For example, with
metric='dark'we can visualize the darkest images from the dataset.
metric='bright'populates the gallery with the brightest images on top.
metric='blur'shows the blurriest images on top.
Verify dark, bright and blurry images
Again, we see that not all images in the statistical visualization gallery are problematic. As a curator, you'd need to verify and filter out the problematic images.
Since the Oxford Pets Dataset is a curated dataset, we'd not expect to find extremely bright, dark or blurry images.
One of fastdup's coolest feature is visualizing image clusters. In the previous section we saw how to visualize similar image pairs. In this section we group similar looking image (or even duplicates) as a cluster and visualize them in gallery.
To do so, simply run:
Clusters are known as 'components' in fastdup. You'd see the term 'component' used more frequently in code and documentations.
So there you have it. With few lines of code you can quickly sift through thousands of images in your dataset for potential issues. Not to mention, you can run it just by using Google Colab, with limited compute resource!
In this tutorial we've seen how to use fastdup to find:
- Broken images.
- Duplicate image pairs.
- Dark, bright and blurry images.
- Image clusters.
What to do about all the problematic images? You can decide to keep or eliminate them. Check out the next tutorial!
Updated about 1 month ago
Now that we found some issues related to the dataset, let's see how do we clean and curate the dataset in the next section