有人看到图形断开是从哪里来的吗?

2021-11-29 23:13:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下错误抛出,虽然我没有看到断开发生的地方。你知道吗

我想知道有没有人知道怎么修?我将附上下面的代码和错误的完整回溯。提前谢谢你的帮助。你知道吗

from keras.layers import Conv2D, UpSampling2D, LeakyReLU, Concatenate, Lambda, Input, UpSampling2D
from tensorflow.keras import Model
from keras.applications.densenet import DenseNet169


'''
Following is to get layers for skip connection and num_filters
'''
base_model = DenseNet169(include_top=False,input_shape=(224,224,3))
base_model_output_shape=base_model.layers[-1].output.shape
decoder_filters = int(base_model_output_shape[-1]/2)

def UpProject(array,filters,name,concat_with):
    up_i = UpSampling2D((2,2),interpolation='bilinear')(array)
    up_i=Concatenate(name=name+'_concat')([up_i,base_model.get_layer(concat_with).output])  #skip connection
    up_i=Conv2D(filters=filters,kernel_size=3,strides=1,padding='same',name=name+'_convA')(up_i)
    up_i=LeakyReLU(alpha=.2)(up_i)
    up_i=Conv2D(filters=filters,kernel_size=3,strides=1,padding='same',name=name+'_convB')(up_i)
    up_i=LeakyReLU(alpha=.2)(up_i)

    return up_i

def get_Model():
    #encoder network
    img_inp_shape=(224,224,3)
    img_input = Input(img_inp_shape)
    normalized = Lambda(lambda x: x/256 - .5)(img_input)
    encoded = base_model(normalized)


    #begin decoding 
    decoder = Conv2D(filters=decoder_filters,kernel_size=1,padding='same',input_shape=base_model_output_shape,name='conv2')(encoded)
    decoder = UpProject(decoder,int(decoder_filters/2),'up_1','pool3_pool')
    decoder = UpProject(decoder,int(decoder_filters/4),'up_2','pool2_pool')
    decoder = UpProject(decoder,int(decoder_filters/8),'up_3','pool1')
    decoder = UpProject(decoder,int(decoder_filters/16),'up_4','conv1/relu')

    conv3 = Conv2D(filters=1,kernel_size=3,strides=1,padding='same',name='conv3')(decoder)

    model = Model(inputs=img_input,outputs=conv3)

    return model

model = get_Model()

错误消息:

Traceback (most recent call last):

  File "<ipython-input-2-eef68b7cc748>", line 1, in <module>
    model = get_Model()

  File "C:/Users/Alec/.spyder-py3/depth_functional.py", line 40, in get_Model
    model = Model(inputs=img_input,outputs=conv3)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\network.py", line 94, in __init__
    self._init_graph_network(*args, **kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\network.py", line 241, in _init_graph_network
    self.inputs, self.outputs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\network.py", line 1511, in _map_graph_network
    str(layers_with_complete_input))

ValueError: Graph disconnected: cannot obtain value for tensor Tensor("input_1:0", shape=(None, 224, 224, 3), dtype=float32) at layer "input_1". The following previous layers were accessed without issue: []