且构网

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

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

更新时间:2023-12-01 21:40:52

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).