Giter Site home page Giter Site logo

flyingpot / pytorch_deephash Goto Github PK

View Code? Open in Web Editor NEW
184.0 8.0 49.0 28 KB

Pytorch implementation of Deep Learning of Binary Hash Codes for Fast Image Retrieval, CVPRW 2015

License: MIT License

Python 100.00%
pytorch deep-learning deephash hash image-retrieval

pytorch_deephash's Introduction

pytorch_deephash

Introduction

This is the Pytorch implementation of Deep Learning of Binary Hash Codes for Fast Image Retrieval, and can achieve more than 93% mAP in CIFAR10 dataset.

Environment

Pytorch 1.4.0

torchvision 0.5.0

tqdm

numpy

Training

python train.py

You will get trained models in model folder by default, and models' names are their test accuracy.

Evaluation

python evaluate.py --pretrained {your saved model name in model folder by default}

Tips

  1. If using Windows, keep num_works zero

  2. There are some other args, which you can get them by adding '-h' or reading the code.

pytorch_deephash's People

Contributors

flyingpot avatar intsigstephon 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

pytorch_deephash's Issues

About multi-label

Hello, I found that this paper deals with single-label datasets,do you know if this paper can process multi-label datasets?

Help with another implementation

Hi @flyingpot

There is an extension of this work available here: https://github.com/kevinlin311tw/Caffe-DeepBinaryCode. I would like to port to Pytorch, but I do not understand much of Caffe. Could you help me? Where I could start? As it is an extension of this work that you implemented I think I can utilize your implementation. I just need to implement for CIFAR-10, so I guess I just need to implement the final part of the network that generates the hashing codes.

Transfer Learning

Hi @flyingpot,

Thank you for shared with us your project. I would like to use your implementation with a net that I developed myself in place of AlexNet. In that case I would have to modify the net.py file to get the features of my model, but I'm having difficulty. Could you help me?

训练集大于10类时,训练报错

您好,借用您的代码,用自己的图片进行训练时:
trainset = datasets.ImageFolder(root='data/out', transform=transform_train)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=128,
shuffle=True, num_workers=2)

如果'data/out下的分类大于10时,程序就会报错:
RuntimeError: cuda runtime error (59) : device-side assert triggered at /pytorch/aten/src/THCUNN/generic/Threshold.cu:67

您知道是什么原因吗?

测试检索时的问题

您好,借用您的代码,将网络模型换为了VGG16,训练之后进行mAP测试时,直接用:python mAP.py --pretrained 测试的话,程序返回给我的mAP达到了91%.
但是我无法确认这个结果的准确性,我对训练集图片进行了标识,然后sort_indices数组的前20位出来当做索引,但是这20个图片所对应的图片都不是我所检索的图片。
想请教一下,如果我想要返回单次检索的top10,应该如何做?或者说mAP返回的准确率是基于top几的数据来计算的。
期待您的回复。

Precision for multilabel

Hi @flyingpot,
I'm sorry to bother you again. I modified the model to train on a multilabel base, but I'm having difficulty calculating the map. Your function that calculates map is this here:

for i in range(query_times):
        print('Query ', i+1)
        query_label = tst_label[i]
        query_binary = tst_binary[i,:]
        query_result = np.count_nonzero(query_binary != trn_binary, axis=1)    #don't need to divide binary length
        sort_indices = np.argsort(query_result)
        buffer_yes= np.equal(query_label, trn_label[sort_indices]).astype(int)
        P = np.cumsum(buffer_yes) / Ns
        AP[i] = np.sum(P * buffer_yes) /sum(buffer_yes)
    map = np.mean(AP)
    print(map)

How would that line of code look buffer_yes= np.equal(query_label, trn_label[sort_indices]).astype(int) to return relevant if it has at least one correct label? The image label consists of an array of 0s and 1s of size 21 where 1 corresponds to that label exists for that image. Thank you so much.

The value of loss function

Hello. When using AlexNet for classification, the accuracy is higher, but after adding the hidden layer, the accuracy is very low. Do you know the reason?The value of my loss function has been maintained at around 2. Did your loss function fall faster? Thank you.

train.py error

