using multiprocessing with theano

≡放荡痞女 提交于 2019-12-04 14:12:53

It is possible to use multiple processes if the other processes do not use keras, to my knowledge you need to restrict usage of keras to a single process. This seems to include all keras classes and methods, even those who do not seem to use the gpu, e.g. ImageDataGenerator.

If the workload is GPU limited it is also possible to use the threading library, which creates threads instead of processes, e.g. to load data while the GPU processes the previous batch, then the restriction does not apply. Due to the global interpreter lock this is not a solution in CPU limited environments.

Your situation looks like a parallel [read, do work on GPU, write]. This can be reformed to a pipeline, e.g. some processes reading, the main process performing GPU work and some processes writing.

  1. Create Queue objects for input/output (threading.Queue or multiprocessing.Queue)
  2. Create background worker threads/processes which read data from disk and feed it to the input queue
  3. Create background worker threads/processes which write data from the output queue to disk
  4. main loop which takes data from the input queue, creates batches, processes the data on the gpu and fills the output queue
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!