class_docstr: Run prediction in multiple processes, on either CPU or GPU.
  Each process fetch datapoints as tasks and run predictions independently.
class_docstr_tok: ["Run","prediction","in","multiple","processes",",","on","either","CPU","or","GPU",".","Each","process","fetch","datapoints","as","tasks","and","run","predictions","independently","."]
docstr: Args:
      config: same as in :class:`DatasetPredictorBase`.
      dataset: same as in :class:`DatasetPredictorBase`.
      nr_proc (int): number of processes to use
      use_gpu (bool): use GPU or CPU.
          If GPU, then ``nr_proc`` cannot be more than what's in
          CUDA_VISIBLE_DEVICES.
      ordered (bool): produce outputs in the original order of the
          datapoints. This will be a bit slower. Otherwise, :meth:`get_result` will produce
          outputs in any order.
docstr_tok: ["Args",":","config",":","same","as","in",":","class",":","`","DatasetPredictorBase","`",".","dataset",":","same","as","in",":","class",":","`","DatasetPredictorBase","`",".","nr_proc","(","int",")",":","number","of","processes","to","use","use_gpu","(","bool",")",":","use","GPU","or","CPU",".","If","GPU",",","then","``","nr_proc","``","can","not","be","more","than","what","'s","in","CUDA_VISIBLE_DEVICES",".","ordered","(","bool",")",":","produce","outputs","in","the","original","order","of","the","datapoints",".","This","will","be","a","bit","slower",".","Otherwise",",",":","meth",":","`","get_result","`","will","produce","outputs","in","any","order","."]
code: def __init__(
      self, config, dataset, nr_proc, use_gpu=True, ordered=True
  ):
      """
      Args:
          config: same as in :class:`DatasetPredictorBase`.
          dataset: same as in :class:`DatasetPredictorBase`.
          nr_proc (int): number of processes to use
          use_gpu (bool): use GPU or CPU.
              If GPU, then ``nr_proc`` cannot be more than what's in
              CUDA_VISIBLE_DEVICES.
          ordered (bool): produce outputs in the original order of the
              datapoints. This will be a bit slower. Otherwise, :meth:`get_result` will produce
              outputs in any order.
      """
      if config.return_input:
          logger.warn(
              "Using the option `return_input` in MultiProcessDatasetPredictor might be slow"
          )
      assert nr_proc >= 1, nr_proc
      super(MultiProcessDatasetPredictor, self).__init__(
          config, dataset
      )
  
      self.nr_proc = nr_proc
      self.ordered = ordered
  
      self.inqueue, self.inqueue_proc = dump_dataflow_to_process_queue(
          self.dataset, nr_proc * 2, self.nr_proc
      )  # put (idx, dp) to inqueue
  
      if use_gpu:
          try:
              gpus = os.environ["CUDA_VISIBLE_DEVICES"].split(",")
          except KeyError:
              gpus = list(range(get_num_gpu()))
          assert (
              len(gpus) >= self.nr_proc
          ), "nr_proc={} while only {} gpus available".format(
              self.nr_proc, len(gpus)
          )
      else:
          gpus = ["-1"] * self.nr_proc
      # worker produces (idx, result) to outqueue
      self.outqueue = multiprocessing.Queue()
      self.workers = [
          MultiProcessQueuePredictWorker(
              i, self.inqueue, self.outqueue, self.config
          )
          for i in range(self.nr_proc)
      ]
  
      # start inqueue and workers
      self.inqueue_proc.start()
      for p, gpuid in zip(self.workers, gpus):
          if gpuid == "-1":
              logger.info("Worker {} uses CPU".format(p.idx))
          else:
              logger.info("Worker {} uses GPU {}".format(p.idx, gpuid))
          with change_gpu(gpuid):
              p.start()
  
      if ordered:
          self.result_queue = OrderedResultGatherProc(
              self.outqueue, nr_producer=self.nr_proc
          )
          self.result_queue.start()
          ensure_proc_terminate(self.result_queue)
      else:
          self.result_queue = self.outqueue
      ensure_proc_terminate(self.workers + [self.inqueue_proc])
  
imports: import multiprocessing
  import os
  from abc import ABCMeta, abstractmethod
  import six
  from ..dataflow import DataFlow
  from ..dataflow.remote import dump_dataflow_to_process_queue
  from ..utils import logger
  from ..utils.develop import HIDE_DOC
  from ..utils.concurrency import DIE, OrderedResultGatherProc, ensure_proc_terminate
  from ..utils.gpu import change_gpu, get_num_gpu
  from ..utils.utils import get_tqdm
  from .base import OfflinePredictor
  from .concurrency import MultiProcessQueuePredictWorker
  from .config import PredictConfig
label_desc: Use image node_id 1 to create a new MultiProcessDatasetPredictor object from inherited base classes: DatasetPredictorBase with example: obj = MultiProcessDatasetPredictor(config, dataset, nr_proc, use_gpu, ordered)