简体   繁体   English

在 python 中并行化的好方法?

[英]Good method for parallelizing in python?

I have a quite simple task.我有一个非常简单的任务。 I have a video and first i have to slice it per frame, predict it using tensorflow, and combine those predicted frames into a single video.我有一个视频,首先我必须每帧对其进行切片,使用 tensorflow 对其进行预测,然后将这些预测帧组合成一个视频。 Here's the result I got:这是我得到的结果:

Slicing ... Time elapsed since last slice : 0s. Frame-1
.
Slicing ... Time elapsed since last slice : 2.0517446994781494s. Frame-2
.
Slicing ... Time elapsed since last slice : 0.8912339210510254s. Frame-3
.
Slicing ... Time elapsed since last slice : 0.8657193183898926s. Frame-4
.
Slicing ... Time elapsed since last slice : 0.8655312061309814s. Frame-5
.
Slicing ... Time elapsed since last slice : 0.8827650547027588s. Frame-6
.
Slicing ... Time elapsed since last slice : 0.8690683841705322s. Frame-7
.
Slicing ... Time elapsed since last slice : 0.8906550407409668s. Frame-8
.
Slicing ... Time elapsed since last slice : 0.8798754215240479s. Frame-9
.
Slicing ... Time elapsed since last slice : 0.9341959953308105s. Frame-10

each frame took about 0.8 second.每帧大约需要 0.8 秒。 Let's say i have a 5 seconds video with 30 fps.假设我有一个 30 fps 的 5 秒视频。 It will take about 120 seconds to process.处理大约需要 120 秒。

I have a thought about parallelizing for this like multithreading etc. Is this even possible?我有一个关于并行化的想法,比如多线程等。这甚至可能吗? Where do I have to start?我必须从哪里开始? Thank you.谢谢你。

You can try out multiprocessing package in python.您可以在 python 中尝试多处理 package。 For more details refer: https://docs.python.org/3/library/multiprocessing.html .有关详细信息,请参阅: https://docs.python.org/3/library/multiprocessing.html

Or other thing you can try out is to Maximize TensorFlow Performance on CPU by optimization.或者您可以尝试的其他方法是通过优化最大化 CPU 上的 TensorFlow 性能。 The primary goal of the performance optimization is to make use of all the cores available in the machine and thereby speed up the process.性能优化的主要目标是利用机器中所有可用的内核,从而加快进程。 This can be achieved by setting the intra_op_parallelism_threads, inter_op_parallelism_threads, OMP_NUM_THREADS etc.这可以通过设置 intra_op_parallelism_threads、inter_op_parallelism_threads、OMP_NUM_THREADS 等来实现。

Please refer: https://software.intel.com/en-us/articles/maximize-tensorflow-performance-on-cpu-considerations-and-recommendations-for-inference请参考: https://software.intel.com/en-us/articles/maximize-tensorflow-performance-on-cpu-considerations-and-recommendations-for-inference

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM