当前位置: 首页>>代码示例>>Python>>正文


Python tqdm.tqdm方法代码示例

本文整理汇总了Python中tqdm.tqdm.tqdm方法的典型用法代码示例。如果您正苦于以下问题:Python tqdm.tqdm方法的具体用法?Python tqdm.tqdm怎么用?Python tqdm.tqdm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tqdm.tqdm的用法示例。


在下文中一共展示了tqdm.tqdm方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_tqdm_kwargs

# 需要导入模块: from tqdm import tqdm [as 别名]
# 或者: from tqdm.tqdm import tqdm [as 别名]
def get_tqdm_kwargs(**kwargs):
    """
    Return default arguments to be used with tqdm.

    Args:
        kwargs: extra arguments to be used.
    Returns:
        dict:
    """
    default = dict(
        smoothing=0.5,
        dynamic_ncols=True,
        ascii=True,
        bar_format='{l_bar}{bar}|{n_fmt}/{total_fmt}[{elapsed}<{remaining},{rate_noinv_fmt}]'
    )

    try:
        # Use this env var to override the refresh interval setting
        interval = float(os.environ['TENSORPACK_PROGRESS_REFRESH'])
    except KeyError:
        interval = _pick_tqdm_interval(kwargs.get('file', sys.stderr))

    default['mininterval'] = interval
    default.update(kwargs)
    return default 
开发者ID:tensorpack,项目名称:dataflow,代码行数:27,代码来源:utils.py

示例2: get_tqdm

# 需要导入模块: from tqdm import tqdm [as 别名]
# 或者: from tqdm.tqdm import tqdm [as 别名]
def get_tqdm(*args, **kwargs):
    """ Similar to :func:`tqdm.tqdm()`,
    but use tensorpack's default options to have consistent style. """
    return tqdm(*args, **get_tqdm_kwargs(**kwargs)) 
开发者ID:tensorpack,项目名称:dataflow,代码行数:6,代码来源:utils.py

示例3: __call__

# 需要导入模块: from tqdm import tqdm [as 别名]
# 或者: from tqdm.tqdm import tqdm [as 别名]
def __call__(self, blockno, readsize, totalsize):
        if self.t is None:
            self.t = tqdm.tqdm(total=totalsize)
        self.t.update(readsize) 
开发者ID:dmlc,项目名称:dgl,代码行数:6,代码来源:download.py

示例4: _download_and_extract

# 需要导入模块: from tqdm import tqdm [as 别名]
# 或者: from tqdm.tqdm import tqdm [as 别名]
def _download_and_extract(self, path, filename):
        import shutil, zipfile, zlib
        from tqdm import tqdm
        import urllib.request

        fn = os.path.join(path, filename)
        with PBar() as pb:
            urllib.request.urlretrieve(self.url, fn, pb)
        print('Download finished. Unzipping the file...')

        with zipfile.ZipFile(fn) as zf:
            zf.extractall(path)
        print('Unzip finished.') 
开发者ID:dmlc,项目名称:dgl,代码行数:15,代码来源:download.py

示例5: _reporthook

# 需要导入模块: from tqdm import tqdm [as 别名]
# 或者: from tqdm.tqdm import tqdm [as 别名]
def _reporthook(t):
    """ ``reporthook`` to use with ``urllib.request`` that prints the process of the download.

    Uses ``tqdm`` for progress bar.

    **Reference:**
    https://github.com/tqdm/tqdm

    Args:
        t (tqdm.tqdm) Progress bar.

    Example:
        >>> with tqdm(unit='B', unit_scale=True, miniters=1, desc=filename) as t:  # doctest: +SKIP
        ...   urllib.request.urlretrieve(file_url, filename=full_path, reporthook=reporthook(t))
    """
    last_b = [0]

    def inner(b=1, bsize=1, tsize=None):
        """
        Args:
            b (int, optional): Number of blocks just transferred [default: 1].
            bsize (int, optional): Size of each block (in tqdm units) [default: 1].
            tsize (int, optional): Total size (in tqdm units). If [default: None] remains unchanged.
        """
        if tsize is not None:
            t.total = tsize
        t.update((b - last_b[0]) * bsize)
        last_b[0] = b

    return inner 
开发者ID:PetrochukM,项目名称:PyTorch-NLP,代码行数:32,代码来源:download.py

示例6: eval

