【问题标题】:Graph disconnected: cannot obtain value for tensor Tensor("input_1:0", shape=(None, 299, 299, 3), dtype=float32) at layer "input_1"图表已断开:无法在“input_1”层获取张量 Tensor("input_1:0", shape=(None, 299, 299, 3), dtype=float32) 的值
【发布时间】:2020-05-28 18:56:31
【问题描述】:

我正在尝试为Xception 模型使用热图(修改了顶层):

import tensorflow as to
import cv2
import numpy as np
label = 1
IMAGE_PATH = '/home/piyush/Desktop/HV/hv_2/deep-viz-keras/images/doberman.png'

img = tf.keras.preprocessing.image.load_img(IMAGE_PATH, target_size=(299, 299))
img = tf.keras.preprocessing.image.img_to_array(img)

model_path = '/home/piyush/Desktop/temp/model.h5'
model = tf.keras.models.load_model(model_path)
inputs = tf.keras.Input(shape=(299,299,3))
#print(model.summary())
#print([layer.shape for layer in model.get_layer('xception').layers])
final = tf.keras.Model(inputs=model.inputs, outputs=model.output)
print(model.inputs)
#extractor = tf.keras.Model(inputs=inputs, outputs=[layer.output for layer in model.layers])
conv_layer = tf.keras.Model(inputs=inputs,outputs=model.get_layer('xception').get_layer('block14_sepconv2_act').output)

如果我运行它,我会收到以下错误:

        conv_layer = tf.keras.Model(inputs=inputs, outputs=model.get_layer('xception').get_layer('block14_sepconv2_act').output)

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

【问题讨论】:

  • 您的输入变量根本没有连接到模型。

标签: python tensorflow keras deep-learning


【解决方案1】:

你定义

inputs = tf.keras.Input(shape=(299,299,3))

但是永远不要在模型中使用这个变量。你可能只是想要

inputs = model.inputs

因为您正在加载现有模型,而不是创建新模型。

【讨论】:

    【解决方案2】:

    已解决:

    conv_layer = tf.keras.Model(inputs= model.get_layer('xception').inputs,outputs=model.get_layer('xception').get_layer('block14_sepconv2_act').output)

    模型断开的原因,输入和输出应该是同一个模型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-31
      • 2019-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-25
      • 1970-01-01
      • 2019-09-24
      相关资源
      最近更新 更多