當前位置: 首頁>>代碼示例>>Python>>正文


Python cv2.setNumThreads方法代碼示例

本文整理匯總了Python中cv2.setNumThreads方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.setNumThreads方法的具體用法?Python cv2.setNumThreads怎麽用?Python cv2.setNumThreads使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cv2的用法示例。


在下文中一共展示了cv2.setNumThreads方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setNumThreads [as 別名]
def __init__(
        self,
        root,
        split,
        ignore_label,
        mean_bgr,
        augment=True,
        base_size=None,
        crop_size=321,
        scales=(1.0),
        flip=True,
    ):
        self.root = root
        self.split = split
        self.ignore_label = ignore_label
        self.mean_bgr = np.array(mean_bgr)
        self.augment = augment
        self.base_size = base_size
        self.crop_size = crop_size
        self.scales = scales
        self.flip = flip
        self.files = []
        self._set_files()

        cv2.setNumThreads(0) 
開發者ID:kazuto1011,項目名稱:deeplab-pytorch,代碼行數:27,代碼來源:base.py

示例2: __init__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setNumThreads [as 別名]
def __init__(self, root, split, mean, std, base_size=None, augment=True, val=False,
                crop_size=321, scale=True, flip=True, rotate=False, blur=False, return_id=False):
        self.root = root
        self.split = split
        self.mean = mean
        self.std = std
        self.augment = augment
        self.crop_size = crop_size
        if self.augment:
            self.base_size = base_size
            self.scale = scale
            self.flip = flip
            self.rotate = rotate
            self.blur = blur
        self.val = val
        self.files = []
        self._set_files()
        self.to_tensor = transforms.ToTensor()
        self.normalize = transforms.Normalize(mean, std)
        self.return_id = return_id

        cv2.setNumThreads(0) 
開發者ID:yassouali,項目名稱:pytorch_segmentation,代碼行數:24,代碼來源:base_dataset.py

示例3: run_training

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setNumThreads [as 別名]
def run_training(train_module, train_name, cudnn_benchmark=True):
    """Run a train scripts in train_settings.
    args:
        train_module: Name of module in the "train_settings/" folder.
        train_name: Name of the train settings file.
        cudnn_benchmark: Use cudnn benchmark or not (default is True).
    """

    # This is needed to avoid strange crashes related to opencv
    cv.setNumThreads(0)

    torch.backends.cudnn.benchmark = cudnn_benchmark

    print('Training:  {}  {}'.format(train_module, train_name))

    settings = ws_settings.Settings()
    settings.module_name = train_module
    settings.script_name = train_name
    settings.project_path = 'ltr/{}/{}'.format(train_module, train_name)

    expr_module = importlib.import_module('ltr.train_settings.{}.{}'.format(train_module, train_name))
    expr_func = getattr(expr_module, 'run')

    expr_func(settings) 
開發者ID:visionml,項目名稱:pytracking,代碼行數:26,代碼來源:run_training.py

示例4: configure_hacks

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setNumThreads [as 別名]
def configure_hacks(config={}, **kw):
    """
    Configures hacks to fix global settings in external modules

    Args:
        config (dict): exected to contain they key "workers" with an
           integer value equal to the number of dataloader processes.
        **kw: can also be used to specify config items

    Modules we currently hack:
        * cv2 - fix thread count
    """
    config = _update_defaults(config, kw)
    if config['workers'] > 0:
        import cv2
        cv2.setNumThreads(0) 
開發者ID:Erotemic,項目名稱:netharn,代碼行數:18,代碼來源:api.py

示例5: _check_thread_safety

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setNumThreads [as 別名]
def _check_thread_safety(harn):
        """
        References:
            https://github.com/pytorch/pytorch/issues/1355
        """
        import cv2
        n_workers = max(loader.num_workers for loader in harn.loaders.values()
                        if loader is not None)
        if n_workers > 1:
            n_threads = cv2.getNumThreads()
            if n_threads > 1:
                msg = ('OpenCV threadcount of {} is non-zero and a DataLoader '
                       'is using {} workers. This may cause deadlocks '
                       'To be safe use cv2.setNumThreads(0)').format(
                           n_threads, n_workers)
                warnings.warn(msg, RuntimeWarning)
                harn.warn(msg) 
開發者ID:Erotemic,項目名稱:netharn,代碼行數:19,代碼來源:fit_harn.py

