Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transformer #361

Merged
merged 1 commit into from
Aug 17, 2015
Merged

Transformer #361

merged 1 commit into from
Aug 17, 2015

Conversation

skaae
Copy link
Member

@skaae skaae commented Aug 6, 2015

Spatial transformer Layer

TODO/questions

@skaae
Copy link
Member Author

skaae commented Aug 7, 2015

I cleaned up the docs and added some very simple tests.

@f0k
Copy link
Member

f0k commented Aug 7, 2015

I get an error when generating the docs. It seems to be related to objectives.rst??

Oh, my bad. Didn't see that when doing #359, I only ran the tests :-/ Fixed in #364!

@skaae
Copy link
Member Author

skaae commented Aug 7, 2015

Thanks. I'll wait for #364 to be merged

@f0k
Copy link
Member

f0k commented Aug 7, 2015

Thanks. I'll wait for #364 to be merged

Merged! If you want, you can rebase your branch now:

git checkout transformer
git pull upstream master --rebase
git push --force origin transformer

@skaae
Copy link
Member Author

skaae commented Aug 7, 2015

And no doc errors, except for my own...

@skaae skaae closed this Aug 7, 2015
@skaae skaae reopened this Aug 7, 2015
The network that calculates the parameters of the affine
transformation. See the example for how to initialize to the identity
transform. Note that all parameters are clipped to lie in the range
``[-1, 1]``, similar to [1]_.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean you're clipping the values in the code? Wouldn't it be more efficient to just require the localization_network to output values in [-1, 1] in the first place?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you could do that. But if you happen to output values larger than -1,+1 i think you would get indexing errors which are pretty hard to debug.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But i'm very open to suggestions. Not sure if i have done it in the best way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an option clip_transform=True that clips transformation parameters when activated (which should be the default), but that can be disabled for improved performance if your network has tanh output, for example.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but i think that performance drop from using clipping is negligible?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be. Let's just leave that for later (i.e., a future PR, if it turns out to be worth it)!

@skaae
Copy link
Member Author

skaae commented Aug 7, 2015

Just realized that what if have said about the range of the affine parameters was not correct. The parameters are free to be any value. The clips are to ensure that we do not look up illegal indices.

I removed the references to [-1, +1] from the documetation. ]

def get_output_shape_for(self, input_shapes):
shp = input_shapes[0]
dsf = self.downsample_factor
return shp[:2] + tuple(int(s//dsf) for s in shp[2:])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized that this won't work with Nones. You'd need:

return (shp[:2] + tuple(None if s is None
                        else int(s//dsf) for s in shp[2:]))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And maybe we should't use integer division if we allow floats for downsample factors?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For non integer downsample factor i just floor the output shapes. Is that the question?

@f0k
Copy link
Member

f0k commented Aug 8, 2015

Great, I like your documentation extensions! Just two minor things, and then I'd be all for squashing and merging!

@skaae
Copy link
Member Author

skaae commented Aug 8, 2015

I think this is done if any one else whant to have a look?

I would like to test the code on MNIST before I merge it. I have used the code at it worked fine, but just in case I have messed something up :)

input : a :class:`Layer` instance
The input where the affine transformation is applied. This should
have convolution format, i.e. (num_batch, channels, height, width).
localization_network: : a :class:`Layer` instance
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a colon too much (the one in localization_network:). Didn't see that before, sorry. Guess it might confuse Sphinx. Feel free to amend your commit if you have the time, otherwise we can leave that for some general docstring proofreading sometime.

@f0k
Copy link
Member

f0k commented Aug 10, 2015

Looks good except for one minor thing I've overlooked before, sorry!

I would like to test the code on MNIST before I merge it.

When you're testing again on MNIST, could you try replacing the integer // divisions by normal / divisions? It should be the same. The integer divisions suggest that downsample_factor would be an integer, which would render the type casting unneeded. So I'd prefer using / for the division if possible!

Let me know when you've tested on MNIST and are fine with this PR to be merged!

@skaae
Copy link
Member Author

skaae commented Aug 10, 2015

I fixed the last docstring error. Using / does work, which makes sense. Thanks for the detailed review :)

I'll get back when i have run the MNIST test. I'll probably add a recipe to reproduce the results in the paper.

@f0k
Copy link
Member

f0k commented Aug 10, 2015

I'll get back when i have run the MNIST test.

Cool! Feel free to commit / squash / push so Travis can run already. (Just to be sure, note that there are two occurrences of // in the code.)

@f0k
Copy link
Member

f0k commented Aug 13, 2015

Any news? Can we merge this today, or do you still want to test something?

@skaae
Copy link
Member Author

skaae commented Aug 13, 2015

No. Im still in Montreal but i’m going home today. I’ll be able to test it in the weekend.

On 13 Aug 2015, at 08:20, Jan Schlüter notifications@github.com wrote:

Any news? Can we merge this today, or do you still want to test something?


Reply to this email directly or view it on GitHub.

@skaae
Copy link
Member Author

skaae commented Aug 15, 2015

I ran a test on cluttered MNIST and the layer seems to be working fine. I'm fine with merging.

The experiment is here:

https://github.com/skaae/Recipes/blob/spatial_transform/examples/spatial_transformer_network.ipynb

The last plot shows that its does zoom as expected.

@f0k
Copy link
Member

f0k commented Aug 17, 2015

Cool, thanks a lot! Will merge this after #382. Your recipe looks very nice as well.

@f0k
Copy link
Member

f0k commented Aug 17, 2015

Thinking again, didn't we want to move that to special.py (#373 (comment))? If so, you'd need to rename transform.py, test_transform.py and docs/layers/transform.rst accordingly, and update the references in layers/__init__.py and docs/layers.rst. In #373, we've chosen "Special-purpose layers" for the header in docs/layers/special.rst: https://github.com/Lasagne/Lasagne/pull/373/files#diff-5e96c229ca5e2f81af27a8a50443dec8R1

Do you want to rename it here (and squash or amend), or shall we merge #373, rebase yours and move it? I guess the former would be less work for you, then I can care about rebasing #373.

@skaae
Copy link
Member Author

skaae commented Aug 17, 2015

Ah yes forgot that. Go ahead and merge #373. I can rebase this when you have merged #373.

@f0k
Copy link
Member

f0k commented Aug 17, 2015

All right, merged it. Rebasing this one should just trigger trivial conflicts in docs/modules/layers.rst and lasagne/layers/__init__.py. I guess it will be easiest to not add transform to those two files at all when you solve the conflict, then move over your code from *transform.* to *special.* and amend your commit.

@skaae
Copy link
Member Author

skaae commented Aug 17, 2015

I moved it to special.py . Hopefully Travis passes :)

@f0k
Copy link
Member

f0k commented Aug 17, 2015

Cool, that was fast! Looks good to me, let's see what Travis and Coveralls think!

@f0k
Copy link
Member

f0k commented Aug 17, 2015

Merging, thanks a lot!

We can now figure out if there are ways to make it faster if the image shape is known at compile time (which is probably a common use case).

f0k added a commit that referenced this pull request Aug 17, 2015
@f0k f0k merged commit db57650 into Lasagne:master Aug 17, 2015
@skaae skaae deleted the transformer branch August 20, 2015 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants