Keras与Django整合问题(keras反复识别问题)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38003892/article/details/79073821

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

猜你喜欢

转载自blog.csdn.net/qq_38003892/article/details/79073821