NoneType'对象没有属性'_inbound_nodes

时间:2018-06-22 01:58:36

标签: keras

嗨,我一直在努力解决这个问题,尽管我无法真正弄清楚。对于我的特殊情况,我将不胜感激。非常感谢你!我的网络结构如下:

def get_unet(self):
    inputs = Input((self.img_rows, self.img_cols, 1))

    conv1 = Conv2D(64, 3, activation='relu', padding='same', kernel_initializer='he_normal')(inputs)
    conv1 = Conv2D(64, 3, activation='relu', padding='same', kernel_initializer='he_normal')(conv1)
    pool1 = MaxPooling2D(pool_size=(2, 2))(conv1)

    conv2 = Conv2D(128, 3, activation='relu', padding='same', kernel_initializer='he_normal')(pool1)
    conv2 = Conv2D(128, 3, activation='relu', padding='same', kernel_initializer='he_normal')(conv2)
    pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)

    conv3 = Conv2D(256, 3, activation='relu', padding='same', kernel_initializer='he_normal')(pool2)
    conv3 = Conv2D(256, 3, activation='relu', padding='same', kernel_initializer='he_normal')(conv3)
    pool3 = MaxPooling2D(pool_size=(2, 2))(conv3)

    conv4 = Conv2D(512, 3, activation='relu', padding='same', kernel_initializer='he_normal')(pool3)
    conv4 = Conv2D(512, 3, activation='relu', padding='same', kernel_initializer='he_normal')(conv4)
    drop4 = Dropout(0.5)(conv4)
    pool4 = MaxPooling2D(pool_size=(2, 2))(drop4)

    conv5 = Conv2D(1024, 3, activation='relu', padding='same', kernel_initializer='he_normal')(pool4)
    conv5 = Conv2D(1024, 3, activation='relu', padding='same', kernel_initializer='he_normal')(conv5)
    drop5 = Dropout(0.5)(conv5)

    up6 = Conv2D(512, 2, activation='relu', padding='same', kernel_initializer='he_normal')(
        UpSampling2D(size=(2, 2))(drop5))
    print("drop4 shape",type(drop4),drop4.shape)
    print("up6 shape",type(up6),up6.shape)

    merge6=tf.concat([drop4, up6], axis=3)
    print(merge6.shape)
    conv6 = Conv2D(512, 3, activation='relu', padding='same', kernel_initializer='he_normal')(merge6)
    conv6 = Conv2D(512, 3, activation='relu', padding='same', kernel_initializer='he_normal')(conv6)
    up7 = Conv2D(256, 2, activation='relu', padding='same', kernel_initializer='he_normal')(
        UpSampling2D(size=(2, 2))(conv6))
    print("conv3,up7",conv3.shape,up7.shape)
    merge7 =tf.concat([conv3, up7],axis=3)
    conv7 = Conv2D(256, 3, activation='relu', padding='same', kernel_initializer='he_normal')(merge7)
    conv7 = Conv2D(256, 3, activation='relu', padding='same', kernel_initializer='he_normal')(conv7)

    up8 = Conv2D(128, 2, activation='relu', padding='same', kernel_initializer='he_normal')(
        UpSampling2D(size=(2, 2))(conv7))
    print("conv2,up8",conv2.shape,up8.shape)
    merge8 = tf.concat([conv2, up8],axis=3)
    conv8 = Conv2D(128, 3, activation='relu', padding='same', kernel_initializer='he_normal')(merge8)
    conv8 = Conv2D(128, 3, activation='relu', padding='same', kernel_initializer='he_normal')(conv8)

    up9 = Conv2D(64, 2, activation='relu', padding='same', kernel_initializer='he_normal')(
        UpSampling2D(size=(2, 2))(conv8))
    print("conv1,up9",conv1.shape,up9.shape)

    merge9 = tf.concat([conv1, up9], axis=3)
    print("merge9 shape",merge9.shape)
    conv9 = Conv2D(64, 3, activation='relu', padding='same', kernel_initializer='he_normal')(merge9)
    conv9 = Conv2D(64, 3, activation='relu', padding='same', kernel_initializer='he_normal')(conv9)
    conv9 = Conv2D(2, 3, activation='relu', padding='same', kernel_initializer='he_normal')(conv9)
    conv10 = Conv2D(1, 1, activation='sigmoid')(conv9)
    print("conv10 shape",conv10.shape)
    print("inputs shape1,outputs conv10  shape2",inputs.shape,conv10.shape)
    model = Model(inputs=inputs, outputs=conv10)

    model.compile(optimizer=Adam(lr=1e-4), loss='binary_crossentropy', metrics=['accuracy'])
    print('model compile')
    return model

这是错误:

  model = Model(inputs=inputs, outputs=conv10)
  File "/usr/local/lib/python3.5/dist-packages/keras/legacy/interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/network.py", line 91, in __init__
    self._init_graph_network(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/network.py", line 235, in _init_graph_network
    self.inputs, self.outputs)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/network.py", line 1412, in _map_graph_network
    tensor_index=tensor_index)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/network.py", line 1399, in build_map
    node_index, tensor_index)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/network.py", line 1399, in build_map
    node_index, tensor_index)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/network.py", line 1399, in build_map
    node_index, tensor_index)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/network.py", line 1399, in build_map
    node_index, tensor_index)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/network.py", line 1371, in build_map
    node = layer._inbound_nodes[node_index]
AttributeError: 'NoneType' object has no attribute '_inbound_nodes'

1 个答案:

答案 0 :(得分:1)

将您所有的tf.concat()替换为keras.layers.concatenate()。这就是问题所在。另外,如果还没有更新,请更新您的keras。