Git Product home page Git Product logo

inverse-compositional-stn's Introduction

Inverse Compositional Spatial Transformer Networks

Chen-Hsuan Lin and Simon Lucey
IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2017 (oral presentation)

Project page: https://chenhsuanlin.bitbucket.io/inverse-compositional-STN
Paper: https://chenhsuanlin.bitbucket.io/inverse-compositional-STN/paper.pdf
Poster: https://chenhsuanlin.bitbucket.io/inverse-compositional-STN/poster.pdf
arXiv preprint: https://arxiv.org/abs/1612.03897

We provide TensorFlow code for the following experiments:

  • MNIST classification
  • traffic sign classification

[NEW!] The PyTorch implementation of the MNIST experiment is now up!


TensorFlow

Prerequisites

This code is developed with Python3 (python3) but it is also compatible with Python2.7 (python). TensorFlow r1.0+ is required. The dependencies can install by running

pip3 install --upgrade numpy scipy termcolor matplotlib tensorflow-gpu

If you're using Python2.7, use pip2 instead; if you don't have sudo access, add the --user flag.

Running the code

The training code can be executed via the command

python3 train.py <netType> [(options)]

<netType> should be one of the following:

  1. CNN - standard convolutional neural network
  2. STN - Spatial Transformer Network (STN)
  3. IC-STN - Inverse Compositional Spatial Transformer Network (IC-STN)

The list of optional arguments can be found by executing python3 train.py --help.
The default training settings in this released code is slightly different from that in the paper; it is stabler and optimizes the networks better.

When the code is run for the first time, the datasets will be automatically downloaded and preprocessed.
The checkpoints are saved in the automatically created directory model_GROUP; summaries are saved in summary_GROUP.

Visualizing the results

We've included code to visualize the training over TensorBoard. To execute, run

tensorboard --logdir=summary_GROUP --port=6006

We provide three types of data visualization:

  1. SCALARS: training/test error over iterations
  2. IMAGES: alignment results and mean/variance appearances
  3. GRAPH: network architecture

PyTorch

The PyTorch version of the code is stil under active development. The training speed is currently slower than the TensorFlow version. Suggestions on improvements are welcome! :)

Prerequisites

This code is developed with Python3 (python3). It has not been tested with Python2.7 yet. PyTorch 0.2.0+ is required. Please see http://pytorch.org/ for installation instructions.
Visdom is also required; it can be installed by running

pip3 install --upgrade visdom

If you don't have sudo access, add the --user flag.

Running the code

First, start a Visdom server by running

python3 -m visdom.server -port=7000

The training code can be executed via the command (using the same port number)

python3 train.py <netType> --port=7000 [(options)]

<netType> should be one of the following:

  1. CNN - standard convolutional neural network
  2. STN - Spatial Transformer Network (STN)
  3. IC-STN - Inverse Compositional Spatial Transformer Network (IC-STN)

The list of optional arguments can be found by executing python3 train.py --help.
The default training settings in this released code is slightly different from that in the paper; it is stabler and optimizes the networks better.

When the code is run for the first time, the datasets will be automatically downloaded and preprocessed.
The checkpoints are saved in the automatically created directory model_GROUP; summaries are saved in summary_GROUP.

Visualizing the results

We provide three types of data visualization on Visdom:

  1. Training/test error over iterations
  2. Alignment results and mean/variance appearances

If you find our code useful for your research, please cite

@inproceedings{lin2017inverse,
  title={Inverse Compositional Spatial Transformer Networks},
  author={Lin, Chen-Hsuan and Lucey, Simon},
  booktitle={IEEE Conference on Computer Vision and Pattern Recognition ({CVPR})},
  year={2017}
}

Please contact me ([email protected]) if you have any questions!

inverse-compositional-stn's People

Contributors

chenhsuanlin avatar coldmooon avatar zehaos 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

inverse-compositional-stn's Issues

what is opt.refMtrx?

In the IC-STN code(pytorch), in <option.py> file, there are following 2 lines of code:

opt.refMtrx = warp.fit(Xsrc=opt.canon4pts,Xdst=opt.image4pts)
opt.refMtrx = np.eye(3).astype(np.float32)

