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

forward pass projection #8559

Closed
Alexivia opened this issue Mar 20, 2017 · 3 comments
Closed

forward pass projection #8559

Alexivia opened this issue Mar 20, 2017 · 3 comments
Labels
type:support Support issues

Comments

@Alexivia
Copy link

Hi,

Is there any way to define a layer that for forward-pass calculates its output by projecting the weight values into a different value range, but for the back-propagation uses the real weight values? i.e., as an example from the mnist.py file, if for the hidden layer 1 forward pass we could have hidden1 = tf.nn.relu(tf.matmul(images, projection_func(weights)) + biases), but for the gradient calculation during back-propagation the weights were updated without projection_func().

This would be useful to implement BNNs, to apply functions such as the ones mentioned by @Jony101K here.

Thanks.
Alexandre

@Alexivia
Copy link
Author

@bhack, could you help me with this?

@gaohuazuo
Copy link
Contributor

gaohuazuo commented Mar 24, 2017

Maybe you can try https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/framework/function.py. It allows you to construct a new op with existing ones, and define its gradient.

from tensorflow.python.framework.function import Defun

def _projection_func_grad(op, grad):
    # compute the (fake) gradient, in this case just pass it through
    return grad

@Defun(tf.float32, python_grad_func=_projection_func_grad)
def projection_func(weights):
    # do something
    return weights

@aselle
Copy link
Contributor

aselle commented Mar 24, 2017

This question is better asked on StackOverflow since it is not a bug or feature request. There is also a larger community that reads questions there. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:support Support issues
Projects
None yet
Development

No branches or pull requests

3 participants