我正在使用Tensorflow 2.0和tf.keras构建一个暹罗网络。当我完成代码清理并开始培训时,弹出了一个错误。
我在网上找到的以下code中使用了此类。我添加了tensorflow.keras
(在某些情况下为tensorflow.python.keras
)而不是keras
,以确保不会遇到兼容性问题。我也删除了不必要的神经网络,因为我将使用该类作为样板。
使用VGG19作为基础,我编写了以下代码:
base = VGG19(weights='imagenet', include_top=False)
'''Inputs'''
inputA = base.input
inputB = base.input
'''Twin networks'''
net1 = base(inputA)
net2 = base(inputB)
'''Connecting the networks'''
normalized_layer = Normalized_Correlation_Layer(stride = (1,1), patch_size = (5, 5))([net1, net2])
'''Connecting the final layers'''
layer = Dense(1024, activation='relu')(normalized_layer)
layer = Dropout(0.2)(layer)
layer = Dense(1, activation='sigmoid')
model = Model(inputs=[inputA, inputB], outputs=layer)
model.summary
我希望对输出网络进行可视化,但是却得到了:
Traceback (most recent call last):
File "C:\Users\AyazA\Desktop\VOSNet\train.py", line 34, in <module>
normalized_layer = NCL(stride = (1,1), patch_size = (5, 5))([net1, net2])
File "C:\Python36\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 612, in __call__
outputs = self.call(inputs, *args, **kwargs)
File "C:\Users\AyazA\Desktop\VOSNet\backend\normalized_correlation.py", line 62, in call
inp_shape = input_1._keras_shape
AttributeError: 'Tensor' object has no attribute '_keras_shape'
我检查了代码的第62行,但似乎没有发现任何错误。 如果有帮助,请查看完整的code。