If I commented the second line out, the performance dropped significantly and the network become harder to train.

However, the tensorflow version is using the results from 'warp.fit', and works fine.

What is the reason that for pytorch version, you are using np.eye(3), instead of warp.fit?

IC-STN algorithm for landmark detection

Thanks for your great job. I want to use the IC-STN for the face landmark detection task. Different from the classification task, do I need to inverse transform the transformed image to obtain the points on the orginal
image?Waiting for your advice.

RuntimeError

Hello,

Thanks for sharing the code of your interesting work IC-STN.

I am now using Pytorch version. However, I meet runtime error as below:

Expected a Tensor of type Variable but found an undefined Tensor at position #2 for iterable argument #0 'tensors'

It seems there is an operation that includes tensor which should be defined as Variable.

Any comments?

Thanks.

How to use this code to align source image to target image?

First, thanks for releasing a clean and well trained code for your paper!
I have two sets of image(source and target), and I want to align source image to the target image. Should I try to replace data "label" in dataloader to "target/template"? or what I should change?

Dataload issue

As the PyTorch Implementation uses Tensorflow to load data, I write a class inheriting from torch.utils.data.Dataset, and then use Dataloader to load data. However, I got errors as below:

RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method

I debug this, and found out that "torch.set_default_tensor_type("torch.cuda.FloatTensor")" in options.py causing this issue.

While, when I removed this sentence, I got another error:

File "/home/lin/inverse-compositional-STN/MNIST-pytorch/graph.py", line 156, in initialize
m.weight.data.normal_(0,0.0 if last0 and m is model.linearLayers[-1] else stddev)
RuntimeError: invalid argument 2: standard deviation must be strictly positive at /pytorch/torch/lib/TH/THRandom.c:255

Stuck at loading MNIST dataset

Hello guys, I tried to run train.py using this command
python train.py CNN --group groupCNN --model modelCNN --lr 0.001 --lr 0.001 --batchSize 32 --maxIter 2000 --warpType translation
But somehow I stuck at this loading MNIST dataset. My Internet works normally so I dont know what is going on. I also dont know if the parameter I used on the command above is correct or not since the readme doesnt provide any examples to compare.
Thanks
a

Problem with traffic signs

Hello.
Just tried to run your code. Mnist-tensorflow works fine, but traffic signs shows some strange results... Can you tell me, if just running train.py with option, for example IC-STN, is enough in case of signs?

problem_with_signs

here is what i've got.

这个问题是什么原因呢

您好,我在训练您的tensorflowsh书写数字时候,遇见了这个问题,请问是什么原因呢

Traceback (most recent call last):
File "F:/stn1/inverse-compositional-STN-master/MNIST-tensorflow/train.py", line 74, in
traintrainData,validData,testData = data.loadMNIST("F:/stn1/inverse-compositional-STN-master/MNIST-tenso
rflow/data/MNIST.npz")
File "F:\stn1\inverse-compositional-STN-master\MNIST-tensorflow\data.py", line 25, in loadMNIST
trainData = MNIST["train"].item()
File "D:\python3\lib\site-packages\numpy\lib\npyio.py", line 262, in getitem
raise KeyError("%s is not a file in the archive" % key)
KeyError: 'train is not a file in the archive'

Large test error

Hi,

Nice work! I am trying to reproduce the results shown in the paper, but using IC-STN with depth = 2, the test error after 100000 epochs is 14.72%, and the loss is 0.5346. For IC-STN with depth = 4, the test error goes up dramatically in the end, and it seems that there is overfitting. I am running the train.py without any modification.

I am wondering whether do we have to change the hyper parameters such as the learning rate, training iterations, in order to obtain the results like Table 2 in paper, where errors are around 1%?

what is the role of refMtrx in function: transformImage(warp.py)

Hi, I have read your code。 But I am confused about the role of refMtrx in #warp.py-function: transformImage()#. It seems that refMtrx is set to be torch.eye() in options.py, and do nothing in #warp.py-Line75#. Can I directly use transMtrx = pMtrx in #warp.py-Line75#? I am worried about if i ignore refMtrx, some unexpected errors may be introduced.

Looking forward to your reply!
Thanks

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.