keras-cn
keras-cn copied to clipboard
keras更新后出现 Exception: Regularizers cannot be reused
具体的代码是这个 model2.add(TimeDistributed(Convolution2D(64, 3, 3, border_mode='valid', W_regularizer=l2(0.01), activity_regularizer=activity_l2(0.01))))
如果去掉activity_regularizer就正常了,tf和th都试了,都会报这个异常
Using TensorFlow backend.
Traceback (most recent call last):
File "test.py", line 26, in
File "/Users/cesc/anaconda/lib/python2.7/site-packages/keras/engine/topology.py", line 487, in call self.build(input_shapes[0]) File "/Users/cesc/anaconda/lib/python2.7/site-packages/keras/layers/wrappers.py", line 100, in build super(TimeDistributed, self).build() File "/Users/cesc/anaconda/lib/python2.7/site-packages/keras/layers/wrappers.py", line 28, in build regularizer.set_layer(self) File "/Users/cesc/anaconda/lib/python2.7/site-packages/keras/regularizers.py", line 113, in set_layer raise Exception('Regularizers cannot be reused') Exception: Regularizers cannot be reused
@cescigl 对这个问题不太了解,看了看源代码分析了一下,也许你应该把正则项放到Convolution2D之外,也就是对TimeDistributed Covolution2D正则而不是对其中的一个Convolution2D正则,TimeDistributed的父类是Wrapper,其父类是Layer所以也可以加正则。
猜测问题的原因可能是为一个层施加了多次正则
@MoyanZitto fchollet在27天前更新了wrapper层。 Fix activity regularization for wrapper layers fchollet committed 27 days ago 添加了相关代码 # properly attribute the current layer to # regularizers that need access to it # (e.g. ActivityRegularizer). for regularizer in self.regularizers: if hasattr(regularizer, 'set_layer'): regularizer.set_layer(self)
不知道会不会有影响
@cescigl 您好,我现在遇到的问题跟您一样,TimeDistributed(Dense(5, activation='softmax', activity_regularizer=activity_l1(0.01)))(lstm) ,提示 “Regularizers cannot be reused”,看了下文档,感觉这么用的用法是正确的啊,不知道为什么报错。 所以想请问一下,您这个问题是怎么解决的?谢谢~~
@summerHaha 我并没有测试新版本的问题,这个问题只在某个版本出现,之前的版本是OK的,我只是没有用regular