当我保存我的模型时,我收到以下错误信息:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-40-853303da8647> in <module>()
7
8
----> 9 model.save(outdir+'model.h5')
10
11
5 frames
/usr/local/lib/python3.6/dist-packages/h5py/_hl/group.py in __setitem__(self, name, obj)
371
372 if isinstance(obj, HLObject):
--> 373 h5o.link(obj.id, self.id, name, lcpl=lcpl, lapl=self._lapl)
374
375 elif isinstance(obj, SoftLink):
h5py/_objects.pyx in h5py._objects.with_phil.wrapper()
h5py/_objects.pyx in h5py._objects.with_phil.wrapper()
h5py/h5o.pyx in h5py.h5o.link()
RuntimeError: Unable to create link (name already exists)
当我使用内置层或其他用户定义的层构建我的模型时,不会发生这种情况。只有当我使用这个特定的用户定义层时才会出现这个错误:
class MergeTwo(keras.layers.Layer):
def __init__(self, nout, **kwargs):
super(MergeTwo, self).__init__(**kwargs)
self.nout = nout
self.alpha = self.add_weight(shape=(self.nout,), initializer='zeros',
trainable=True)
self.beta = self.add_weight(shape=(self.nout,), initializer='zeros',
trainable=True)
def call(self, inputs):
A, B = inputs
result = keras.layers.add([self.alpha*A ,self.beta*B])
result = keras.activations.tanh(result)
return result
def get_config(self):
config = super(MergeTwo, self).get_config()
config['nout'] = self.nout
return config
我阅读了文档,但是没有任何作用,我无法弄清原因。我正在使用Google Colab和Tensorflow版本2.2.0。