Python Keras添加层和非类型:类型错误,不可下标
我正在尝试使用预训练的VGG16模型作为编码器部分,为Keras中的分段创建一个FCN。现在在解码器部分,我尝试将转置卷积层的输出添加到VGG模型早期层的输出中Python Keras添加层和非类型:类型错误,不可下标,python,tensorflow,keras,computer-vision,conv-neural-network,Python,Tensorflow,Keras,Computer Vision,Conv Neural Network,我正在尝试使用预训练的VGG16模型作为编码器部分,为Keras中的分段创建一个FCN。现在在解码器部分,我尝试将转置卷积层的输出添加到VGG模型早期层的输出中 x = Conv2DTranspose(layer4.output_shape[-1], 4, strides=2, padding="same", activation="relu")(x) x = Add()([x, layer4]) 但是它抛出了一个TypeError:“NoneType”
x = Conv2DTranspose(layer4.output_shape[-1], 4, strides=2, padding="same", activation="relu")(x)
x = Add()([x, layer4])
但是它抛出了一个TypeError:“NoneType”对象在Add
层的build函数中不可下标
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-39-0915433797bf> in <module>()
7 # add a deconvolution layer, add skip with layer 4
8 x = Conv2DTranspose(layer4.output_shape[-1], 4, strides=2, padding="same", activation="relu")(x)
----> 9 x = Add()([x, layer4])
10
11 # another deconvolution layer with layer 3
3 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/layers/merge.py in build(self, input_shape)
90 def build(self, input_shape):
91 # Used purely for shape validation.
---> 92 if not isinstance(input_shape[0], tuple):
93 raise ValueError('A merge layer should be called on a list of inputs.')
94 if len(input_shape) < 2:
但是由于某种原因,tf.add
不喜欢使用Keras层
不管怎样,解决这个问题的最佳方法是什么?我可以使输入形状固定,但我认为FCN的优点是它可以接受可变的输入形状。您能分享第4层的定义吗?你如何让它脱离VGG网络?也许尝试一下shape
而不是output\u shape
:x=conv2dtranpse(layer4.shape[-1],4,strips=2,padding=“same”,activation=“relu”)(x)
我通过的模型keras.applications.vgg16.vgg16(include\u top=False)
和layer4
是块4的池层,它是base\u模型。get\u层(“块4\u池”)
layer4
没有属性shape
。它只有input\u-shape
和output\u-shape
。您能分享第4层的定义吗?你如何让它脱离VGG网络?也许尝试一下shape
而不是output\u shape
:x=conv2dtranpse(layer4.shape[-1],4,strips=2,padding=“same”,activation=“relu”)(x)
我通过的模型keras.applications.vgg16.vgg16(include\u top=False)
和layer4
是块4的池层,它是base\u模型。get\u层(“块4\u池”)
layer4
没有属性shape
。它只有input\u-shape
和output\u-shape
。
x = Lambda(lambda x: tf.add(x[0], x[1]))((x, layer4))