Giter Club home page Giter Club logo

flask-keras-cnn-image-retrieval's Introduction

Image Retrieval Engine Based on Keras

License

演示

演示地址(不能访问,没钱续VPS了),跑在CPU上,web界面采用的SoTu

环境

In [1]: import keras
Using Theano backend.

keras 2.0.1 及 2.0.5 版本均经过测试可用。推荐Python 2.7,支持Python 3.6.

此外需要numpy, matplotlib, os, h5py, argparse. 推荐使用anaconda安装

使用

  • 步骤一

python index.py -database <path-to-dataset> -index <name-for-output-index>

  • 步骤二

python query_online.py -query <path-to-query-image> -index <path-to-index-flie> -result <path-to-images-for-retrieval>

├── database 图像数据集
├── extract_cnn_vgg16_keras.py 使用预训练vgg16模型提取图像特征
|── index.py 对图像集提取特征,建立索引
├── query_online.py 库内搜索
└── README.md

示例

# 对database文件夹内图片进行特征提取,建立索引文件featureCNN.h5
python index.py -database database -index featureCNN.h5

# 使用database文件夹内001_accordion_image_0001.jpg作为测试图片,在database内以featureCNN.h5进行近似图片查找,并显示最近似的3张图片
python query_online.py -query database/001_accordion_image_0001.jpg -index featureCNN.h5 -result database

论文推荐

awesome-cbir-papers

问题汇总

  • query_online.py line 28报错,将index.py line 62注释,使用line 61.

此外,若在使用过程中出现任何问题,请在赞赏留言中留下您的微信,收到消息后我会尽快修复。

A small reward is highly appreciated! (#^.^#) Thank you~

flask-keras-cnn-image-retrieval's People

Contributors

untamed-atlas avatar willard-yuan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-keras-cnn-image-retrieval's Issues

预训练模型与数据集问题

你好!请问这预训练模型的数据集是多大的呀,训练的一些参数可以分享一下吗?数据集是只有database下面的几张图吗?请问有补充的数据集不

Training New Weights?

Currently, imagenet weights are used. Is it possible to train the weights based on the indexing images? (using techniques such as unsupervised learning)

如何使用resnet?

你使用的keras的vgg16相对比较慢, 如果要换成keras的resnet, code哪些部分要改变?谢谢

ValueError: Illegal slicing argument for scalar dataspace

Indexing worked fine

Using TensorFlow backend.
--------------------------------------------------
         feature extraction starts
--------------------------------------------------
2019-02-18 01:14:32.787757: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
extracting feature from image No. 1 , 9 images in total
extracting feature from image No. 2 , 9 images in total
extracting feature from image No. 3 , 9 images in total
extracting feature from image No. 4 , 9 images in total
extracting feature from image No. 5 , 9 images in total
extracting feature from image No. 6 , 9 images in total
extracting feature from image No. 7 , 9 images in total
extracting feature from image No. 8 , 9 images in total
extracting feature from image No. 9 , 9 images in total
--------------------------------------------------
      writing feature extraction results ...
--------------------------------------------------
dgtlmoon@acer:/tmp/flask-keras-cnn-image-retrieval$ ls -al index.save 
-rw-rw-r-- 1 dgtlmoon dgtlmoon 20741 Feb 18 01:14 index.save

but...

$ python query_online.py -query query/541daeb93a3e4cd8a101b7d5e83a6779.jpg -index ./index.save -result result/
Using TensorFlow backend.
[[0.         0.27786013 0.         ... 0.00188846 0.02606245 0.        ]
 [0.05857334 0.06311509 0.03466835 ... 0.         0.         0.        ]
 [0.02201021 0.         0.05797203 ... 0.01631281 0.06619522 0.01133065]
 ...
 [0.03652793 0.         0.01706417 ... 0.         0.10876585 0.        ]
 [0.01404525 0.         0.01023624 ... 0.         0.01086351 0.03146496]
 [0.03362079 0.00451447 0.         ... 0.         0.05480169 0.01739029]]
Traceback (most recent call last):
  File "query_online.py", line 28, in <module>
    imgNames = h5f['dataset_2'][:]
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "/usr/local/lib/python2.7/dist-packages/h5py/_hl/dataset.py", line 463, in __getitem__
    selection = sel2.select_read(fspace, args)
  File "/usr/local/lib/python2.7/dist-packages/h5py/_hl/selections2.py", line 103, in select_read
    return ScalarReadSelection(fspace, args)
  File "/usr/local/lib/python2.7/dist-packages/h5py/_hl/selections2.py", line 88, in __init__
    raise ValueError("Illegal slicing argument for scalar dataspace")
ValueError: Illegal slicing argument for scalar dataspace

提取特征那一步有问题

在提取特征那里,您好像是获取了1000维的score作为特征并不是4096维的特征。希望您看下!

test时出现问题

你好呀~我在执行
python query_online.py -query database/001_accordion_image_0001.jpg -index featureCNN.h5 -result database 的时候提示以下错误是什情况呢?
ValueError: Illegal slicing argument for scalar dataspace

咨询一个大数据量的问题

作者你好,从你的方法当中学到很多。 现在有一个问题想请教一下。 在海量数据的情况下,h5py的读取速度和保存速度会变得越来越慢。 我自己做实验的情况来看,刚开始数据从提取特征到最后查找相似度结束大概用时10ms左右。5w张图片以后, 单h5文件的读取和矩阵计算已经占到200ms以上了。 你这边有没有什么好的经验,如何在海量数据下保证图片处理过程的实时性呢?

problem

test.py: error: the following arguments are required: --database, --index

显存占用过大

跑在gpu上占用了4G的显存 也太大了吧 这个正常吗
Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4278 MB memory)

