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()

你可能感兴趣的:(problem)