当你在构建自定义keras类时候,如果call中使用已有的layer,需要在__init__中提前定义
比如:
def __init__(self, pre_lens=28, window=180, is_teachers=False, name='mul', **kwargs):
super(multcn, self).__init__(name=name,**kwargs)
self.tcn = TCN(
kernel_size=7,
use_skip_connections=False,
use_batch_norm=True,
use_weight_norm=False,
use_layer_norm=False
)
self.units = 32
self.pre_lens = pre_lens
self.window = window
self.is_teachers = is_teachers
self.dense_linear = Dense(self.pre_lens, activation='linear')
self.dense_relu = Dense(self.pre_lens, activation='relu')
self.dense_sigmoid = Dense(self.pre_lens, activation='sigmoid')
self.dense_tanh = Dense(self.pre_lens, activation='tanh')
定义好后 可在call function中自由使用