# 需要导入模块: from tqdm import tqdm [as 别名]
# 或者: from tqdm.tqdm import tqdm [as 别名]
def eval(self, dataloader, yolo, test_num=10000):
        labels = []
        sample_metrics = []  # List of tuples (TP, confs, pred)
        total_losses = list()
        Tensor = torch.cuda.FloatTensor if torch.cuda.is_available() else torch.FloatTensor
        for batch_i, (_, imgs, targets) in enumerate(tqdm.tqdm(dataloader, desc="Detecting objects")):
            # Extract labels
            labels += targets[:, 1].tolist()
            # Rescale target
            targets = Variable(targets.to(self.device), requires_grad=False)

            imgs = Variable(imgs.type(Tensor), requires_grad=False)
            with torch.no_grad():
                loss, outputs = yolo(imgs, targets)
                outputs = non_max_suppression(outputs, conf_thres=0.5, nms_thres=0.5)
                total_losses.append(loss.item())
            targets = targets.to("cpu")
            targets[:, 2:] = xywh2xyxy(targets[:, 2:])
            targets[:, 2:] *= int(self.model_config['img_size'])
            sample_metrics += get_batch_statistics(outputs, targets, iou_threshold=0.5)
        if len(sample_metrics) > 0:
            true_positives, pred_scores, pred_labels = [np.concatenate(x, 0) for x in list(zip(*sample_metrics))]
            precision, recall, AP, f1, ap_class = ap_per_class(true_positives, pred_scores, pred_labels, labels)
        else:
            return 0.0, 0.0, 0.0
        total_loss = sum(total_losses) / len(total_losses)
        return total_loss, AP.mean(), recall.mean() 
开发者ID:FederatedAI,项目名称:FATE,代码行数:29,代码来源:model_wrapper.py

示例7: train_one_epoch

# 需要导入模块: from tqdm import tqdm [as 别名]
# 或者: from tqdm.tqdm import tqdm [as 别名]
def train_one_epoch(self):
        """
        Return:
            total_loss: the total loss during training
            accuracy: the mAP
        """
        pred_bboxes, pred_labels, pred_scores = list(), list(), list()
        gt_bboxes, gt_labels, gt_difficults = list(), list(), list()
        self.trainer.reset_meters()
        for ii, (img, sizes, bbox_, label_, scale, gt_difficults_) in \
                tqdm.tqdm(enumerate(self.dataloader)):
            scale = at.scalar(scale)
            img, bbox, label = img.cuda().float(), bbox_.cuda(), label_.cuda()
            self.trainer.train_step(img, bbox, label, scale)
            if (ii + 1) % self.opt.plot_every == 0:
                sizes = [sizes[0][0].item(), sizes[1][0].item()]
                pred_bboxes_, pred_labels_, pred_scores_ = \
                    self.faster_rcnn.predict(img, [sizes])
                pred_bboxes += pred_bboxes_
                pred_labels += pred_labels_
                pred_scores += pred_scores_
                gt_bboxes += list(bbox_.numpy())
                gt_labels += list(label_.numpy())
                gt_difficults += list(gt_difficults_.numpy())

        return self.trainer.get_meter_data()['total_loss'] 
开发者ID:FederatedAI,项目名称:FATE,代码行数:28,代码来源:model_wrapper.py

示例8: _pbar

# 需要导入模块: from tqdm import tqdm [as 别名]
# 或者: from tqdm.tqdm import tqdm [as 别名]
def _pbar(iterable, desc, leave=True, position=None, verbose='progressbar'):

    if verbose is not False and \
            verbose not in ['progressbar', 'tqdm', 'tqdm_notebook']:
        raise ValueError('verbose must be one of {progressbar,'
                         'tqdm, tqdm_notebook, False}. Got %s' % verbose)

    try:
        from tqdm import tqdm
        verbose = 'tqdm'
    except ImportError:
        pass

    if verbose == 'progressbar':
        from mne.utils import ProgressBar
        pbar = ProgressBar(iterable, mesg=desc)
    # XXX: remove the tqdm option after a few releases of MNE since it
    # natively supported by the MNE progressbar
    elif verbose == 'tqdm':
        pbar = tqdm(iterable, desc=desc, leave=leave, position=position,
                    dynamic_ncols=True)
    elif verbose == 'tqdm_notebook':
        from tqdm import tqdm_notebook
        pbar = tqdm_notebook(iterable, desc=desc, leave=leave,
                             position=position, dynamic_ncols=True)
    elif verbose is False:
        pbar = iterable
    return pbar 
开发者ID:autoreject,项目名称:autoreject,代码行数:30,代码来源:utils.py

示例9: clean_by_interp

