there's a heavy Class instantiation that I don't want to include every api call. So what I've thought to do is instantiate the class on server start.
So what I've come up with is something like this:
from package import Classobj
from flask import Flask
cobj = Classobj(arg1, arg2)
app = Flask(__name__)
@app.route('/route', methods=['POST'])
def api_call():
res = cobj.foo(arg1,arg2)
return res
The class instantiation loads up a model, so it typically takes a few seconds just for that. The problem is, when I do it like this I get an error I can't trace.
Just this:
ValueError: Tensor Tensor("dense_1/Sigmoid:0", shape=(?, 4), dtype=float32) is not an element of this graph.
However, when I include the class instantiation on the api call, it works.
@app.route('/route', methods=['POST'])
def api_call():
cobj = Classobj(arg1, arg2)
res = cobj.foo(arg1,arg2)
return res
Still pretty new to Python, would appreciate any help. Thank you!