Max-Pool Gradient Error (Tensorflow 0.9rc0)

时间:2016-07-11 20:10:51

标签: tensorflow

I am getting an auto-differentiation error for max-pooling. Note that I am feeding in an image, using the gradient of the convnet output wrt the input image, updating the image based on the gradient, and then feeding the image back to the network (think adversarial images). As such, this involves trickier gradient handling and consequently I get this error:

LookupError: No gradient defined for operation 'gradients/MaxPool_grad/MaxPoolGrad' (op type: MaxPoolGrad)

Is there an easy work-around?

1 个答案:

答案 0 :(得分:3)

As the error message suggests, the MaxPoolGrad operation in TensorFlow does not have the corresponding gradient function implemented in TensorFlow as of version 0.9.

To elaborate, the Python function tf.gradients performs reverse mode auto-differentiation by walking the graph of computation that has been built up so far. When it encounters a node with operation type Foo, it tries to look up the corresponding gradient function in an internal registry. The registry is populated by calling the RegisterGradient function.

Note that, while TensorFlow has entries in this registry for many (in fact most) types of nodes, there are still a subset of node types for which there are no entries. Such cases cause the error you see above. It will indeed be useful to figure out a gradient function for MaxPoolGrad, implement it, and send a pull request.