【发布时间】:2019-04-28 15:01:02
【问题描述】:
我正在使用 sjango,我正在尝试使用带有 tensorflow 后端的 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)
错误来自最后一行“模型预测”
提前感谢您的帮助
【问题讨论】:
-
我建议检查权重是否与架构相符。
-
是的,是一样的
标签: django python-3.x tensorflow machine-learning keras