python - 如何在其他 python 文件中使用 keras 模型?在 django
问题描述
加载模型太慢了,所以我在settings.py中加载模型。然后我在其他文件中重用模型,模型没有加载。
但我收到以下错误:
"Tensor Tensor("predictions/Softmax:0", shape=(?, 3), dtype=float32) is not an element of this graph"
许多人说这个错误类似于在上下文管理器中使用时发生的错误:
with graph.as_default():
和
with sess.as_default():
但这对我不起作用,我猜这个答案适用于在多线程情况下加载模型。
如果你能帮助我,我真的很感激。
我的部分代码如下
*****settings.py/the file where to load the models*****
from keras.models import load_model
GMODEL = load_model(MODEL_ROOT +'/MobileNetV2(full).h5')
*****function.py/the file where to reuse the models*****
from django.conf import settings
model = settings.GMODEL
解决方案
推荐阅读
- javascript - 清除没有画布的 HTML 页面
- spring-boot - 403 Forbidden post request spring boot not working
- https - 使用linkedin api评论帖子返回403虽然我拥有所需的所有权限
- wordpress - preg_replace 特定文本到较小的后者 strtolower
- c - 是否有将图像点拉伸到 SDL2 中渲染器部分的功能?
- node.js - 使用 pm2 命令列出所有环境参数
- mysql - 货币交易的 SQL 模型解决方案?
- java - 如何在 for 循环中创建公共变量
- autodesk-forge - 添加绘图文档时出现未指定的错误
- angular - 如何为按钮循环创建角度模式弹出窗口