相似度计算 以及预训练模型问题

有两个问题想请教下:
1.除了余弦相似度以外还有啥比较推荐的相似度计算方式吗
2. 预训练模型是在imagenet上训练的 它的特征为何可以用它其他新的数据集上 作为特征提取??

谢谢

How to get the scores of images?

why do this? thank you for your answer.
scores = np.dot(norm_feat, feats.T) rank_ID = np.argsort(scores)[::-1] rank_score = scores[rank_ID]

关于索引的问题

图像特征求出来之后,普遍的做法是遍历所有的特征求余弦距离,如果特征特别多效率是不是不够高,如何用哈希索引之类来帮助我们在保持精度的情况下更高效的进行检索呢? @

flask

大哥
flask 有和这个代码 配合的flask界面了吗

请问有相关论文吗?

您好,感谢您的分享! 因为我还是个图像检索方面的小白,所以想系统地学习一下,请问这个项目您是根据哪篇论文做出来的吗? 或者是什么其他的理论资料呢? 谢谢了!!期待您的回复

预训练模型问题

请问预训练模型来提取的特征 但是对于新的图片集这样的特征为何有用呀?
谢谢

一个调试时出现的问题

你好,我在ubuntu下尝试配置这个代码,但是碰到了一些问题

alec@alec-CP65S://home/alec/cnncode/flask-retrival$ python extract_CNN_VGG_Keras.py
Using Theano backend.
Traceback (most recent call last):

File "extract_CNN_VGG_Keras.py", line 102, in out = model.predict(im)
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 724, in predict
return self.model.predict(x, batch_size=batch_size, verbose=verbose)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 1269, in predict`
...
...
File "/usr/local/lib/python2.7/dist-packages/theano/gof/cmodule.py", line 302, in dlimport
rval = import(module_name, {}, {}, [module_name])

ImportError: ('The following error happened while compiling the node', CorrMM{valid, (1, 1), (1, 1)}(IncSubtensor{InplaceSet;::, ::, int64:int64:, int64:int64:}.0, Subtensor{::, ::, ::int64, ::int64}.0), '\n', '/home/alec/.theano/compiledir_Linux-4.2--generic-x86_64-with-Ubuntu-14.04-trusty-x86_64-2.7.6-64/tmpQAGgtF/c4bfcd4af5f141b0dbcc5236ff225cfd.so: undefined symbol: openblas_get_num_threads', '[CorrMM{valid, (1, 1), (1, 1)}(<TensorType(float32, 4D)>, <TensorType(float32, 4D)>)]')

应该是out = model.predict(im)中传递的参数有问题?尝试了几种图像,感觉应该不是数据集的问题,但是不知道怎么调整了,想请教一下...

还有个疑问就是,这份代码关于图像检索的部分是不是就是extract_CNN_VGG_Keras.py和searchDemo.py两个文件,deep_dream.py是与此无关的是吗?

和triplet loss计算的差异

你好
我正在尝试你的作品。
请教一个问题,请问该方法总结来说是以下方法吗?
用vgg16模型提取query image的特征,再依次做相似度计算,取出相似度最高的图片。
请问以上方法适用于「相似服装」的查找吗。

市面上相似服装的查找的方法最近有triplet loss的方法。请问triplet loss方法和本方法都有哪些差异呢。
谢谢

index.py在python3.6下报错TypeError: No conversion path for dtype: dtype('<U28')

报错代码:h5f.create_dataset('dataset_2', data = names)
原因:create_dataset 只接受 ascii 的数据,如果你是Python3或者python使用utf-8的编码就会报错。
解决办法:
#h5f.create_dataset('dataset_2', data = names)
namess = []
for j in names:
namess.append(j.encode())
h5f.create_dataset('dataset_2', data = namess)
h5f.close()

Is relying on top weights always what the user should expect?

Sort of mentioned in #14 , but more specifically I think the problem is that model.extract_feat(img_path) in index.py is always looking at the top/last layer which is the most 'abstract' in VGG16, so if the network can get a good confidence score on something like seeing a dog in the image, then other images will always be 'similar'.

(Because we are using the existing trained weights)

I'm not totally sure what todo , but feels to me like the network should pull features from a middle layer, so that it's comparing edges, lines, and other low level objects instead of high level abstract information? thoughts?

for example

  • If I have a lot of photos of paintings, but I want to search for very similar paintings.. the photos with the border/frame around the painting will always be more 'similar' regardless of the contents of the painting

请教下flask界面问题

大佬好、请教下 你写的flask web界面代码方便分享一下吗,我只看到了soutu这个、好像跟你使用的这个特征不太一样、这个使用的界面代码方便分享一下吗

后续有考虑优化吗?

感谢整理分享的论文!
看了下您的实现,用VGG16提取特征,把两张图片的点积作为相似分数,后续有考虑优化吗?

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.