mmcv/utils/progressbar.py
def track_progress(func, tasks, bar_width=50, **kwargs):
    """Track the progress of tasks execution with a progress bar.

    Tasks are done with a simple for-loop.

    Args:
        func (callable): The function to be applied to each task.
        tasks (list or tuple[Iterable, int]): A list of tasks or
            (tasks, total num).
        bar_width (int): Width of progress bar.

    Returns:
        list: The task results.
    """
    if isinstance(tasks, tuple):
        assert len(tasks) == 2
        assert isinstance(tasks[0], collections_abc.Iterable)
        assert isinstance(tasks[1], int)
        task_num = tasks[1]
        tasks = tasks[0]
    elif isinstance(tasks, collections_abc.Iterable):
        task_num = len(tasks)
    else:
        raise TypeError(
            '"tasks" must be an iterable object or a (iterator, int) tuple')
    prog_bar = ProgressBar(task_num, bar_width)
    results = []
    for task in tasks:
        results.append(func(task, **kwargs))
        prog_bar.update()
    sys.stdout.write('\n')
    return results
def track_progress(func, tasks, bar_width=50, **kwargs):
    if isinstance(tasks, tuple):
        assert len(tasks) == 2
        assert isinstance(tasks[0], collections_abc.Iterable)
        assert isinstance(tasks[1], int)
        task_num = tasks[1]
        tasks = tasks[0]
    elif isinstance(tasks, collections_abc.Iterable):
        task_num = len(tasks)
    else:
        raise TypeError(
            '"tasks" must be an iterable object or a (iterator, int) tuple')
    prog_bar = ProgressBar(task_num, bar_width)
    results = []
    for task in tasks:
        results.append(func(task, **kwargs))
        prog_bar.update()
    sys.stdout.write('\n')
    return results
def track_progress ( func , tasks , bar_width = 50 , * * kwargs ) : if isinstance ( tasks , tuple ) : assert len ( tasks ) == 2 assert isinstance ( tasks [ 0 ] , collections_abc . Iterable ) assert isinstance ( tasks [ 1 ] , int ) task_num = tasks [ 1 ] tasks = tasks [ 0 ] elif isinstance ( tasks , collections_abc . Iterable ) : task_num = len ( tasks ) else : raise TypeError ( '"tasks" must be an iterable object or a (iterator, int) tuple' ) prog_bar = ProgressBar ( task_num , bar_width ) results = [ ] for task in tasks : results . append ( func ( task , * * kwargs ) ) prog_bar . update ( ) sys . stdout . write ( '\n' ) return results
Track the progress of tasks execution with a progress bar.

    Tasks are done with a simple for-loop.

    Args:
        func (callable): The function to be applied to each task.
        tasks (list or tuple[Iterable, int]): A list of tasks or
            (tasks, total num).
        bar_width (int): Width of progress bar.

    Returns:
        list: The task results.
Track the progress of tasks execution with a progress bar .