python - 跳过连接: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']
非常感谢你的帮助
解决方案
推荐阅读
- python - PyCharm 运行窗口在完成运行代码后自动关闭
- excel - 在 Word 文档上查找整个单词并替换
- python - Python从任意类继承方法
- azure - 停止创建 Log Analytics 工作区
- python - NameError:名称'X'未定义sklearn
- docker - 在 Docker 容器中包含 NuGet 私有源的安全方法
- asp.net-mvc - .NET Core WebAPI 在缺少次要版本的情况下回退 API 版本
- sdk - 为什么在尝试运行 Yarn start 时出现以下错误
- c# - 如何在 ASP.NET MVC 视图中将存储在模型变量中的格式化资源字符串呈现为 HTML?
- python - 将文件中某个文本字段内的双引号替换为单引号。Python