我正尝试在Keras中为递归卷积网络构建RCL块,如论文https://www.cv-foundation.org/openaccess/content_cvpr_2015/papers/Liang_Recurrent_Convolutional_Neural_2015_CVPR_paper.pdf
中所述使用我的自定义keras图层的模型得到编译,但是在保存模型运行1个历元后,我遇到了h5py抛出的错误:
h5py._objects.with_phil.wrapper()中的h5py / _objects.pyx
h5py._objects.with_phil.wrapper()中的h5py / _objects.pyx
hppy.h5o.link()中的h5py / h5o.pyx
RuntimeError:无法创建链接(名称已经存在)
我正在使用自定义图层中已经存在的keras图层:
class Recurrent_block(tf.keras.layers.Layer):
def __init__(self, ch_out,t):
self.num_outputs = num_outputs
self.t = t
self.ch_out = ch_out
super(Recurrent_block, self).__init__()
def build(self, input_shape)
self.shape = tf.TensorShape([input_shape[0].value,input_shape[1].value,input_shape[2].value,self.ch_out])
self.fc = tf.keras.models.Sequential([tf.keras.layers.Conv2D(filters=self.ch_out, kernel_size=(3,3), strides=(1, 1), padding='same'),tf.keras.layers.BatchNormalization(),tf.keras.layers.Activation('relu')])
self.fc.build(self.shape)
print(self.fc.trainable_weights)
self._trainable_weights = self.fc.trainable_weights
super(Recurrent_block, self).build(self.shape)
def call(self,x):
x = tf.keras.layers.Conv2D(self.ch_out,kernel_size=1,strides=(1, 1),padding='same')(x)
for i in range(self.t+1):
if i==0:
x1 = self.fc(x)
x1 = self.fc(x+x1)
return x1
有人可以帮助解决该错误,或者只是指导我如何将多个keras层组合到一个自定义层中,并以我的方式更改调用函数。