【FastDup】可以查找重复、相似、异常的图像的python库

一、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=
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ctrl A_ctrl C_ctrl V

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值