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


Python Events.STARTED属性代码示例

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


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

示例1: attach

# 需要导入模块: from ignite.engine import Events [as 别名]
# 或者: from ignite.engine.Events import STARTED [as 别名]
def attach(self, trainer, train_loader):

        from torch.utils.data import DataLoader

        @trainer.on(Events.STARTED)
        def run_benchmark(_):
            if idist.get_rank() == 0:
                print("-" * 50)
                print(" - Dataflow benchmark")

            self.benchmark_dataflow.run(train_loader)
            t = self.timer.value()

            if idist.get_rank() == 0:
                print(" ")
                print(" Total time ({} iterations) : {:.5f} seconds".format(self.num_iters, t))
                print(" time per iteration         : {} seconds".format(t / self.num_iters))

                if isinstance(train_loader, DataLoader):
                    num_images = train_loader.batch_size * self.num_iters
                    print(" number of images / s       : {}".format(num_images / t))

                print("-" * 50) 
开发者ID:pytorch,项目名称:ignite,代码行数:25,代码来源:training.py

示例2: test_continue_training

# 需要导入模块: from ignite.engine import Events [as 别名]
# 或者: from ignite.engine.Events import STARTED [as 别名]
def test_continue_training():
    # Tests issue : https://github.com/pytorch/ignite/issues/993
    max_epochs = 2
    data = range(10)
    engine = Engine(lambda e, b: 1)
    state = engine.run(data, max_epochs=max_epochs)
    assert state.max_epochs == max_epochs
    assert state.iteration == len(data) * max_epochs
    assert state.epoch == max_epochs

    @engine.on(Events.STARTED)
    def assert_continue_training():
        assert engine.state.epoch == max_epochs

    state = engine.run(data, max_epochs=max_epochs * 2)
    assert state.max_epochs == max_epochs * 2
    assert state.iteration == len(data) * max_epochs * 2
    assert state.epoch == max_epochs * 2 
开发者ID:pytorch,项目名称:ignite,代码行数:20,代码来源:test_engine_state_dict.py

示例3: test_state_custom_attrs_init

# 需要导入模块: from ignite.engine import Events [as 别名]
# 或者: from ignite.engine.Events import STARTED [as 别名]
def test_state_custom_attrs_init():
    def _test(with_load_state_dict=False):
        engine = Engine(lambda e, b: None)
        engine.state.alpha = 0.0
        engine.state.beta = 1.0

        if with_load_state_dict:
            engine.load_state_dict({"iteration": 3, "max_epochs": 5, "epoch_length": 5})

        @engine.on(Events.STARTED | Events.EPOCH_STARTED | Events.EPOCH_COMPLETED | Events.COMPLETED)
        def check_custom_attr():
            assert hasattr(engine.state, "alpha") and engine.state.alpha == 0.0
            assert hasattr(engine.state, "beta") and engine.state.beta == 1.0

        engine.run([0, 1, 2, 3, 4], max_epochs=5)

    _test()
    _test(with_load_state_dict=True) 
开发者ID:pytorch,项目名称:ignite,代码行数:20,代码来源:test_engine_state_dict.py

示例4: test_add_event_handler

# 需要导入模块: from ignite.engine import Events [as 别名]
# 或者: from ignite.engine.Events import STARTED [as 别名]
def test_add_event_handler():
    engine = DummyEngine()

    class Counter(object):
        def __init__(self, count=0):
            self.count = count

    started_counter = Counter()

    def handle_iteration_started(engine, counter):
        counter.count += 1

    engine.add_event_handler(Events.STARTED, handle_iteration_started, started_counter)

    completed_counter = Counter()

    def handle_iteration_completed(engine, counter):
        counter.count += 1

    engine.add_event_handler(Events.COMPLETED, handle_iteration_completed, completed_counter)

    engine.run(15)

    assert started_counter.count == 15
    assert completed_counter.count == 15 
开发者ID:pytorch,项目名称:ignite,代码行数:27,代码来源:test_event_handlers.py

示例5: test_add_event_handler_without_engine

# 需要导入模块: from ignite.engine import Events [as 别名]
# 或者: from ignite.engine.Events import STARTED [as 别名]
def test_add_event_handler_without_engine():
    engine = DummyEngine()

    class Counter(object):
        def __init__(self, count=0):
            self.count = count

    started_counter = Counter()

    def handle_iteration_started():
        started_counter.count += 1

    engine.add_event_handler(Events.STARTED, handle_iteration_started)

    completed_counter = Counter()

    def handle_iteration_completed(counter):
        counter.count += 1

    engine.add_event_handler(Events.COMPLETED, handle_iteration_completed, completed_counter)

    engine.run(15)

    assert started_counter.count == 15
    assert completed_counter.count == 15 
开发者ID:pytorch,项目名称:ignite,代码行数:27,代码来源:test_event_handlers.py

示例6: test_has_event_handler

# 需要导入模块: from ignite.engine import Events [as 别名]
# 或者: from ignite.engine.Events import STARTED [as 别名]
def test_has_event_handler():
    engine = DummyEngine()
    handlers = [MagicMock(spec_set=True), MagicMock(spec_set=True)]
    m = MagicMock(spec_set=True)
    for handler in handlers:
        engine.add_event_handler(Events.STARTED, handler)
    engine.add_event_handler(Events.COMPLETED, m)

    for handler in handlers:
        assert engine.has_event_handler(handler, Events.STARTED)
        assert engine.has_event_handler(handler)
        assert not engine.has_event_handler(handler, Events.COMPLETED)
        assert not engine.has_event_handler(handler, Events.EPOCH_STARTED)

    assert not engine.has_event_handler(m, Events.STARTED)
    assert engine.has_event_handler(m, Events.COMPLETED)
    assert engine.has_event_handler(m)
    assert not engine.has_event_handler(m, Events.EPOCH_STARTED) 
开发者ID:pytorch,项目名称:ignite,代码行数:20,代码来源:test_event_handlers.py

示例7: test_args_and_kwargs_are_passed_to_event

# 需要导入模块: from ignite.engine import Events [as 别名]
# 或者: from ignite.engine.Events import STARTED [as 别名]
def test_args_and_kwargs_are_passed_to_event():
    engine = DummyEngine()
    kwargs = {"a": "a", "b": "b"}
    args = (1, 2, 3)
    handlers = []
    for event in [Events.STARTED, Events.COMPLETED]:
        handler = create_autospec(spec=lambda e, x1, x2, x3, a, b: None)
        engine.add_event_handler(event, handler, *args, **kwargs)
        handlers.append(handler)

    engine.run(1)
    called_handlers = [handle for handle in handlers if handle.called]
    assert len(called_handlers) == 2

    for handler in called_handlers:
        handler_args, handler_kwargs = handler.call_args
        assert handler_args[0] == engine
        assert handler_args[1::] == args
        assert handler_kwargs == kwargs 
开发者ID:pytorch,项目名称:ignite,代码行数:21,代码来源:test_event_handlers.py

示例8: test_on_decorator

# 需要导入模块: from ignite.engine import Events [as 别名]
# 或者: from ignite.engine.Events import STARTED [as 别名]
def test_on_decorator():
    engine = DummyEngine()

    class Counter(object):
        def __init__(self, count=0):
            self.count = count

    started_counter = Counter()

    @engine.on(Events.STARTED, started_counter)
    def handle_iteration_started(engine, started_counter):
        started_counter.count += 1

    completed_counter = Counter()

    @engine.on(Events.COMPLETED, completed_counter)
    def handle_iteration_completed(engine, completed_counter):
        completed_counter.count += 1

    engine.run(15)

    assert started_counter.count == 15
    assert completed_counter.count == 15 
开发者ID:pytorch,项目名称:ignite,代码行数:25,代码来源:test_event_handlers.py

示例9: test_event_handler_started

# 需要导入模块: from ignite.engine import Events [as 别名]
# 或者: from ignite.engine.Events import STARTED [as 别名]
def test_event_handler_started():
    true_event_handler_time = 0.1
    true_max_epochs = 2
    true_num_iters = 2

    profiler = BasicTimeProfiler()
    dummy_trainer = Engine(_do_nothing_update_fn)
    profiler.attach(dummy_trainer)

    @dummy_trainer.on(Events.STARTED)
    def delay_start(engine):
        time.sleep(true_event_handler_time)

    dummy_trainer.run(range(true_num_iters), max_epochs=true_max_epochs)
    results = profiler.get_results()
    event_results = results["event_handlers_stats"]["STARTED"]

    assert event_results["total"] == approx(true_event_handler_time, abs=1e-1) 
开发者ID:pytorch,项目名称:ignite,代码行数:20,代码来源:test_time_profilers.py

示例10: attach

# 需要导入模块: from ignite.engine import Events [as 别名]
# 或者: from ignite.engine.Events import STARTED [as 别名]
def attach(self, engine, start=Events.STARTED, pause=Events.COMPLETED, resume=None, step=None):
        """ Register callbacks to control the timer.

        Args:
            engine (ignite.engine.Engine):
                Engine that this timer will be attached to
            start (ignite.engine.Events):
                Event which should start (reset) the timer
            pause (ignite.engine.Events):
                Event which should pause the timer
            resume (ignite.engine.Events, optional):
                Event which should resume the timer
            step (ignite.engine.Events, optional):
                Event which should call the `step` method of the counter

        Returns:
            self (Timer)

        """

        engine.add_event_handler(start, self.reset)
        engine.add_event_handler(pause, self.pause)

        if resume is not None:
            engine.add_event_handler(resume, self.resume)

        if step is not None:
            engine.add_event_handler(step, self.step)

        return self 
开发者ID:hrhodin,项目名称:UnsupervisedGeometryAwareRepresentationLearning,代码行数:32,代码来源:timing.py

示例11: test_not_chainerui_logger

# 需要导入模块: from ignite.engine import Events [as 别名]
# 或者: from ignite.engine.Events import STARTED [as 别名]
def test_not_chainerui_logger():
    handler = OutputHandler('test', metric_names='all')

    engine = MagicMock()

    from ignite.contrib.handlers.base_logger import BaseLogger
    logger = BaseLogger()

    with pytest.raises(RuntimeError) as e:
        handler(engine, logger, Events.STARTED)
    assert 'only with ChainerUILogger' in str(e.value) 
开发者ID:chainer,项目名称:chainerui,代码行数:13,代码来源:test_handler.py

示例12: test_not_unique_handler

# 需要导入模块: from ignite.engine import Events [as 别名]
# 或者: from ignite.engine.Events import STARTED [as 别名]
def test_not_unique_handler(client):
    handler1 = OutputHandler('same_name', metric_names='all')
    handler2 = OutputHandler('same_name', metric_names='all')

    engine = MagicMock()

    logger = ChainerUILogger()
    logger.attach(engine, handler1, Events.STARTED)
    with pytest.raises(RuntimeError) as e:
        logger.attach(engine, handler2, Events.STARTED)
    assert 'unique tag name' in str(e.value) 
开发者ID:chainer,项目名称:chainerui,代码行数:13,代码来源:test_handler.py

示例13: attach

# 需要导入模块: from ignite.engine import Events [as 别名]
# 或者: from ignite.engine.Events import STARTED [as 别名]
def attach(self, engine, start=Events.STARTED, pause=Events.COMPLETED, resume=None, step=None):
        """ Register callbacks to control the timer.

        Args:
            engine (Engine):
                Engine that this timer will be attached to.
            start (Events):
                Event which should start (reset) the timer.
            pause (Events):
                Event which should pause the timer.
            resume (Events, optional):
                Event which should resume the timer.
            step (Events, optional):
                Event which should call the `step` method of the counter.

        Returns:
            self (Timer)

        """

        engine.add_event_handler(start, self.reset)
        engine.add_event_handler(pause, self.pause)

        if resume is not None:
            engine.add_event_handler(resume, self.resume)

        if step is not None:
            engine.add_event_handler(step, self.step)

        return self 
开发者ID:leokarlin,项目名称:LaSO,代码行数:32,代码来源:timing.py

示例14: attach

# 需要导入模块: from ignite.engine import Events [as 别名]
# 或者: from ignite.engine.Events import STARTED [as 别名]
def attach(
        self,
        engine: Engine,
        start: Events = Events.STARTED,
        pause: Events = Events.COMPLETED,
        resume: Optional[Events] = None,
        step: Optional[Events] = None,
    ):
        """ Register callbacks to control the timer.

        Args:
            engine (Engine):
                Engine that this timer will be attached to.
            start (Events):
                Event which should start (reset) the timer.
            pause (Events):
                Event which should pause the timer.
            resume (Events, optional):
                Event which should resume the timer.
            step (Events, optional):
                Event which should call the `step` method of the counter.

        Returns:
            self (Timer)

        """

        engine.add_event_handler(start, self.reset)
        engine.add_event_handler(pause, self.pause)

        if resume is not None:
            engine.add_event_handler(resume, self.resume)

        if step is not None:
            engine.add_event_handler(step, self.step)

        return self 
开发者ID:pytorch,项目名称:ignite,代码行数:39,代码来源:timing.py

示例15: _detach

# 需要导入模块: from ignite.engine import Events [as 别名]
# 或者: from ignite.engine.Events import STARTED [as 别名]
def _detach(self, trainer):
        """
        Detaches lr_finder from trainer.

        Args:
            trainer: the trainer to detach form.
        """

        if trainer.has_event_handler(self._run, Events.STARTED):
            trainer.remove_event_handler(self._run, Events.STARTED)
        if trainer.has_event_handler(self._warning, Events.COMPLETED):
            trainer.remove_event_handler(self._warning, Events.COMPLETED)
        if trainer.has_event_handler(self._reset, Events.COMPLETED):
            trainer.remove_event_handler(self._reset, Events.COMPLETED) 
开发者ID:pytorch,项目名称:ignite,代码行数:16,代码来源:lr_finder.py


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