示例6: __init__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setNumThreads [as 別名]
def __init__(
        self,
        root,
        split="train",
        base_size=513,
        crop_size=321,
        mean=(104.008, 116.669, 122.675),
        scale=(0.5, 1.5),
        warp=True,
        flip=True,
        preload=False,
        visibility_mask=None,
    ):
        self.root = root
        self.split = split
        self.base_size = base_size
        self.crop_size = crop_size
        self.mean = np.array(mean)
        self.scale = scale
        self.warp = warp
        self.flip = flip
        self.preload = preload

        self.files = np.array([])
        self.images = []
        self.labels = []
        self.ignore_label = None
        self.visibility_mask = visibility_mask

        self._set_files()

        if self.preload:
            self._preload_data()

        cv2.setNumThreads(0) 
開發者ID:subhc,項目名稱:SPNet,代碼行數:37,代碼來源:cocostuff.py

示例7: __init__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setNumThreads [as 別名]
def __init__(
        self,
        root,
        split="train",
        base_size=513,
        crop_size=321,
        mean=(104.008, 116.669, 122.675),
        scale=(0.5, 0.75, 1.0, 1.25, 1.5),
        warp=True,
        flip=True,
        preload=False,
    ):
        self.root = root
        self.split = split
        self.base_size = base_size
        self.crop_size = crop_size
        self.mean = np.array(mean)
        self.scale = scale
        self.warp = warp
        self.flip = flip
        self.preload = preload

        self.files = []
        self.images = []
        self.labels = []
        self.ignore_label = None

        self._set_files()

        if self.preload:
            self._preload_data()

        cv2.setNumThreads(0) 
開發者ID:dmechea,項目名稱:PanopticSegmentation,代碼行數:35,代碼來源:cocostuff.py

示例8: get_image

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setNumThreads [as 別名]
def get_image(self, idx):
        assert False, 'DO NOT USE cv2 NOW, AVOID DEADLOCK'
        import cv2
        # cv2.setNumThreads(0)  # for solving deadlock when switching epoch
        img_file = os.path.join(self.image_dir, '%06d.png' % idx)
        assert os.path.exists(img_file)
        return cv2.imread(img_file)  # (H, W, 3) BGR mode 
開發者ID:sshaoshuai,項目名稱:PointRCNN,代碼行數:9,代碼來源:kitti_dataset.py

示例9: _Pool_initialize_worker

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setNumThreads [as 別名]
def _Pool_initialize_worker(augseq, seed_start):
    # pylint: disable=invalid-name, protected-access

    # Not using this seems to have caused infinite hanging in the case
    # of gaussian blur on at least MacOSX.
    # It is also in most cases probably not sensible to use multiple
    # threads while already running augmentation in multiple processes.
    cv2.setNumThreads(0)

    if seed_start is None:
        # pylint falsely thinks in older versions that
        # multiprocessing.current_process() was not callable, see
        # https://github.com/PyCQA/pylint/issues/1699
        # pylint: disable=not-callable
        process_name = _get_context().current_process().name
        # pylint: enable=not-callable

        # time_ns() exists only in 3.7+
        if sys.version_info[0] == 3 and sys.version_info[1] >= 7:
            seed_offset = time.time_ns()
        else:
            seed_offset = int(time.time() * 10**6) % 10**6
        seed = hash(process_name) + seed_offset
        _reseed_global_local(seed, augseq)
    Pool._WORKER_SEED_START = seed_start
    Pool._WORKER_AUGSEQ = augseq
    # not sure if really necessary, but shouldn't hurt either
    Pool._WORKER_AUGSEQ.localize_random_state_()


# This could be a classmethod or staticmethod of Pool in 3.x, but in 2.7 that
# leads to pickle errors. 
開發者ID:aleju,項目名稱:imgaug,代碼行數:34,代碼來源:multicore.py

示例10: __getitem__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setNumThreads [as 別名]
def __getitem__(self, idx):

        cv2.setNumThreads(0) # some hack to make sure pyTorch doesn't deadlock. Found at https://github.com/pytorch/pytorch/issues/1355. Seems to work for me

        # Get label filename
        label_filename = self.starts[idx]

        label = cv2.imread(str(os.path.join(self.base_dir, 'Labels', label_filename))) # Shape: [H x W x 3]
        label = label[..., 0] == 255 # Turn it into a {0,1} binary mask with shape: [H x W]
        label = label.astype(np.uint8)

        # find corresponding image file
        img_file = label_filename.split('_')[0] + '.jpg'
        img = cv2.imread(str(os.path.join(self.base_dir, 'Images', img_file)))
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

        # These might not be the same size. resize them to the smaller one
        if label.shape[0] < img.shape[0]:
            new_size = label.shape[::-1] # (W, H)
        else:
            new_size = img.shape[:2][::-1]
        label = cv2.resize(label, new_size)
        img = cv2.resize(img, new_size)

        img_crop, morphed_label_crop, label_crop = self.transform(img, label)

        return {
            'rgb' : img_crop,
            'initial_masks' : morphed_label_crop,
            'labels' : label_crop
        } 
