List-of-Differentiable--OPs-and-Non-differentiable-OPs--in-Tensorflow
List-of-Differentiable--OPs-and-Non-differentiable-OPs--in-Tensorflow copied to clipboard
Incorrect list - I guess the script somehow also needs to check return values?
I think currently the list of differentiable OPs is incorrect.
Take ArgMax
as an example:
https://github.com/tensorflow/tensorflow/blob/87462bfac761435a46641ff2f10ad0b6e5414a4b/tensorflow/python/ops/math_grad.py#L37
It returns [None, None].
And I guess, that is why I'm still getting:
ValueError: No gradients provided for any variable
when I use a Lambda-Layer with tf.math.argmax
within keras.
So my guess is that ArgMax
is indeed not differentiable.
But maybe I'm just missing something?
Example code:
import tensorflow as tf
import tensorflow.keras.backend as K
from tensorflow.keras.layers import *
from tensorflow.keras.models import *
from tensorflow.keras.optimizers import *
def ArgMax():
return Lambda(lambda q:tf.math.argmax(q, 2))
inputs1 = Input(shape = (1,1,))
d = Dense(3)(inputs1)
out = ArgMax()(d)
model = Model(inputs = [inputs1], outputs = [out], name = "test")
model.summary()
model.compile(SGD(0.1),loss="mae")
model.fit(
x = [np.ones((100,1,1))],
y = [np.zeros((100,1))],
batch_size = 100,
verbose = 2,
epochs = 10)