[英]Graph disconnected: cannot obtain value for tensor Tensor(“input_5:0”, shape=(None, None, None, 128), dtype=float32) at layer “input_5”
[英]Graph disconnected: cannot obtain value for tensor Tensor("input_1:0", shape=(None, 299, 299, 3), dtype=float32) at layer "input_1"
我正在嘗試將熱圖用於Xception
model(修改了頂層):
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: []
你定義
inputs = tf.keras.Input(shape=(299,299,3))
但是永遠不要在 model 中使用這個變量。你可能只是想
inputs = model.inputs
因為您正在加載現有的 model,而不是創建新的。
解決了:
conv_layer = tf.keras.Model(inputs= model.get_layer('xception').inputs,outputs=model.get_layer('xception').get_layer('block14_sepconv2_act').output)
model 斷開連接的原因,因此輸入和 output 應該是相同的 model。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.