簡體   English   中英

預測時具有張量流錯誤的Keras

[英]Keras with tensorflow error when prediction

我使用sjango並且我正在嘗試使用具有張量流后端的Keras來預測圖像,但是我有這樣的錯誤:

line 3669, in _as_graph_element_locked
    raise ValueError("Tensor %s is not an element of this graph." % obj)
ValueError: Tensor Tensor("dense_6/Softmax:0", shape=(?, 50), dtype=float32) is not an element of this graph.
[28/Apr/2019 16:54:53] "POST /facture/upload/ HTTP/1.1" 500 133945

這是我的代碼:

#Loading the model 
pwd = os.path.dirname(__file__)
with open(pwd+'/ModelML/model_architecture19.json', 'r') as f:
    model = model_from_json(f.read())
# Load weights into the new model
model.load_weights(pwd+'/ModelML/model_weights19.h5')



roi = cv2.cvtColor(roi,cv2.COLOR_BGR2GRAY)
            ret2, roi = cv2.threshold(roi, 127, 255, cv2.THRESH_BINARY_INV)    
            roi = cv2.resize(roi, (IMG_SIZE, IMG_SIZE)) # Resize the image
            roi = roi.reshape(1,IMG_SIZE, IMG_SIZE,1)
            #normalize image
            roi = roi /255 


            graph = tf.get_default_graph()
            with graph.as_default():
                pred =model.predict(roi)

錯誤來自最后一行“模型預測”

在此先感謝您的幫助

函數或方法中是否為graph = tf.get_default_graph()

怎么樣在model.load_weights(pwd+'/ModelML/model_weights19.h5')之后移動它?

這些線

pwd = os.path.dirname(__file__)
with open(pwd+'/ModelML/model_architecture19.json', 'r') as f:
    model = model_from_json(f.read())
# Load weights into the new model
model.load_weights(pwd+'/ModelML/model_weights19.h5')
graph = tf.get_default_graph()

應該在任何階級或職能范圍之外。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM