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


Python handlers.ProgressBar方法代码示例

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


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

示例1: test_pbar

# 需要导入模块: from ignite.contrib import handlers [as 别名]
# 或者: from ignite.contrib.handlers import ProgressBar [as 别名]
def test_pbar(capsys):

    n_epochs = 2
    loader = [1, 2]
    engine = Engine(update_fn)

    pbar = ProgressBar()
    pbar.attach(engine, ["a"])

    engine.run(loader, max_epochs=n_epochs)

    captured = capsys.readouterr()
    err = captured.err.split("\r")
    err = list(map(lambda x: x.strip(), err))
    err = list(filter(None, err))
    expected = "Epoch [2/2]: [1/2]  50%|█████     , a=1 [00:00<00:00]"
    assert err[-1] == expected 
开发者ID:pytorch,项目名称:ignite,代码行数:19,代码来源:test_tqdm_logger.py

示例2: test_pbar_file

# 需要导入模块: from ignite.contrib import handlers [as 别名]
# 或者: from ignite.contrib.handlers import ProgressBar [as 别名]
def test_pbar_file(tmp_path):
    n_epochs = 2
    loader = [1, 2]
    engine = Engine(update_fn)

    file_path = tmp_path / "temp.txt"
    file = open(str(file_path), "w+")

    pbar = ProgressBar(file=file)
    pbar.attach(engine, ["a"])
    engine.run(loader, max_epochs=n_epochs)

    file.close()  # Force a flush of the buffer. file.flush() does not work.

    file = open(str(file_path), "r")
    lines = file.readlines()

    expected = "Epoch [2/2]: [1/2]  50%|█████     , a=1 [00:00<00:00]\n"
    assert lines[-2] == expected 
开发者ID:pytorch,项目名称:ignite,代码行数:21,代码来源:test_tqdm_logger.py

示例3: test_pbar_batch_indeces

# 需要导入模块: from ignite.contrib import handlers [as 别名]
# 或者: from ignite.contrib.handlers import ProgressBar [as 别名]
def test_pbar_batch_indeces(capsys):
    engine = Engine(lambda e, b: time.sleep(0.1))

    @engine.on(Events.ITERATION_STARTED)
    def print_iter(_):
        print("iteration: ", engine.state.iteration)

    ProgressBar(persist=True).attach(engine)
    engine.run(list(range(4)), max_epochs=1)

    captured = capsys.readouterr()
    err = captured.err.split("\r")
    err = list(map(lambda x: x.strip(), err))
    err = list(filter(None, err))
    printed_batch_indeces = set(map(lambda x: int(x.split("/")[0][-1]), err))
    expected_batch_indeces = list(range(1, 5))
    assert sorted(list(printed_batch_indeces)) == expected_batch_indeces 
开发者ID:pytorch,项目名称:ignite,代码行数:19,代码来源:test_tqdm_logger.py

示例4: test_pbar_no_metric_names

# 需要导入模块: from ignite.contrib import handlers [as 别名]
# 或者: from ignite.contrib.handlers import ProgressBar [as 别名]
def test_pbar_no_metric_names(capsys):

    n_epochs = 2
    loader = [1, 2]
    engine = Engine(update_fn)

    pbar = ProgressBar()
    pbar.attach(engine)

    engine.run(loader, max_epochs=n_epochs)

    captured = capsys.readouterr()
    err = captured.err.split("\r")
    err = list(map(lambda x: x.strip(), err))
    err = list(filter(None, err))
    actual = err[-1]
    expected = "Epoch [2/2]: [1/2]  50%|█████      [00:00<00:00]"
    assert actual == expected 
开发者ID:pytorch,项目名称:ignite,代码行数:20,代码来源:test_tqdm_logger.py

示例5: test_pbar_with_output

# 需要导入模块: from ignite.contrib import handlers [as 别名]
# 或者: from ignite.contrib.handlers import ProgressBar [as 别名]
def test_pbar_with_output(capsys):
    n_epochs = 2
    loader = [1, 2]
    engine = Engine(update_fn)

    pbar = ProgressBar()
    pbar.attach(engine, output_transform=lambda x: {"a": x})

    engine.run(loader, max_epochs=n_epochs)

    captured = capsys.readouterr()
    err = captured.err.split("\r")
    err = list(map(lambda x: x.strip(), err))
    err = list(filter(None, err))
    expected = "Epoch [2/2]: [1/2]  50%|█████     , a=1 [00:00<00:00]"
    assert err[-1] == expected 
开发者ID:pytorch,项目名称:ignite,代码行数:18,代码来源:test_tqdm_logger.py

示例6: test_pbar_with_scalar_output

