且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在多线程中运行 Keras 模型进行预测

更新时间:2023-12-01 21:48:58

python 中的多线程不一定能更好地利用您的资源,因为 python 使用 全局解释器锁,并且一次只能运行一个本地线程.

multi threading in python doesn't necessarily make a better use of your resources since python uses global interpreter lock and only one native thread can run at a time.

在 python 中,通常你应该使用多处理来利用你的资源,但由于我们谈论的是 keras 模型,我不确定这样做是否正确.在多个进程中加载​​多个模型有其自身的开销,您可以简单地增加批量大小,正如其他人已经指出的那样.

in python, usually you should use multi processing to utilize your resources, but since we're talking about keras models, I'm not sure even that is the right thing to do. loading several models in several processes has its own overhead, and you could simply increase the batch size as others have already pointed out.

或者,如果您有一个繁重的预处理阶段,您可以在一个过程中预处理您的数据并在另一个过程中预测它们(尽管我怀疑这是否必要).

OR if you have a heavy pre-processing stage you could preprocess your data in one process and predict them in another (although I doubt that would be necessary either).