我有一个pythonrestapi(keras),它有5个模型文件供5个用户使用。当一个请求出现时,会发生以下情况 1检查用户 2加载该特定用户的相关模型 三。执行并输出结果。在
但我的问题是,当请求计数增加时,执行时间也会增加。 debug output in the console
post请求的代码如下(flask app):
my_path = os.path.abspath(os.path.dirname(__file__))
model_name = "./"+userName+"/model.h5"
scaler_name = "./"+userName+"/scaler.sc"
modelPath = os.path.join(my_path, model_name)
scalerPath = os.path.join(my_path, scaler_name)
start_time = time.time()
# load the model
model = load_model(modelPath)
scaler = joblib.load(scalerPath)
print("--- %s seconds ---" % (time.time() - start_time))
............
Keras不会删除您不再使用的模型,因此仍在使用内存。在
您可以尝试clear_session(),如here所示,或者如果模型相同,但具有不同的权重,则可以尝试重用模型,但替换权重。在
相关问题 更多 >
编程相关推荐