首页 > 解决方案 > 跳过连接:ValueError:图表已断开:无法获取张量张量的值

问题描述

我正在尝试在自动编码器架构中添加跳过连接,但遇到了图形断开连接错误。

我在谷歌上看了看,但没有一个建议的解决方案对我有用。

这是我的代码:

  HEIGHT = 80 ##80#
  WIDTH = 320 #320#
  width =WIDTH
  height = HEIGHT

  padding_="same"
  depth=1

  inputShape = (height, width, depth)
  # define the input to the encoder
  input_img = Input(shape=inputShape)
  #print( input_img.shape)


  x = Conv2D(filters[0], (3, 3), padding='same')(input_img)
  x = BatchNormalization()(x)
  x = Activation('relu')(x)
  x = MaxPooling2D((2, 2), padding='same')(x)
  #print(x.shape)

  ############################################################################
  x = Conv2D(filters[1], (3, 3), padding='same')(x)
  x = BatchNormalization()(x)
  x = Activation('relu')(x)
  x1=x
  x = MaxPooling2D((2, 2), padding='same')(x)
  #print(x.shape)
  ############################################################################


  x = Conv2D(filters[2], (3, 3), padding='same')(x)
  x = BatchNormalization()(x)
  x = Activation('relu')(x)
  x = MaxPooling2D((2, 2), padding='same')(x)
  #print(x.shape)

  x = Conv2D(filters[3], (3, 3), padding='same')(x)
  x = BatchNormalization()(x)
  x = Activation('relu')(x)
  #print(x.shape)
  encoded = MaxPooling2D((2, 2), padding='same')(x)

  # flatten the network and then construct our latent vector
  volumeSize = K.int_shape(encoded)
  x = Flatten()(encoded)
  #print(x.shape)
  latent = Dense(latentDim)(x)
  #print(latent.shape)
  # build the encoder model
  encoder = Model(input_img, latent, name="encoder")

  # start building the decoder model which will accept the
  # output of the encoder as its inputs
  latentInputs = Input(shape=(latentDim,))
  x = Dense(np.prod(volumeSize[1:]))(latentInputs)
  x = Reshape((volumeSize[1], volumeSize[2], volumeSize[3]))(x)  # becomes like encoded 2D
  #print(x.shape)


  ############################################################################
  x = Conv2D(filters[3], (3, 3), padding='same')(x)
  x = BatchNormalization()(x)
  x = Activation('relu')(x)
  x = UpSampling2D((2, 2))(x)
  #print(x.shape)
  ############################################################################



  x = Conv2D(filters[2], (3, 3), padding='same')(x)
  x = BatchNormalization()(x)
  x = Activation('relu')(x)
  x = UpSampling2D((2, 2))(x)
  #print(x.shape)


  x = Conv2D(filters[1], (3, 3), padding='same')(x)
  x = BatchNormalization()(x)
  x = Activation('relu')(x)
  x = UpSampling2D((2, 2))(x)

  # x = tf.keras.layers.Add()([x1, x])
  x=concatenate([x1,x])
  #print(x.shape)

  x = Conv2D(filters[0], (3, 3), padding='same')(x)
  x = BatchNormalization()(x)
  x = Activation('relu')(x)
  #print(x.shape)


  x = UpSampling2D((2, 2))(x)
  x = Conv2D(1, (3, 3), padding='same')(x)
  x = BatchNormalization()(x)
  #print(x.shape)
  decoded = Activation('sigmoid')(x)
  # build the decoder model

  decoder = Model(latentInputs, decoded)
  # our autoencoder is the encoder + decoder
  autoencoder = Model(input_img, decoder(encoder(input_img)),name="autoencoder")

这是错误

ValueError: Graph disconnected: 无法在“conv2d_174”层获取张量 Tensor("input_41:0", shape=(None, 80, 320, 1), dtype=float32) 的值。访问以下之前的图层没有问题:['dense_41', 'reshape_20', 'conv2d_178', 'batch_normalization_177', 'activation_177', 'up_sampling2d_76', 'conv2d_179', 'batch_normalization_178']

这是我的编码器解码器的绘制图

非常感谢你的帮助

标签: pythontensorflowkerasdeep-learning

解决方案


推荐阅读