现象:
- 服务器上 运行flask接口;
- keras后端是tensorflow;
- 会出现线程扰动。
经常出现
FailedPreconditionError: Attempting to use uninitialized value batchnormalization_
或者Tensor Tensor("crf_1/cond/Merge:0", shape=(?, ?, 260), dtype=float32) is not an element of this graph.
使用keras.backend.clear_session()
可能会导致前后两处预测结果不一样,因为图发生了变化
或者直接失效。
解决办法:
在mianFlask.py
文件开头写上:
#### 开头
myYolo = YOLO()
global graph
graph = tf.get_default_graph()
#------------------
在mianFlask.py
文件中间,接口route调用模型推理的地方:
## 调用模型
startTime = timeit.default_timer() # 记录开始时间
with graph.as_default(): ######
imageResult, resultNum, resultLables= myYolo.detect_image(image) # 调用模型查询数据
endTime = timeit.default_timer() # 记录 结束时间
原文链接:https://lookme.blog.csdn.net/article/details/108451063
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
还没有人抢沙发呢~