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

Tanh #116

Closed
wants to merge 2 commits into from
Closed

Tanh #116

wants to merge 2 commits into from

Conversation

aravindhm
Copy link

Added a hyperbolic tangent activation function layer. This was developed in the boost-eigen branch so hasn't been tested/compiled with master (I don't have MKL). Please test / examine this and let me know if anything needs to be fixed.

#include <algorithm>

namespace caffe {

Copy link
Contributor

Choose a reason for hiding this comment

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

You should create a SetUp method to check that there is only one bottom blob and only one top blob or if you also want this layer to work in-place you could add this

void TanHLayer<Dtype>::SetUp(const vector<Blob<Dtype>*>& bottom,
      vector<Blob<Dtype>*>* top) {
  NeuronLayer<Dtype>::SetUp(bottom, top);

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for the back-and-forth, but one does not need to write a custom set up function if no special care needs to be carried out. The NeuronLayer has a virtual SetUp() function that will deal with the default construction and in-place check:

https://github.com/BVLC/caffe/blob/master/src/caffe/layers/neuron_layer.cpp

So maybe simply ignore the setup function...?

Copy link
Author

Choose a reason for hiding this comment

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

We need a setup for the situation in which tanh is not used in place. It should then call Reshape for (*top)[0].

Copy link
Member

Choose a reason for hiding this comment

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

@aravindhm
Copy link
Author

I've added a SetUp function. I noticed that its not present in ReLU or Sigmoid either. Included all recent changes from Master into this. One of my friends verified that the MKL version compiles and the CPU tests pass - he doesn't have a GPU on that machine.

@sguada
Copy link
Contributor

sguada commented Feb 18, 2014

@aravindhm sorry for the confusion, @Yangqing is right you don't need to add a setup in this case. Neuron_layer will take care of that.

@aravindhm now you are adding new commits to this layer and merging it with master again. That will mess with other commits. You will need to revert, or better to rebase again against the new master by doing the following (@shelhamer please correct me if I'm wrong):

If your master is different from BVLC/master then first create a new branch diverged to keep your changes.

git checkout master
git branch diverged

Then fetch the latest changes from BVLC/master and reset your master to be the same as BLVC/master

git fetch bvlc master
git reset --hard bvlc/master

Now you can pick the commits your tanh branch that you want to keep for the pull-request by deleting or editing the lines in the interactive window

git checkout tanh
git rebase -i master

And now you have to force push to your repository to have clean history

git push --force origin tanh

@aravindhm
Copy link
Author

I've followed those instructions blindly after resetting back to the commit before the setup function was added. The tests all pass when I integrate it with boost-eigen. The extra SetUp function is not there.

@shelhamer
Copy link
Member

@aravindhm sorry for the confusion in sharing your contribution. I'm writing up a guide to help with such matters. Thanks for your work :)

shelhamer added a commit that referenced this pull request Feb 18, 2014
Add TanH = hyperbolic tangent activation layer (popular for sparse
autoencoders).
@shelhamer
Copy link
Member

Merged to dev per #101. Thanks!

@shelhamer shelhamer closed this Feb 18, 2014
shelhamer added a commit to shelhamer/caffe that referenced this pull request Feb 23, 2014
Add TanH = hyperbolic tangent activation layer (popular for sparse
autoencoders).
shelhamer added a commit to shelhamer/caffe that referenced this pull request Feb 26, 2014
Add TanH = hyperbolic tangent activation layer (popular for sparse
autoencoders).
shelhamer added a commit that referenced this pull request Feb 26, 2014
Add TanH = hyperbolic tangent activation layer (popular for sparse
autoencoders).
shelhamer added a commit that referenced this pull request Feb 26, 2014
Add TanH = hyperbolic tangent activation layer (popular for sparse
autoencoders).
shelhamer added a commit that referenced this pull request Feb 26, 2014
mitmul pushed a commit to mitmul/caffe that referenced this pull request Sep 30, 2014
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

5 participants