图断开连接:无法获取张量 Tensor("conv2d_1_input:0", shape=(?, 128, 128, 1), dtype=float32) 的值
Graph disconnected: cannot obtain value for tensor Tensor("conv2d_1_input:0", shape=(?, 128, 128, 1), dtype=float32)
我正在尝试实现一个自动编码器,它获取 3 个不同的输入并融合这三个图像。我想获得编码器中一个层的输出并将其与解码器中的一个层连接但是当我 运行 它时我得到图形断开连接错误。
这是我的代码:
def create_model(input_shape):
input_1 = keras.layers.Input(input_shape)
input_2 = keras.layers.Input(input_shape)
input_3 = keras.layers.Input(input_shape)
network = keras.models.Sequential([
keras.layers.Conv2D(32, (7, 7), activation=tf.nn.relu, padding='SAME',input_shape=input_shape),
keras.layers.Conv2D(32, (7, 7), activation=tf.nn.relu, padding='SAME', name = 'a'),
keras.layers.AvgPool2D((2, 2)),
keras.layers.BatchNormalization(),
keras.layers.Dropout(0.3)])
encoded_1 = network(input_1)
encoded_2 = network(input_2)
encoded_3 = network(input_3)
a = network.get_layer('a').output
x = keras.layers.Concatenate()([encoded_1,encoded_2,encoded_3])
x = keras.layers.Conv2D(32, (3, 3), activation=tf.nn.relu, padding='SAME')(x)
x = keras.layers.UpSampling2D((2,2))(x)
x = keras.layers.BatchNormalization()(x)
x = keras.layers.Dropout(0.3)(x)
x = keras.layers.Concatenate()([x,a])
x = keras.layers.Conv2D(32, (3, 3), activation=tf.nn.relu, padding='SAME')(x)
x = keras.layers.UpSampling2D((2,2))(x)
x = keras.layers.BatchNormalization()(x)
x = keras.layers.Dropout(0.3)(x)
decoded = keras.layers.Conv2D(3, (3, 3), activation=tf.nn.relu, padding='SAME')(x)
final_net= keras.models.Model(inputs=[input_1,input_2,input_3],outputs=decoded)
return final_net
错误是:
Graph disconnected: cannot obtain value for tensor Tensor("conv2d_1_input:0", shape=(?, 128, 128, 1), dtype=float32) at layer "conv2d_1_input". The following previous layers were accessed without issue: ['input_6', 'input_5', 'input_4', 'sequential_1', 'sequential_1', 'sequential_1', 'concatenate', 'conv2d_2']
是因为拼接了[x,a]。我试图从三个图像中获取层的输出,例如:
encoder_1.get_layer('a').output
encoder_2.get_layer('a').output
encoder_3.get_layer('a').output
但我收到错误消息“'Tensor' 对象没有属性 'output'”
如果您需要获得 a1
、a2
和 a3
输出,则需要创建子网。并且可以如下连接x
和a
。
def create_model(input_shape):
input_1 = keras.layers.Input(input_shape)
input_2 = keras.layers.Input(input_shape)
input_3 = keras.layers.Input(input_shape)
network = keras.models.Sequential([
keras.layers.Conv2D(32, (7, 7), activation=tf.nn.relu, padding='SAME',input_shape=input_shape),
keras.layers.Conv2D(32, (7, 7), activation=tf.nn.relu, padding='SAME', name = 'a'),
keras.layers.AvgPool2D((2, 2)),
keras.layers.BatchNormalization(),
keras.layers.Dropout(0.3)])
encoded_1 = network(input_1)
encoded_2 = network(input_2)
encoded_3 = network(input_3)
subnet = keras.models.Sequential()
for l in network.layers:
subnet.add(l)
if l.name == 'a': break
a1 = subnet(input_1)
a2 = subnet(input_2)
a3 = subnet(input_3)
x = keras.layers.Concatenate()([encoded_1,encoded_2,encoded_3])
a = keras.layers.Concatenate()([a1,a2,a3])
x = keras.layers.Conv2D(32, (3, 3), activation=tf.nn.relu, padding='SAME')(x)
x = keras.layers.UpSampling2D((2,2))(x)
x = keras.layers.BatchNormalization()(x)
x = keras.layers.Dropout(0.3)(x)
x = keras.layers.Concatenate()([x,a])
x = keras.layers.Conv2D(32, (3, 3), activation=tf.nn.relu, padding='SAME')(x)
x = keras.layers.UpSampling2D((2,2))(x)
x = keras.layers.BatchNormalization()(x)
x = keras.layers.Dropout(0.3)(x)
decoded = keras.layers.Conv2D(3, (3, 3), activation=tf.nn.relu, padding='SAME')(x)
final_net= keras.models.Model(inputs=[input_1,input_2,input_3],outputs=decoded)
return final_net
我正在尝试实现一个自动编码器,它获取 3 个不同的输入并融合这三个图像。我想获得编码器中一个层的输出并将其与解码器中的一个层连接但是当我 运行 它时我得到图形断开连接错误。 这是我的代码:
def create_model(input_shape):
input_1 = keras.layers.Input(input_shape)
input_2 = keras.layers.Input(input_shape)
input_3 = keras.layers.Input(input_shape)
network = keras.models.Sequential([
keras.layers.Conv2D(32, (7, 7), activation=tf.nn.relu, padding='SAME',input_shape=input_shape),
keras.layers.Conv2D(32, (7, 7), activation=tf.nn.relu, padding='SAME', name = 'a'),
keras.layers.AvgPool2D((2, 2)),
keras.layers.BatchNormalization(),
keras.layers.Dropout(0.3)])
encoded_1 = network(input_1)
encoded_2 = network(input_2)
encoded_3 = network(input_3)
a = network.get_layer('a').output
x = keras.layers.Concatenate()([encoded_1,encoded_2,encoded_3])
x = keras.layers.Conv2D(32, (3, 3), activation=tf.nn.relu, padding='SAME')(x)
x = keras.layers.UpSampling2D((2,2))(x)
x = keras.layers.BatchNormalization()(x)
x = keras.layers.Dropout(0.3)(x)
x = keras.layers.Concatenate()([x,a])
x = keras.layers.Conv2D(32, (3, 3), activation=tf.nn.relu, padding='SAME')(x)
x = keras.layers.UpSampling2D((2,2))(x)
x = keras.layers.BatchNormalization()(x)
x = keras.layers.Dropout(0.3)(x)
decoded = keras.layers.Conv2D(3, (3, 3), activation=tf.nn.relu, padding='SAME')(x)
final_net= keras.models.Model(inputs=[input_1,input_2,input_3],outputs=decoded)
return final_net
错误是:
Graph disconnected: cannot obtain value for tensor Tensor("conv2d_1_input:0", shape=(?, 128, 128, 1), dtype=float32) at layer "conv2d_1_input". The following previous layers were accessed without issue: ['input_6', 'input_5', 'input_4', 'sequential_1', 'sequential_1', 'sequential_1', 'concatenate', 'conv2d_2']
是因为拼接了[x,a]。我试图从三个图像中获取层的输出,例如:
encoder_1.get_layer('a').output
encoder_2.get_layer('a').output
encoder_3.get_layer('a').output
但我收到错误消息“'Tensor' 对象没有属性 'output'”
如果您需要获得 a1
、a2
和 a3
输出,则需要创建子网。并且可以如下连接x
和a
。
def create_model(input_shape):
input_1 = keras.layers.Input(input_shape)
input_2 = keras.layers.Input(input_shape)
input_3 = keras.layers.Input(input_shape)
network = keras.models.Sequential([
keras.layers.Conv2D(32, (7, 7), activation=tf.nn.relu, padding='SAME',input_shape=input_shape),
keras.layers.Conv2D(32, (7, 7), activation=tf.nn.relu, padding='SAME', name = 'a'),
keras.layers.AvgPool2D((2, 2)),
keras.layers.BatchNormalization(),
keras.layers.Dropout(0.3)])
encoded_1 = network(input_1)
encoded_2 = network(input_2)
encoded_3 = network(input_3)
subnet = keras.models.Sequential()
for l in network.layers:
subnet.add(l)
if l.name == 'a': break
a1 = subnet(input_1)
a2 = subnet(input_2)
a3 = subnet(input_3)
x = keras.layers.Concatenate()([encoded_1,encoded_2,encoded_3])
a = keras.layers.Concatenate()([a1,a2,a3])
x = keras.layers.Conv2D(32, (3, 3), activation=tf.nn.relu, padding='SAME')(x)
x = keras.layers.UpSampling2D((2,2))(x)
x = keras.layers.BatchNormalization()(x)
x = keras.layers.Dropout(0.3)(x)
x = keras.layers.Concatenate()([x,a])
x = keras.layers.Conv2D(32, (3, 3), activation=tf.nn.relu, padding='SAME')(x)
x = keras.layers.UpSampling2D((2,2))(x)
x = keras.layers.BatchNormalization()(x)
x = keras.layers.Dropout(0.3)(x)
decoded = keras.layers.Conv2D(3, (3, 3), activation=tf.nn.relu, padding='SAME')(x)
final_net= keras.models.Model(inputs=[input_1,input_2,input_3],outputs=decoded)
return final_net