文章目录
一、FastDup 简介
github开源地址:FastDup | A tool for gaining insights from a large image collection
github发布时间:2022年5月
FastDup可以发现异常,重复和接近重复的图像,相似性聚类,学习规范行为和图像之间的时间交互。 它可以用于更高质量数据集的智能子采样、异常值去除、要发送标记的新信息的新颖性检测。 FastDup仅仅在CPU中运行就可以查找数百万张图像。
二、安装 FastDup库
For Python 3.7 and 3.8 (Ubuntu 20.04 or Ubuntu 18.04 or Mac M1):
python3.8 -m pip install fastdup
注:windows 系统中无法安装 fastdup
下面是在 Ubuntu 18.04 中安装成功的示例:
三、使用 FastDup
3.1 相似性度量
FastDup 默认采用的距离度量是余弦距离(cosine distance),两张图片的 distance 取值范围为 [0,1] ;distance越大,则相似度越高。FastDup 中两张图片的相似性度量为:
totally identical images (distance = 1)
identical images (distance > 0.990)
nearly identical images (d > 0.980)
above threshold images (d > 0.900)
outlier images (d < 0.050)
其中distance的范围并没有什么意义,因为这不是一个绝对固定的值,我们可以根据需求自行设置。
3.2 测试代码
代码仓中的 example 文件夹下有用 food-101 数据集的示例代码,这里使用自己的数据集进行测试。
import os
import fastdup
from IPython.display import HTML
# Running FastDup on the your dataset
# 数据集图片可以都放在一个文件夹中,也可以分成几个子文件夹。
# 程序会遍历给定路径下的所有子文件夹和图像文件。
input_dir = '../dataset/logo'
results_dir = '../results/logo'
fastdup.run(input_dir=input_dir, work_dir=results_dir)
# Detecting Top-15 Duplicated Image Pairs
# 检测完全相同的前15组图片(distance>0.990)
num_images_dupllicated=15
save_path_dupllicated = os.path.join(results_dir, 'dupllicated-gallery-top')
if not os.path.exists(save_path_dupllicated):
os.mkdir(save_path_dupllicated)
fastdup.create_duplicates_gallery(os.path.join(results_dir, 'similarity.csv'),
save_path_dupllicated, num_images=num_images_dupllicated, descending=True)
gallery_file_name_dupllicated = os.path.join(save_path_dupllicated, 'similarity.html')
HTML(filename=gallery_file_name_dupllicated)
"""
文件重命名
代码中的 similarity.csv 和 similarity.html 不能改文件名
但 dupllicated-gallery-top 和 similar-gallery-top 下面的html文件都叫 similarity.html 显然不合理
因此将 dupllicated-gallery-top 文件夹下面的 similarity.html 重命名为 dupllicated.html
"""
os.rename(gallery_file_name_dupllicated,os.path.join(save_path_dupllicated, 'dupllicated.html'))
# Searching for Top-15 Semantically Similar Images
# 检测相似的前15组图片(distance>0.908)
num_images_similar