開發者ID:chrisdxie,項目名稱:uois,代碼行數:33,代碼來源:data_loader.py

示例11: __init__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setNumThreads [as 別名]
def __init__(self, width, height):
		"""
			Args:
				width and height are only used to determine the 
				output aspect ratio, not the actual output size
		"""
		self.ops = []
		cv2.setNumThreads(0)
		self.width = float(width)
		self.height = float(height) 
開發者ID:princeton-vl,項目名稱:YouTube3D,代碼行數:12,代碼來源:ReDWebDataset.py

示例12: __init__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setNumThreads [as 別名]
def __init__(self, config=None, split=None, purpose=None, preload=False):
    super(_Coco, self).__init__()

    self.split = split
    self.purpose = purpose

    self.root = config.dataset_root

    self.single_mode = hasattr(config, "single_mode") and config.single_mode

    # always used (labels fields used to make relevancy mask for train)
    self.gt_k = config.gt_k
    self.pre_scale_all = config.pre_scale_all
    self.pre_scale_factor = config.pre_scale_factor
    self.input_sz = config.input_sz

    self.include_rgb = config.include_rgb
    self.no_sobel = config.no_sobel

    assert ((not hasattr(config, "mask_input")) or (not config.mask_input))
    self.mask_input = False

    # only used if purpose is train
    if purpose == "train":
      self.use_random_scale = config.use_random_scale
      if self.use_random_scale:
        self.scale_max = config.scale_max
        self.scale_min = config.scale_min

      self.jitter_tf = tvt.ColorJitter(brightness=config.jitter_brightness,
                                       contrast=config.jitter_contrast,
                                       saturation=config.jitter_saturation,
                                       hue=config.jitter_hue)

      self.flip_p = config.flip_p  # 0.5

      self.use_random_affine = config.use_random_affine
      if self.use_random_affine:
        self.aff_min_rot = config.aff_min_rot
        self.aff_max_rot = config.aff_max_rot
        self.aff_min_shear = config.aff_min_shear
        self.aff_max_shear = config.aff_max_shear
        self.aff_min_scale = config.aff_min_scale
        self.aff_max_scale = config.aff_max_scale

    assert (not preload)

    self.files = []
    self.images = []
    self.labels = []

    if not osp.exists(config.fine_to_coarse_dict):
      generate_fine_to_coarse(config.fine_to_coarse_dict)

    with open(config.fine_to_coarse_dict, "rb") as dict_f:
      d = pickle.load(dict_f)
      self._fine_to_coarse_dict = d["fine_index_to_coarse_index"]

    cv2.setNumThreads(0) 
開發者ID:xu-ji,項目名稱:IIC,代碼行數:61,代碼來源:cocostuff.py

示例13: __init__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setNumThreads [as 別名]
def __init__(self, config=None, split=None, purpose=None, preload=False):
    super(_Potsdam, self).__init__()

    self.split = split
    self.purpose = purpose

    self.root = config.dataset_root

    self.single_mode = hasattr(config, "single_mode") and config.single_mode

    assert (os.path.exists(os.path.join(self.root, "debugged.out")))

    # always used (labels fields used to make relevancy mask for train)
    self.gt_k = config.gt_k
    self.pre_scale_all = config.pre_scale_all
    self.pre_scale_factor = config.pre_scale_factor
    self.input_sz = config.input_sz

    self.include_rgb = config.include_rgb
    self.no_sobel = config.no_sobel

    # only used if purpose is train
    if purpose == "train":
      self.use_random_scale = config.use_random_scale
      if self.use_random_scale:
        self.scale_max = config.scale_max
        self.scale_min = config.scale_min

      self.jitter_tf = tvt.ColorJitter(brightness=config.jitter_brightness,
                                       contrast=config.jitter_contrast,
                                       saturation=config.jitter_saturation,
                                       hue=config.jitter_hue)

      self.flip_p = config.flip_p  # 0.5

      self.use_random_affine = config.use_random_affine
      if self.use_random_affine:
        self.aff_min_rot = config.aff_min_rot
        self.aff_max_rot = config.aff_max_rot
        self.aff_min_shear = config.aff_min_shear
        self.aff_max_shear = config.aff_max_shear
        self.aff_min_scale = config.aff_min_scale
        self.aff_max_scale = config.aff_max_scale

    self.preload = preload

    self.files = []
    self.images = []
    self.labels = []

    self._set_files()

    if self.preload:
      self._preload_data()

    cv2.setNumThreads(0) 
開發者ID:xu-ji,項目名稱:IIC,代碼行數:58,代碼來源:potsdam.py


注:本文中的cv2.setNumThreads方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。