# 需要导入模块: from ignite.contrib import handlers [as 别名]
# 或者: from ignite.contrib.handlers import ProgressBar [as 别名]
def test_pbar_with_scalar_output(capsys):
    n_epochs = 2
    loader = [1, 2]
    engine = Engine(update_fn)

    pbar = ProgressBar()
    pbar.attach(engine, output_transform=lambda x: x)

    engine.run(loader, max_epochs=n_epochs)

    captured = capsys.readouterr()
    err = captured.err.split("\r")
    err = list(map(lambda x: x.strip(), err))
    err = list(filter(None, err))
    expected = "Epoch [2/2]: [1/2]  50%|█████     , output=1 [00:00<00:00]"
    assert err[-1] == expected 
开发者ID:pytorch,项目名称:ignite,代码行数:18,代码来源:test_tqdm_logger.py

示例7: test_pbar_with_str_output

# 需要导入模块: from ignite.contrib import handlers [as 别名]
# 或者: from ignite.contrib.handlers import ProgressBar [as 别名]
def test_pbar_with_str_output(capsys):
    n_epochs = 2
    loader = [1, 2]
    engine = Engine(update_fn)

    pbar = ProgressBar()
    pbar.attach(engine, output_transform=lambda x: "red")

    engine.run(loader, max_epochs=n_epochs)

    captured = capsys.readouterr()
    err = captured.err.split("\r")
    err = list(map(lambda x: x.strip(), err))
    err = list(filter(None, err))
    expected = "Epoch [2/2]: [1/2]  50%|█████     , output=red [00:00<00:00]"
    assert err[-1] == expected 
开发者ID:pytorch,项目名称:ignite,代码行数:18,代码来源:test_tqdm_logger.py

示例8: test_pbar_output_tensor

# 需要导入模块: from ignite.contrib import handlers [as 别名]
# 或者: from ignite.contrib.handlers import ProgressBar [as 别名]
def test_pbar_output_tensor(capsys):
    def _test(out_tensor, out_msg):
        loader = [1, 2, 3, 4, 5]

        def update_fn(engine, batch):
            return out_tensor

        engine = Engine(update_fn)

        pbar = ProgressBar(desc="Output tensor")
        pbar.attach(engine, output_transform=lambda x: x)
        engine.run(loader, max_epochs=1)

        captured = capsys.readouterr()
        err = captured.err.split("\r")
        err = list(map(lambda x: x.strip(), err))
        err = list(filter(None, err))
        expected = "Output tensor: [4/5]  80%|████████  , {} [00:00<00:00]".format(out_msg)
        assert err[-1] == expected

    _test(out_tensor=torch.tensor([5, 0]), out_msg="output_0=5, output_1=0")
    _test(out_tensor=torch.tensor(123), out_msg="output=123")
    _test(out_tensor=torch.tensor(1.234), out_msg="output=1.23") 
开发者ID:pytorch,项目名称:ignite,代码行数:25,代码来源:test_tqdm_logger.py

示例9: test_pbar_on_epochs

# 需要导入模块: from ignite.contrib import handlers [as 别名]
# 或者: from ignite.contrib.handlers import ProgressBar [as 别名]
def test_pbar_on_epochs(capsys):

    n_epochs = 10
    loader = [1, 2, 3, 4, 5]
    engine = Engine(update_fn)

    pbar = ProgressBar()
    pbar.attach(engine, event_name=Events.EPOCH_STARTED, closing_event_name=Events.COMPLETED)
    engine.run(loader, max_epochs=n_epochs)

    captured = capsys.readouterr()
    err = captured.err.split("\r")
    err = list(map(lambda x: x.strip(), err))
    err = list(filter(None, err))
    actual = err[-1]
    expected = "Epoch: [9/10]  90%|█████████  [00:00<00:00]"
    assert actual == expected 
开发者ID:pytorch,项目名称:ignite,代码行数:19,代码来源:test_tqdm_logger.py

示例10: test_pbar_wrong_events_order

# 需要导入模块: from ignite.contrib import handlers [as 别名]
# 或者: from ignite.contrib.handlers import ProgressBar [as 别名]
def test_pbar_wrong_events_order():

    engine = Engine(update_fn)
    pbar = ProgressBar()

    with pytest.raises(ValueError, match="should be called before closing event"):
        pbar.attach(engine, event_name=Events.COMPLETED, closing_event_name=Events.COMPLETED)

    with pytest.raises(ValueError, match="should be called before closing event"):
        pbar.attach(engine, event_name=Events.COMPLETED, closing_event_name=Events.EPOCH_COMPLETED)

    with pytest.raises(ValueError, match="should be called before closing event"):
        pbar.attach(engine, event_name=Events.COMPLETED, closing_event_name=Events.ITERATION_COMPLETED)

    with pytest.raises(ValueError, match="should be called before closing event"):
        pbar.attach(engine, event_name=Events.EPOCH_COMPLETED, closing_event_name=Events.EPOCH_COMPLETED)

    with pytest.raises(ValueError, match="should be called before closing event"):
        pbar.attach(engine, event_name=Events.ITERATION_COMPLETED, closing_event_name=Events.ITERATION_STARTED)

    with pytest.raises(ValueError, match="should not be a filtered event"):
        pbar.attach(engine, event_name=Events.ITERATION_STARTED, closing_event_name=Events.EPOCH_COMPLETED(every=10)) 
