我有 3 个工作 Keras 模型,每个模型我用 2 个文件structure.json(保存模型结构)和weight.h5保存它。
我已经构建了一个 Flask 应用程序来加载这些模型。但目前我无法像这样将 threading=True 添加到 run() 选项中:
api.run(threaded=True)
Run Code Online (Sandbox Code Playgroud)
所以我只能使用:
api.run()
Run Code Online (Sandbox Code Playgroud)
在这个烧瓶应用程序中,我有两个不同的 api(1 GET 和 1 POST)。因为它在一个线程上运行,所以运行速度太慢。我的系统每秒有 100 多个连接,每个连接我都必须加载另一个模型。
请注意,我所有的 keras 模型都具有相同的结构。我只需要加载一个结构,每当有新的连接出现时,我都会为该结构加载重量。
我在 api 中的代码是这样的:
# Compile model
json_file = open(formal_model_path, 'r')
loaded_model_json = json_file.read()
json_file.close()
model = model_from_json(loaded_model_json)
model.compile(loss='mean_absolute_error', optimizer='adam')
@api.route("/predict", methods=["POST"])
try:
model.load_weights(os.path.join(cointainer_folder, 'weight.h5'))
except Exception:
return jsonify(
error_code='model_file_reading_failed'
)
Run Code Online (Sandbox Code Playgroud)
我的代码在model.load_weights[...]行启用 threading=True 时出错。
是否有任何解决方案可以通过加载许多不同的 Keras 模型来构建多线程 API?
谁能帮我解释一下时间分布式层(来自Keras Wrapper)和 ConvLSTM-2D (卷积 LSTM)之间的差异,目的、用法等?