Giter Club home page Giter Club logo

cvpr15deepcompare's Introduction

Code for CVPR15 paper "Learning to Compare Image Patches via Convolutional Neural Networks"

This package allows researches to apply the described networks to match image patches and extract corresponding patches.

We tried to make the code as easy to use as possible. The original models were trained with Torch ( http://torch.ch ) and we release them in Torch7 and binary formats with C++ bindings which do not require Torch installation. Thus we provide example code how to use the models in Torch, MATLAB and with OpenCV http://opencv.org

CREDITS, LICENSE, CITATION

Copyright © 2015 Ecole des Ponts, Universite Paris-Est

All Rights Reserved. A license to use and copy this software and its documentation solely for your internal research and evaluation purposes, without fee and without a signed licensing agreement, is hereby granted upon your download of the software, through which you agree to the following:

  1. the above copyright notice, this paragraph and the following three paragraphs will prominently appear in all internal copies and modifications;
  2. no rights to sublicense or further distribute this software are granted;
  3. no rights to modify this software are granted; and
  4. no rights to assign this license are granted.

Please Contact Prof. Nikos Komodakis, 6 Avenue Blaise Pascal - Cite Descartes, Champs-sur-Marne, 77455 Marne-la-Vallee cedex 2, France for commercial licensing opportunities, or for further distribution, modification or license rights.

Created by Sergey Zagoruyko and Nikos Komodakis. http://imagine.enpc.fr/~komodakn/

Please cite the paper below if you use this code in your research.

Sergey Zagoruyko, Nikos Komodakis, "Learning to Compare Image Patches via Convolutional Neural Networks". http://www.cv-foundation.org/openaccess/content_cvpr_2015/papers/Zagoruyko_Learning_to_Compare_2015_CVPR_paper.pdf, bib:

@InProceedings{Zagoruyko_2015_CVPR,
	author = {Zagoruyko, Sergey and Komodakis, Nikos},
	title = {Learning to Compare Image Patches via Convolutional Neural Networks},
	booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
	month = {June},
	year = {2015}
}

Update 4 (April 2017) dead links for models and datasets fixed

Update 3 (July 2016) training code released

Update 2 (February 2016) caffe models released

Update 1 (January 2016) cudnn models removed because cudnn.convert was out

Dataset

The original dataset website is down, you can still download the files here:

http://icvl.ee.ic.ac.uk/vbalnt/notredame.zip
http://icvl.ee.ic.ac.uk/vbalnt/yosemite.zip
http://icvl.ee.ic.ac.uk/vbalnt/liberty.zip

Models

We provide the models in Torch7 and binary format. The table from the paper is here for convenience.

All models expect input patches to be in [0;1] range before mean subtraction.

The models are not supposed to give outputs in [0;1] range, the outputs are not normalized

Train set Test set 2ch 2ch2stream 2chdeep siam siam2stream
yosemite notredame 2.74 2.11 2.43 5.62 5.23
yosemite liberty 8.59 7.2 7.4 13.48 11.34
notredame yosemite 6.04 4.09 4.38 13.23 10.44
notredame liberty 6.04 4.85 4.56 8.77 6.45
liberty yosemite 7 5 6.18 14.76 9.39
liberty notredame 2.76 1.9 2.77 4.04 2.82

Models in nn format can be loaded and used without CUDA support in Torch. To enable CUDA support model:cuda() call required.

An archive with all models (binary and in torch format) is available at: https://s3.amazonaws.com/modelzoo-networks/cvpr2015matching_networks.tar.gz

Torch

To install torch follow http://torch.ch/ Check torch folder for examples. Match patches on CPU:

require 'nn'

N = 76  -- the number of patches to match
patches = torch.rand(N,2,64,64):float()

-- load the network
net = torch.load'../networks/2ch/2ch_liberty.t7'

-- in place mean subtraction
local p = patches:view(N,2,64*64)
p:add(-p:mean(3):expandAs(p))

-- get the output similarities
output = net:forward(patches)

Conversion to a faster cudnn backend is done by cudnn.convert(net, cudnn) function.

C++ API

The code was tested to work in Linux (Ubuntu 14.04) and OS X 10.10, although we release all the source code to enable usage in other operating systems.

We release CUDA code for now, CPU code might be added in the future. To install it you need to have CUDA with the up-to-date CUDA driver (those are separate packages).

Install TH and THC:

cd /tmp
git clone https://github.com/torch/torch7.git
cd torch7/lib/TH
mkdir build; cd build
cmake ..; make -j4 install
cd /tmp
git clone https://github.com/torch/cutorch.git;
cd cutorch/lib/THC
mkdir build; cd build
cmake ..; make -j4 install

Clone and compile this repository it with:

git clone --recursive https://github.com/szagoruyko/cvpr15deepmatch
cd cvpr15deepmatch
mkdir build; cd build;
cmake .. -DCMAKE_INSTALL_PREFIX=../install
make -j4 install

Then you will have loadNetwork function defined in src/loader.h, which expects the state and the path to a network in binary format on input. A simple example:

THCState *state = (THCState*)malloc(sizeof(THCState));
THCudaInit(state);

cunn::Sequential::Ptr net = loadNetwork(state, "networks/siam/siam_notredame.bin");

THCudaTensor *input = THCudaTensor_newWithSize4d(state, 128, 2, 64, 64);
THCudaTensor *output = net->forward(input); // output is 128x1 similarity score tensor

Only 2D and 4D tensors accepted on input.

Again, all binary models expect input patches to be in [0;1] range before mean subtraction.

After you build everything and download the networks run test with run_test.sh. It will download a small test_data.bin file.

MATLAB

Building Matlab bindings requires a little bit of user intervention. Open matlab/make.m file in Matlab and put your paths to Matlab and include/lib paths of TH and THC, then run >> make. Mex file will be created.

To initialize the interface do

deepcompare('init', 'networks/2ch/2ch_notredame.bin');

To reset do

deepcompare('reset')

To propagate through the network:

deepcompare('forward', A)

A can be 2D, 3D or 4D array, which is converted inside to 2D or 4D array (Matlab is col-major and Torch is row-major so the array is transposed):

#dim matlab dim torch dim
2d N x B B x N
3d 64 x 64 x N 1 x N x 64 x 64
4d 64 x 64 x N x B B x N x 64 x 64

2D or 4D tensor is returned. In case of full network propagation for example the output will be 2D: 1 x B, if input was B x 2 x 64 x 64.

To set the number of GPU to be used (the numbering starts from 1):

deepcompare('set_device', 2)

Print the network structure:

deepcompare('print')

To enable splitting the computations of descriptor and decision parts in siamese networks we saved their binary parts.

  • siamese network:
Train Set siam_desc siam_decision
yosemite 3.47 MB,siam_desc_yosemite.bin 1.00 MB,siam_decision_yosemite.bin
notredame 3.47 MB,siam_desc_notredame.bin 1.0MB,siam_decision_notredame.bin
liberty 3.47 MB,siam_desc_liberty.bin 1.00 MB,siam_decision_liberty.bin
  • siam-2stream network:
Train Set siam2stream_desc siam2stream_decision
yosemite 9.16 MB,siam2stream_desc_yosemite.bin 4.01 MB,siam2stream_decision_yosemite.bin
notredame 9.16 MB,siam2stream_desc_notredame.bin 4.01 MB,siam2stream_decision_notredame.bin
liberty 9.16 MB,siam2stream_desc_liberty.bin 4.01 MB,siam2stream_decision_liberty.bin

OpenCV

OpenCV example is here to demonstrate how to use the deep CNN models to match image patches, how to preprocess the patches and use the proposed API.

Depends on OpenCV 3.0. To build the example do

cd build;
cmake -DWITH_OPENCV=ON -DOpenCV_DIR=/opt/opencv .; make -j8

Here /opt/opencv has to be a folder where OpenCV is built. If you have it installed, you don't need to add it, -DWITH_OPENCV=ON will be enough.

To run the example download the images:

wget https://raw.githubusercontent.com/openMVG/ImageDataset_SceauxCastle/master/images/100_7100.JPG
wget https://raw.githubusercontent.com/openMVG/ImageDataset_SceauxCastle/master/images/100_7101.JPG

and run it:

./build/opencv/example networks/siam2stream/siam2stream_desc_notredame.bin 100_7100.JPG 100_7101.JPG

You have to use descriptor matching network in this example. Check the example code for explanation.

CAFFE

Thanks to the awesome @ajtulloch's torch2caffe models were converted to CAFFE format. Unfortunatelly only siam, 2ch and 2chdeep models could be converted at the time, other models will be converted as missing functionality is added to CAFFE.

Download link: https://s3.amazonaws.com/modelzoo-networks/cvpr2015networks-caffe.tar

cvpr15deepcompare's People

Contributors

szagoruyko 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cvpr15deepcompare's Issues

PyTorch evaluation dataset

Hi,

I have downloaded the dataset and unzipped it into a folder. However, when I run the pytorch evaluation code it complains that 'liberty' is a folder. It appears that it is being loaded with load_lua. What format is the dataset expected to be in?

I also downloaded the t7 version of the liberty dataset from www.iis.ee.ic.ac.uk/~vbalnt/liberty-t7.tar.gz however, the code then crashes with the following error:

'''
parsed options: {'model': '2ch', 'lua_model': '../networks/2ch/2ch_liberty.t7', 'nthread': 4, 'gpu_id': '0', 'batch_size': 256, 'test_set': 'liberty.t7', 'test_matches': 'm50_100000_100000_0.txt'}
Loading test data
Traceback (most recent call last):
File "eval.py", line 242, in
main()
File "eval.py", line 176, in main
test_iter = get_iterator(load_provider(), opt.batch_size, opt.nthread)
File "eval.py", line 172, in load_provider
p[t] = p[1][opt.test_matches][t]
KeyError: 1
'''

Assertion failed: 55 56

Getting an assertion failed error within the cutorch library when loading your siam_desc_yosemite.bin and siam_2_stream_desc_yosemite.bin networks, followed by a segfault. Any thoughts?
Here's the error:
55: assertion failed 56: assertion failed [1] 20092 segmentation fault (core dumped) -i ./outputDeepSiam/sfm_data.json -o outputDeepSiam -m -f 1

Training code - FPR95

I think you need to add fprev = L[i] to

    if L[i] > fprev then
      x:resize(j)
      y:resize(j)
      x[j] = FP/N
      y[j] = TP/P
      j = j + 1
    end

Cheers

data.t7

what's the data.t7?Hao can I get this file?

How to use the 2ch2stream network

I want to test the 2ch2stream network, but the net:forward() function give the following error:
image

the network I used is
net = torch.load('./networks/2ch2stream/2ch2stream_yosemite.t7')
My input tensor size is 2x64x64

Can anyone tell me where is wrong and how to use the network in correct way?
Thanks very much!

Error building: ReLU.cu(13)

Evidently THCudaTensor_pointwiseApply1 ought to be changed to THC_pointwiseApply1 in cunnproduction/ReLU.cu(13). See here. It built successfully for me after making that change.

Generating new .bin files from existing .t7 models

How do you generate new .bin files from existing .t7 files?

For example: let's say I have a model I've self-trained or a model from a different project saved as a .t7 . Can I use your loading mechanism to load it in C++, and if so, how?

Thanks!

Problem when loading 2chdeep pre-trained models

Hi,
I'm trying to load your already trained models using the 2chdeep setup. There seems to be a problem with the way you saved them.
This is the error I get when doing torch.load():

unknown Torch class <inn.SpatialMaxPooling>

Could you please check the exported models?

Thanks a lot.

how to use the caffe model?

I am new to deep learning, and i only know how to use caffe a little. If i want to use the caffe model to test the pre-trained model, how should i preprocess the input images? or just give two images to the models? Thanks so much !

Can't run cvpr2015 paper code

Hi @szagoruyko I tried to run your code using torch. First I ran the code for torch format data creation. Then I tried to run the code in /training/train.lua but its fails all the time making error message about models.utils not found. Could you please update your readme with clear process of training and testing in torch?

I will be waiting for a favorable reply.
regards
Nazib

train my own dataset?

thanks for your share code!
i have a task whoese goal is to detect change building from two image taken in different years.and i'm glade to find that your code maybe is useful for my task.
but,there is a trouble now is that i can't understand the dataset formate you used,lead to i can't make my own building dataset feed to the network in order to complete train.
so,can you tell me the detail about the dataset?
1.for example, Is it ok to combine multiple small 64*64 images together to form a large image by the most basic stitching method ?
2.TXT file such as info.txt intrest.txt m50_1000_1000_0.txt,how to create and their function?
3.different m50_xx_xxx_x.txt,Are there any special requirements and meanings for naming these files?
Looking forward to your reply. It will be of great help to me. Thank you!

caffe model output

is it correct that the number of outputs is 1 for all the caffe models?

training by caffe tool

I already try the default siamese network via caffe tool successfuly. So i know a little operation for caffe.

Now if i want to use caffe to train my own data(via 2ch or 2chdeep network),
(my data image with only one channel(8UC1))
1.
how do I prepare the data set format?
As I know the caffe accept LMDB and LEVELDB,
should i mix two image to a two-channel image by other tool(how?)? then convert to lmdb
or better way to do this?

how do i config the training prototxt according above dataset?

according to cvpr2015\2ch\yosemite_deploy.txt.....
input: "data"
input_shape {
dim: 10 <----- why 10? means "use 10 images at the same time"? so output 10 values?
dim: 2
dim: 64
dim: 64
}

pytorch/eval.py: where is the 'lua_model'

I am trying to run the pytorch/eval.py, but I don't know which file I should put for required field '--lua_model'
I tried different lua files in training and torch folder, but always get this error:

torch.utils.serialization.read_lua_file.T7ReaderException: unknown type id 1970365810. The file may be corrupted.

Thank you for your help

torch test error

When I test torch, run match_cpu.lua the following error occurred.
/home/zbw/torch/install/bin/lua: cannot open <../networks/siam2stream/siam2stream_liberty_nn.t7> in mode r at /home/zbw/torch/pkg/torch/lib/TH/THDiskFile.c:673
stack traceback:
[C]: in ?
[C]: in function 'DiskFile'
/home/zbw/torch/install/share/lua/5.2/torch/File.lua:405: in function 'load'
extract_cpu.lua:8: in main chunk
[C]: in function 'dofile'
.../zbw/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: in ?
What's the problem?
Is it my torch installation error?
I'm a new, asking for help!
Thank you very much!

Failed When run ./run_test.sh

Hi, Today I ran the code and test ./run_test.sh using downloaded bins. It all goes Failed in all bins rather than PASS. I am wondering is it correct, or I might have done something wrong. Sorry for the interruption. Thank you ~

Error Linking THC When Building Matlab Interface

Hi, I'm trying to compile the Matlab interface using mex. I followed the directions for installation and added -L/cutorch/lib/THC/build to make.m, but I'm getting a linking error. I've reproduced the error on OSX 10.10 using clang-602.0.53 and Ubuntu 14.04 using gcc 4.8.4. Using clang:

Undefined symbols for architecture x86_64:
   "_cunnrelease_Linear", referenced from:
      cunn::Linear::forward(THCudaTensor*) in libcunnproduction_static.a(cunn.cpp.o)
  "_cunnrelease_ReLUIP", referenced from:
      cunn::ReLU::forward(THCudaTensor*) in libcunnproduction_static.a(cunn.cpp.o)
  "_cunnrelease_SpatialAveragePooling", referenced from:
      cunn::SpatialAveragePooling::forward(THCudaTensor*) in libcunnproduction_static.a(cunn.cpp.o)
  "_cunnrelease_SpatialConvolution", referenced from:
      cunn::SpatialConvolutionMM::forward(THCudaTensor*) in libcunnproduction_static.a(cunn.cpp.o)
  "_cunnrelease_SpatialMaxPooling", referenced from:
      cunn::SpatialMaxPooling::forward(THCudaTensor*) in libcunnproduction_static.a(cunn.cpp.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

    mex: link of ' "deepcompare.mexmaci64"' failed.

Using gcc:

Error using mex
../build/cunnproduction/libcunnproduction_static.a(cunn.cpp.o): In function
`cunn::SpatialConvolutionMM::forward(THCudaTensor*)':
cunn.cpp:(.text+0x368): undefined reference to `cunnrelease_SpatialConvolution'
../build/cunnproduction/libcunnproduction_static.a(cunn.cpp.o): In function
`cunn::SpatialMaxPooling::forward(THCudaTensor*)':
cunn.cpp:(.text+0x523): undefined reference to `cunnrelease_SpatialMaxPooling'
../build/cunnproduction/libcunnproduction_static.a(cunn.cpp.o): In function
`cunn::SpatialAveragePooling::forward(THCudaTensor*)':
cunn.cpp:(.text+0x639): undefined reference to `cunnrelease_SpatialAveragePooling'
../build/cunnproduction/libcunnproduction_static.a(cunn.cpp.o): In function `cunn::ReLU::forward(THCudaTensor*)':
cunn.cpp:(.text+0x6cf): undefined reference to `cunnrelease_ReLUIP'
../build/cunnproduction/libcunnproduction_static.a(cunn.cpp.o): In function `cunn::Linear::forward(THCudaTensor*)':
cunn.cpp:(.text+0x866): undefined reference to `cunnrelease_Linear'
collect2: error: ld returned 1 exit status

Am I linking the wrong library?

how to test a pair of image

Thank you very much for sharing!
If I only want to test the similarity of two images in a pair of images, the return value I want is only the similarity probability of this set of images, can your code get such output?
Which variable is the percentage of similarity that holds each set of test data that I didn't find in the code.
Please specify that for me,this will be very helpful to my study!
Thank you very much!

Ask for the detailed information about the dataset yosemite?

def read_matches_file(filename): print(filename) data = np.loadtxt(filename, dtype=np.uint64) mask = data[:,1] == data[:,4] pairs = data[:,(0, 3)] return pairs[mask], pairs[np.logical_not(mask)]

for example, the txt file named ,m50_2000_2000_0.txt. what's the meaning of each column in the txt file?
@szagoruyko how do we find the detailed describtion about the training data format.

Choice of Criterion

@szagoruyko Does it make any difference whether you use the nn.MarginCriterion() or nn.HingeCriterion()? In the paper, you mentioned the use of a hinge loss with an L2 regularization term on the weights. Is that what is being used in the code?

training code

Hi, will you release your original training code in torch? Thanks

About the coloured dataset

I notice that the paper mentions there is another coloured dataset, any one knows how can I get that dataset???? thank you in advance.

train error

Thank you for sharing the code.
I made a mistake when I tried to run train. lua.

/home/zbw/torch/install/bin/lua: /home/zbw/torch/install/share/lua/5.2/torch/File.lua:375: unknown object
stack traceback:
[C]: in function 'error'
/home/zbw/torch/install/share/lua/5.2/torch/File.lua:375: in function 'readObject'
/home/zbw/torch/install/share/lua/5.2/torch/File.lua:409: in function 'load'
train.lua:42: in function 'loadProvider'
train.lua:54: in main chunk
[C]: in function 'dofile'
.../zbw/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: in ?

I used the create_dataset_file.py in the pytorch folder to convert the data to generate the data.npy file.
This error occurs when i run the following command.
train_set=notredame/data.npy test_set=yosemite/data.npy model=siam th train.lua

Does the model=sim represent the model parameter files that have been trained?
Where does my operation go wrong?
How can I solve this problem?
Looking forward to your reply!
Thank you very much!

Interpreting Network Outputs

Hi @szagoruyko , when I run test patches through a trained network, how am I to interpret the output similarity scores? It doesn't appear that they are normalized to [0,1].

test_data.bin

Hi.

I'm trying to run C++ API. After long-long suffering i've managed to compile torch and this. But there are one problem. When i'm trying to load test_data.bin using wget https://dl.dropboxusercontent.com/u/44617616/test_data.bin it says that "HTTP request sent, awaiting response... 404 Not Found". So, file is deleted from dropbox? Where could i find it?

Thanks in advance

make: *** No rule to make target 'install'. Stop.

Hello,I am using Ubuntun16.04 OS and want to try this program.
1.I try to install TH and THC,but when I insatll THC ,there is an error as fllow
make: *** No rule to make target 'install'. Stop.
I don't know why.
2.The second question is how to change the input data to my data.
Any help will be grateful.Thanks a lot.

fatal error: THC/THC.h: No such file or directory

I am trying to install run the model on OpenCV. But I have tried a few times and I still meet this problem when I run
cmake -DWITH_OPENCV=ON -DOpenCV_DIR=/opt/opencv ..; make -j8
and it all arise this error :
/home/ubuntu/shihua/cvpr15deepcompare-master/opencv/example.cpp:15:21: fatal error: THC/THC.h: No such file or directory
compilation terminated.
CMakeFiles/example.dir/build.make:62: recipe for target 'CMakeFiles/example.dir/example.cpp.o' failed
make[2]: *** [CMakeFiles/example.dir/example.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/example.dir/all' failed
make[1]: *** [CMakeFiles/example.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

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.