首页 > 解决方案 > 如何在其他 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

标签: pythondjangokeras

解决方案


推荐阅读