Git Product home page Git Product logo

imsearch's Introduction

imsearch

基于特征点匹配的的局部图像搜索工具

主要基于以下项目:

  • ORB_SLAM3 - 解决了传统 ORB 算法中存在的特征点过于集中的问题
  • faiss - 对大规模向量进行搜索

安装方式

  1. 安装 OpenCV、faiss

注:编译 faiss 时建议设置 -DFAISS_OPT_LEVEL=avx2 以最大化性能

  1. cargo install --git https://github.com/lolishinshi/imsearch

用法

训练

首次运行时,需要根据大概需要添加的图片数量训练索引:

  • 2k ~ 2w: K 取 65536,需要至少 5.2k 张图片训练
  • 2w ~ 20w:K 取 262144,至少需要 21k 张图片训练
  • 20w ~ 200w:K 取 1048576,至少需要 82k 张图片训练

然后将训练图片放到 train 文件夹内,并使用 imsearch add-images train 添加图片

再使用 imsearch export-data 导出 train.npy

再使用 python utils/train.py K train.npy 训练索引, 训练完的结果会保存在 ~/.config/imsearch/index

注:大数据集上的训练非常耗时,在 K = 1048576,训练图片为 100k 张时,两张 3080 花了 16 个小时才训练完成。

添加图片

使用 imsearch add-images DIR 添加指定目录下的所有图片

构建索引

使用 imsearch build-index 构建索引,这个过程同样非常慢,在 3970x 上,需要约 20~40 分钟构建 10k 张图片的索引

注:可以设置 RUST_LOG=debug 来打印详细日志以观察进度

搜索图片

# 让 imsearch 打印详细日志
export RUST_LOG=debug

# 以默认参数直接搜索单张图片
imsearch search-image test.jpg

# --mmap:不需要加载整个 index 到内存
# --nprobe=128:搜索附近的 128 的 bucket,提高了精度但耗费更多时间
imsearch --mmap --nprobe=128 search-image test.jpg

# 启动服务器,监听 127.0.0.1:8000 端口
imsearch --mmap start-server

# 使用 httpie 通过 web api 搜索图片
http --form http://127.0.0.1:8000/search [email protected]

搜索耗时:250w 张图片的索引,在 3970x 上搜索一次耗时约 0.5s

imsearch's People

Contributors

aloxaf avatar soutubot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.