Я пытаюсь реализовать определенный c пользовательский слой. Тем не менее, когда я запускаю его, все работает, никаких ошибок, но после компиляции и подгонки я не получаю "обучения". Ie, я получаю те же выходы, что и на входах ...
class Reconfiguration_unit(K.layers.Layer):
def __init__(self, *args, **kwargs):
super(Reconfiguration_unit, self).__init__(*args, **kwargs)
def build(self, input_shape):
self.weight = self.add_weight(shape=[input_shape[1],input_shape[1]],
initializer='zeros',
trainable=True)
self.bias = self.add_weight(shape=[input_shape[1],input_shape[1]],
initializer='zeros',
trainable=True)
self.location = self.add_weight(shape=input_shape[1:],
initializer='zeros',
trainable=True)
self.scale = self.add_weight(shape=input_shape[1:],
initializer='zeros',
trainable=True)
def call(self, x):
# 1. Shift and scale data
x_shift = x - self.location
# 2. Rescale componentwise
x_mod = tf.math.multiply(x_shift,self.scale)
# 3. Apply bumpy function Component-wise
x_in_abs = tf.math.abs(x_mod)
Logic_x_leq1 = tf.math.sign(tf.keras.activations.relu(1-x_in_abs)) # Takes value 1 iff |x|<=1 else 0: since probability of |x|=1 is 0 we should be ok
x_thresheld = Logic_x_leq1*tf.math.exp(-1/(1-tf.math.pow(x_in_abs,-1))) # Computes bump function at thresholds with previous logic
# 4+5. Apply Shift (In Tangent Space) and diagonalize
x_out = tf.linalg.diag(x_thresheld) + self.bias
# 6. Multiply by weight matrix (in Tangent Space)
x_out = tf.matmul(x_out,self.weight)
# 7. Apply Matrix Exponential
x_out = tf.linalg.expm(x_out)
# 8. Muliply by output of (1)
x_out = tf.linalg.matvec(x_out,x_shift)
# 9. Recenter Transformed Data
x_out = x_out + self.location
# Return Ouput
return x_out