Keras與Django整合問題(keras反覆識別問題)

(1)問題描述:在利用keras與django時,識別上傳圖片時,第一次可以識別,但是第二次上傳就會出現如下錯誤:

TypeError at /info/
Cannot interpret feed_dict key as Tensor: Tensor Tensor("Placeholder:0", shape=(3, 3, 3, 32), dtype=float32) is not an element of this graph.
Request Method: POST
Request URL:    http://127.0.0.1:8000/info/
Django Version: 1.8.2
Exception Type: TypeError
Exception Value:    
Cannot interpret feed_dict key as Tensor: Tensor Tensor("Placeholder:0", shape=(3, 3, 3, 32), dtype=float32) is not an element of this graph.
Exception Location: G:\ac\lib\site-packages\tensorflow\python\client\session.py in _run, line 1071
Python Executable:  G:\ac\python.exe
Python Version: 3.6.3

(2)分析錯誤原因:因爲第二次上傳依然使用的是第一次創建的model,所以第二次上傳沒有輸入。
(3)解決方案:在創建model之前清理session

keras.backend.clear_session()
model = Sequential()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章