使用elasticSearch实现以图搜图

使用elasticSearch实现以图搜图

逛github的时候发现了这个有趣的项目

项目地址:https://github.com/sethuiyer/Image-to-Image-Search

实现原理

使用CaptionGenerator对图片生成说明

CaptionGenerator可以识别某一个图片并生成描述该图片的语言

比方说下面这张图片,CaptionGenerator会生成:一个男人在冲浪

image-20220721153249335

将生成的图片描述和图片地址保存到elasticsearch

查询图片时生成查询图片的描述,将此描述放到elasticsearch去进行匹配,以此显示出匹配度相近的图片

快速安装

elasticsearch只能在linux系统上安装,所以需要一台虚拟机或者是云服务器,Python程序可以跑在云服务器或者是本地

我的配置:

  • elasticsearch6.0

  • java1.8

  • centos7.6

  • python3.6

实现步骤:

  1. 安装好以上环境

  2. 下载项目到本地https://github.com/sethuiyer/Image-to-Image-Search

  3. 将此模型https://cs.stanford.edu/people/karpathy/neuraltalk/flickr8k_cnn_lstm_v1.zip下载解压后放入models 文件夹下

  4. 根据requirements.txt文件安装Python包,下面的是我自己改的requirements.txt,按照项目里的版本跑不了

    absl-py==0.7.1
    astor==0.7.1
    bleach==3.3.0
    Click==7.0
    elasticsearch==6.3.1
    enum34==1.1.6
    Flask==1.0.3
    gast==0.2.2
    grpcio==1.19.0
    h5py==2.9.0
    html5lib==0.9999999
    itsdangerous==1.1.0
    Jinja2==2.11.3
    Keras==2.2.4
    Keras-Applications==1.0.7
    Keras-Preprocessing==1.0.9
    Markdown==3.1
    MarkupSafe==1.1.1
    mock==2.0.0
    numpy==1.16.2
    pbr==5.1.3
    Pillow==8.1.1
    protobuf==3.7.1
    PyYAML==5.4
    scipy==1.2.1
    six==1.12.0
    tensorboard==1.13.1
    tensorflow==2.4.0
    tensorflow-estimator==1.13.0
    tensorflow-tensorboard==0.1.8
    termcolor==1.1.0
    urllib3==1.24.2
    Werkzeug==0.15.3
    
  5. 如果你的项目和elasticsearch在一台机子上就跳过,否则需要将文件server.pyindex_database.py里的es = Elasticsearch()改为es = Elasticsearch([{'host': 'xxx', 'port': 9200}], timeout=3600),xxx改为安装了elasticsearch机子的ip

  6. 运行index_database.py,添加信息到elasticsearch,可以访问http://xxx:9200/desearch/_search查看是否添加成功

  7. 接着运行server.py,启动web服务,打开http://127.0.0.1:5000/search即可搜图

image-20220721154837603
image-20220721154915886image-20220721155224511
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值