Я перемасштабирую вес по вашей логике c (я использую TF 2.2)
class custom(tf.keras.constraints.Constraint):
def __init__(self, length):
self.length = length
def __call__(self, W):
w_shape = W.shape
rep = w_shape[0]/self.length
w = (np.arange(1,rep+1)/np.arange(1,rep+1).sum()).astype('float32')
w = tf.reshape(tf.repeat(tf.constant(w), self.length*w_shape[1]), [w_shape[0],w_shape[1]])
return w*W
определяю модель
inp = Input(shape=(100))
x = Dense(588)(inp)
out = Dense(42, kernel_constraint=custom(84))(x)
model = Model(inp, out)
model.compile('adam', 'mse')
фиктивный поезд
model.fit(np.random.normal(0,1, (10, 100)), np.random.normal(0,1, (10, 42)), epochs=10)
Я надеюсь, что эта помощь