File size: 985 Bytes
8c212a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# python3.7
"""Contains the running controller for saving snapshot."""

from .base_controller import BaseController

__all__ = ['Snapshoter']


class Snapshoter(BaseController):
    """Defines the running controller for evaluation.

    NOTE: The controller is set to `LAST` priority by default.
    """

    def __init__(self, config):
        config.setdefault('priority', 'LAST')
        super().__init__(config)

        self.num = config.get('num', 100)

    def setup(self, runner):
        assert hasattr(runner, 'synthesize')

    def execute_after_iteration(self, runner):
        mode = runner.mode  # save runner mode.
        runner.synthesize(self.num,
                          html_name=f'snapshot_{runner.iter:06d}.html',
                          save_raw_synthesis=False)
        runner.logger.info(f'Saving snapshot at iter {runner.iter:06d} '
                           f'({runner.seen_img / 1000:.1f} kimg).')
        runner.set_mode(mode)  # restore runner mode.