# 需要导入模块: from tqdm import tqdm [as 别名]
# 或者: from tqdm.tqdm import tqdm [as 别名]
def clean_by_interp(inst, picks=None, verbose='progressbar'):
    """Clean epochs/evoked by LOOCV.

    Parameters
    ----------
    inst : instance of mne.Evoked or mne.Epochs
        The evoked or epochs object.
    picks : ndarray, shape(n_channels,) | None
        The channels to be considered for autoreject. If None, defaults
        to data channels {'meg', 'eeg'}.
    verbose : 'tqdm', 'tqdm_notebook', 'progressbar' or False
        The verbosity of progress messages.
        If `'progressbar'`, use `mne.utils.ProgressBar`.
        If `'tqdm'`, use `tqdm.tqdm`.
        If `'tqdm_notebook'`, use `tqdm.tqdm_notebook`.
        If False, suppress all output messages.

    Returns
    -------
    inst_clean : instance of mne.Evoked or mne.Epochs
        Instance after interpolation of bad channels.
    """
    return _clean_by_interp(inst, picks=picks, verbose=verbose) 
开发者ID:autoreject,项目名称:autoreject,代码行数:25,代码来源:utils.py

示例10: preprocess_images

# 需要导入模块: from tqdm import tqdm [as 别名]
# 或者: from tqdm.tqdm import tqdm [as 别名]
def preprocess_images(images, use_multiprocessing):
    """Resizes and shifts the dynamic range of image to 0-1
    Args:
        images: np.array, shape: (N, H, W, 3), dtype: float32 between 0-1 or np.uint8
        use_multiprocessing: If multiprocessing should be used to pre-process the images
    Return:
        final_images: torch.tensor, shape: (N, 3, 299, 299), dtype: torch.float32 between 0-1
    """
    if use_multiprocessing:
        with multiprocessing.Pool(multiprocessing.cpu_count()) as pool:
            jobs = []
            for im in tqdm.tqdm(images, desc="Starting FID jobs"):
                job = pool.apply_async(preprocess_image, (im,))
                jobs.append(job)
            final_images = torch.zeros(images.shape[0], 3, 299, 299)
            for idx, job in enumerate(tqdm(jobs, desc="finishing jobs")):
                im = job.get()
                final_images[idx] = im#job.get()
    else:
        final_images = torch.zeros((len(images), 3, 299, 299), dtype=torch.float32)
        for idx in range(len(images)):
            im = preprocess_image(images[idx])
            final_images[idx] = im
    assert final_images.shape == (images.shape[0], 3, 299, 299)
    assert final_images.max() <= 1.0
    assert final_images.min() >= 0.0
    assert final_images.dtype == torch.float32
    return final_images 
开发者ID:hukkelas,项目名称:DeepPrivacy,代码行数:30,代码来源:fid.py

示例11: download_file_maybe_extract

# 需要导入模块: from tqdm import tqdm [as 别名]
# 或者: from tqdm.tqdm import tqdm [as 别名]
def download_file_maybe_extract(url, directory, filename=None, extension=None, check_files=[]):
    """ Download the file at ``url`` to ``directory``. Extract to ``directory`` if tar or zip.

    Args:
        url (str or Path): Url of file.
        directory (str): Directory to download to.
        filename (str, optional): Name of the file to download; Otherwise, a filename is extracted
            from the url.
        extension (str, optional): Extension of the file; Otherwise, attempts to extract extension
            from the filename.
        check_files (list of str or Path): Check if these files exist, ensuring the download
            succeeded. If these files exist before the download, the download is skipped.

    Returns:
        (str): Filename of download file.

    Raises:
        ValueError: Error if one of the ``check_files`` are not found following the download.
    """
    if filename is None:
        filename = _get_filename_from_url(url)

    directory = str(directory)
    filepath = os.path.join(directory, filename)
    check_files = [os.path.join(directory, str(f)) for f in check_files]

    if len(check_files) > 0 and _check_download(*check_files):
        return filepath

    if not os.path.isdir(directory):
        os.makedirs(directory)

    logger.info('Downloading {}'.format(filename))

    # Download
    if 'drive.google.com' in url:
        _download_file_from_drive(filepath, url)
    else:
        with tqdm(unit='B', unit_scale=True, miniters=1, desc=filename) as t:
            urllib.request.urlretrieve(url, filename=filepath, reporthook=_reporthook(t))

    _maybe_extract(compressed_filename=filepath, directory=directory, extension=extension)

    if not _check_download(*check_files):
        raise ValueError('[DOWNLOAD FAILED] `*check_files` not found')

    return filepath 
开发者ID:PetrochukM,项目名称:PyTorch-NLP,代码行数:49,代码来源:download.py


注:本文中的tqdm.tqdm.tqdm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。