Ejemplo n.º 1
0
        def __init__(self, encoder, decoder, encoder_preproc, decoder_preproc):
            super().__init__()

            self.enc_preproc = registry.lookup(
                'encoder', encoder['name']).Preproc(**encoder_preproc)
            self.dec_preproc = registry.lookup(
                'decoder', decoder['name']).Preproc(**decoder_preproc)
Ejemplo n.º 2
0
    def __init__(self, logger, config):
        if torch.cuda.is_available():
            self.device = torch.device('cuda')
        else:
            self.device = torch.device('cpu')

        self.logger = logger
        self.train_config = registry.instantiate(TrainConfig, config['train'])
        self.data_random = random_state.RandomContext(
            self.train_config.data_seed)
        self.model_random = random_state.RandomContext(
            self.train_config.model_seed)

        self.init_random = random_state.RandomContext(
            self.train_config.init_seed)
        with self.init_random:
            # 0. Construct preprocessors
            self.model_preproc = registry.instantiate(registry.lookup(
                'model', config['model']).Preproc,
                                                      config['model'],
                                                      unused_keys=('name', ))
            self.model_preproc.load()

            # 1. Construct model
            self.model = registry.construct('model',
                                            config['model'],
                                            unused_keys=('encoder_preproc',
                                                         'decoder_preproc'),
                                            preproc=self.model_preproc,
                                            device=self.device)
            self.model.to(self.device)
Ejemplo n.º 3
0
    def __init__(self, config):
        self.config = config
        if torch.cuda.is_available():
            self.device = torch.device('cuda')
        else:
            self.device = torch.device('cpu')
            torch.set_num_threads(1)

        # 0. Construct preprocessors
        self.model_preproc = registry.instantiate(
            registry.lookup('model', config['model']).Preproc, config['model'])
        self.model_preproc.load()
Ejemplo n.º 4
0
    def __init__(self, logger, config, gpu):
        if torch.cuda.is_available():
            self.device = torch.device('cuda:{}'.format(gpu))
        else:
            self.device = torch.device('cpu')
        random.seed(1)
        numpy.random.seed(1)
        torch.manual_seed(1)
        torch.cuda.manual_seed_all(1)
        torch.backends.cudnn.benchmark = False
        torch.backends.cudnn.deterministic = True
        self.logger = logger
        self.train_config = registry.instantiate(TrainConfig, config['train'])
        self.train_config.eval_every_n = 500
        self.train_config.save_every_n = 500
        self.data_random = random_state.RandomContext(
            self.train_config.data_seed)
        self.model_random = random_state.RandomContext(
            self.train_config.model_seed)

        self.init_random = random_state.RandomContext(
            self.train_config.init_seed)
        with self.init_random:
            # 0. Construct preprocessors
            self.model_preproc = registry.instantiate(registry.lookup(
                'model', config['model']).Preproc,
                                                      config['model'],
                                                      unused_keys=('name', ))
            self.model_preproc.load()

            # 1. Construct model
            self.model = registry.construct('model',
                                            config['model'],
                                            unused_keys=('encoder_preproc',
                                                         'decoder_preproc'),
                                            preproc=self.model_preproc,
                                            device=self.device)
            self.model.to(self.device)
Ejemplo n.º 5
0
 def __init__(self, config):
     self.config = config
     self.model_preproc = registry.instantiate(
         registry.lookup('model', config['model']).Preproc, config['model'])