Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Keras添加层和非类型:类型错误,不可下标_Python_Tensorflow_Keras_Computer Vision_Conv Neural Network - Fatal编程技术网

Python Keras添加层和非类型:类型错误,不可下标

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”

我正在尝试使用预训练的VGG16模型作为编码器部分,为Keras中的分段创建一个FCN。现在在解码器部分,我尝试将转置卷积层的输出添加到VGG模型早期层的输出中

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))