我想训练一个具有自定义激活层的keras模型。自定义激活层具有一个固定的不可压缩参数。
我想改变/设置这个不可训练的参数在模型中的所有自定义激活层在训练后的几个时期。
如何使用keras回调来实现这一点?
发布于 2020-12-02 12:12:56
您需要为此编写一个自定义回调,该回调实现了on_epoch_end方法。大概应该是这样的
class CustomCallback(keras.callbacks.Callback):
def __init__(self, freq):
super().__init__()
self.freq = freq # how often to change the parameter
def on_epoch_end(self, epoch):
if epoch % freq == 0 and epoch > 0:
weights = self.model.get_weights()
# here you change the weight you want, e.g. it is the 5th layer
weights[4] = weights[4] / 10
self.model.set_weights(weights)https://datascience.stackexchange.com/questions/86190
复制相似问题