开发者ID:pytorch,项目名称:ignite,代码行数:24,代码来源:test_tqdm_logger.py

示例11: test_pbar_on_callable_events

# 需要导入模块: from ignite.contrib import handlers [as 别名]
# 或者: from ignite.contrib.handlers import ProgressBar [as 别名]
def test_pbar_on_callable_events(capsys):

    n_epochs = 1
    loader = list(range(100))
    engine = Engine(update_fn)

    pbar = ProgressBar()
    pbar.attach(engine, event_name=Events.ITERATION_STARTED(every=10), closing_event_name=Events.EPOCH_COMPLETED)
    engine.run(loader, max_epochs=n_epochs)

    captured = capsys.readouterr()
    err = captured.err.split("\r")
    err = list(map(lambda x: x.strip(), err))
    err = list(filter(None, err))
    actual = err[-1]
    expected = "Epoch: [90/100]  90%|█████████  [00:00<00:00]"
    assert actual == expected 
开发者ID:pytorch,项目名称:ignite,代码行数:19,代码来源:test_tqdm_logger.py

示例12: test_pbar_log_message

# 需要导入模块: from ignite.contrib import handlers [as 别名]
# 或者: from ignite.contrib.handlers import ProgressBar [as 别名]
def test_pbar_log_message(capsys):
    pbar = ProgressBar()

    pbar.log_message("test")

    captured = capsys.readouterr()
    out = captured.out.split("\r")
    out = list(map(lambda x: x.strip(), out))
    out = list(filter(None, out))
    expected = "test"
    assert out[-1] == expected 
开发者ID:pytorch,项目名称:ignite,代码行数:13,代码来源:test_tqdm_logger.py

示例13: test_pbar_log_message_file

# 需要导入模块: from ignite.contrib import handlers [as 别名]
# 或者: from ignite.contrib.handlers import ProgressBar [as 别名]
def test_pbar_log_message_file(tmp_path):
    file_path = tmp_path / "temp.txt"
    file = open(str(file_path), "w+")

    pbar = ProgressBar(file=file)
    pbar.log_message("test")

    file.close()  # Force a flush of the buffer. file.flush() does not work.

    file = open(str(file_path), "r")
    lines = file.readlines()

    expected = "test\n"
    assert lines[0] == expected 
开发者ID:pytorch,项目名称:ignite,代码行数:16,代码来源:test_tqdm_logger.py

示例14: test_pbar_with_metric

# 需要导入模块: from ignite.contrib import handlers [as 别名]
# 或者: from ignite.contrib.handlers import ProgressBar [as 别名]
def test_pbar_with_metric(capsys):

    n_iters = 2
    data = list(range(n_iters))
    loss_values = iter(range(n_iters))

    def step(engine, batch):
        loss_value = next(loss_values)
        return loss_value

    trainer = Engine(step)

    RunningAverage(alpha=0.5, output_transform=lambda x: x).attach(trainer, "batchloss")

    pbar = ProgressBar()
    pbar.attach(trainer, metric_names=["batchloss",])

    trainer.run(data=data, max_epochs=1)

    captured = capsys.readouterr()
    err = captured.err.split("\r")
    err = list(map(lambda x: x.strip(), err))
    err = list(filter(None, err))
    actual = err[-1]
    expected = "Epoch: [1/2]  50%|█████     , batchloss=0.5 [00:00<00:00]"
    assert actual == expected 
开发者ID:pytorch,项目名称:ignite,代码行数:28,代码来源:test_tqdm_logger.py

示例15: test_pbar_with_all_metric

# 需要导入模块: from ignite.contrib import handlers [as 别名]
# 或者: from ignite.contrib.handlers import ProgressBar [as 别名]
def test_pbar_with_all_metric(capsys):

    n_iters = 2
    data = list(range(n_iters))
    loss_values = iter(range(n_iters))
    another_loss_values = iter(range(1, n_iters + 1))

    def step(engine, batch):
        loss_value = next(loss_values)
        another_loss_value = next(another_loss_values)
        return loss_value, another_loss_value

    trainer = Engine(step)

    RunningAverage(alpha=0.5, output_transform=lambda x: x[0]).attach(trainer, "batchloss")
    RunningAverage(alpha=0.5, output_transform=lambda x: x[1]).attach(trainer, "another batchloss")

    pbar = ProgressBar()
    pbar.attach(trainer, metric_names="all")

    trainer.run(data=data, max_epochs=1)

    captured = capsys.readouterr()
    err = captured.err.split("\r")
    err = list(map(lambda x: x.strip(), err))
    err = list(filter(None, err))
    actual = err[-1]
    expected = "Epoch: [1/2]  50%|█████     , another batchloss=1.5, batchloss=0.5 [00:00<00:00]"
    assert actual == expected 
开发者ID:pytorch,项目名称:ignite,代码行数:31,代码来源:test_tqdm_logger.py


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