你好,我在run train.py的时候出现一个错误,poch: 1
Traceback (most recent call last):
File "", line 1, in
File "D:\tk2018\lib\multiprocessing\spawn.py", line 106, in spawn_main
exitcode = _main(fd)
File "D:\tk2018\lib\multiprocessing\spawn.py", line 115, in _main
prepare(preparation_data)
File "D:\tk2018\lib\multiprocessing\spawn.py", line 226, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "D:\tk2018\lib\multiprocessing\spawn.py", line 278, in _fixup_main_from_path
run_name="mp_main")
File "D:\tk2018\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "D:\tk2018\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "D:\tk2018\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\bi ye she ji 2020\pytorch_deephash-master\train.py", line 124, in
train(epoch)
File "D:\bi ye she ji 2020\pytorch_deephash-master\train.py", line 71, in train
for batch_idx, (inputs, targets) in enumerate(trainloader):
File "D:\tk2018\lib\site-packages\torch\utils\data\dataloader.py", line 501, in iter
return _DataLoaderIter(self)
File "D:\tk2018\lib\site-packages\torch\utils\data\dataloader.py", line 289, in init
w.start()
File "D:\tk2018\lib\multiprocessing\process.py", line 105, in start
self._popen = self._Popen(self)
File "D:\tk2018\lib\multiprocessing\context.py", line 212, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "D:\tk2018\lib\multiprocessing\context.py", line 313, in _Popen
return Popen(process_obj)
File "D:\tk2018\lib\multiprocessing\popen_spawn_win32.py", line 34, in init
prep_data = spawn.get_preparation_data(process_obj._name)
File "D:\tk2018\lib\multiprocessing\spawn.py", line 144, in get_preparation_data
_check_not_importing_main()
File "D:\tk2018\lib\multiprocessing\spawn.py", line 137, in _check_not_importing_main
is not going to be frozen to produce an executable.''')
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

Traceback (most recent call last):
File "D:/bi ye she ji 2020/pytorch_deephash-master/train.py", line 124, in
train(epoch)
File "D:/bi ye she ji 2020/pytorch_deephash-master/train.py", line 71, in train
for batch_idx, (inputs, targets) in enumerate(trainloader):
File "D:\tk2018\lib\site-packages\torch\utils\data\dataloader.py", line 501, in iter
return _DataLoaderIter(self)
File "D:\tk2018\lib\site-packages\torch\utils\data\dataloader.py", line 289, in init
w.start()
File "D:\tk2018\lib\multiprocessing\process.py", line 105, in start
self._popen = self._Popen(self)
File "D:\tk2018\lib\multiprocessing\context.py", line 212, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "D:\tk2018\lib\multiprocessing\context.py", line 313, in _Popen
return Popen(process_obj)
File "D:\tk2018\lib\multiprocessing\popen_spawn_win32.py", line 66, in init
reduction.dump(process_obj, to_child)
File "D:\tk2018\lib\multiprocessing\reduction.py", line 59, in dump
ForkingPickler(file, protocol).dump(obj)
BrokenPipeError: [Errno 32] Broken pipe
请问这个问题如何解决,谢谢

multi gpu problem

when I use multi gpu to train, the map value is decreased compare to the single gpu with the same parameters

How to output path, the name of the picture?

Hello, because I am a novice to the code is not skilled. I want to know how to output a query image and the query to the top 10 image database, image path.
Thank you for your reply!

mAP is zero,see the log below

('Query ', 9981)
('Query ', 9982)
('Query ', 9983)
('Query ', 9984)
('Query ', 9985)
('Query ', 9986)
('Query ', 9987)
('Query ', 9988)
('Query ', 9989)
('Query ', 9990)
('Query ', 9991)
('Query ', 9992)
('Query ', 9993)
('Query ', 9994)
('Query ', 9995)
('Query ', 9996)
('Query ', 9997)
('Query ', 9998)
('Query ', 9999)
('Query ', 10000)
0.0
('total query time = ', 98.12934589385986)

pytorch's version is 0.3.1 and torchvision is 0.2
that's master about pytorch's version?
call you do me a favour? thx
@flyingpot

Why the value of mAP in the mAP.py is not change?

Thanks for your working!
I have run the train.py as the Readme.md. However, when I change the model's pretrained mode the value of mAP is not change, and it's always be 0.9445986000121745. I want to do some change job on your work, thanks again!

from coarse to fine searching

Thank you very much for the code, but did you implement the search process from coarse to fine when searching? I didn't see it specifically in the code, I would like to trouble you to help me solve this problem!

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.