def create_predictor( self, transformation: Transformation, trained_network: HybridBlock ) -> Predictor: prediction_network = DeepStatePredictionNetwork( num_sample_paths=self.num_sample_paths, num_layers=self.num_layers, num_cells=self.num_cells, cell_type=self.cell_type, past_length=self.past_length, prediction_length=self.prediction_length, issm=self.issm, dropout_rate=self.dropout_rate, cardinality=self.cardinality, embedding_dimension=self.embedding_dimension, scaling=self.scaling, params=trained_network.collect_params(), ) copy_parameters(trained_network, prediction_network) return RepresentableBlockPredictor( input_transform=transformation, prediction_net=prediction_network, batch_size=self.trainer.batch_size, freq=self.freq, prediction_length=self.prediction_length, ctx=self.trainer.ctx, )
def create_predictor(self, transformation: Transformation, trained_network: HybridBlock) -> Predictor: prediction_splitter = self._create_instance_splitter("test") prediction_network = DeepStatePredictionNetwork( num_layers=self.num_layers, num_cells=self.num_cells, cell_type=self.cell_type, past_length=self.past_length, prediction_length=self.prediction_length, issm=self.issm, dropout_rate=self.dropout_rate, cardinality=self.cardinality, embedding_dimension=self.embedding_dimension, scaling=self.scaling, num_parallel_samples=self.num_parallel_samples, noise_std_bounds=self.noise_std_bounds, prior_cov_bounds=self.prior_cov_bounds, innovation_bounds=self.innovation_bounds, params=trained_network.collect_params(), ) copy_parameters(trained_network, prediction_network) return RepresentableBlockPredictor( input_transform=transformation + prediction_splitter, prediction_net=prediction_network, batch_size=self.batch_size, freq=self.freq, prediction_length=self.prediction_length, ctx=self.trainer.ctx, )
def create_predictor(self, transformation: Transformation, trained_network: HybridBlock) -> Predictor: prediction_network = GaussianProcessPredictionNetwork( prediction_length=self.prediction_length, context_length=self.context_length, cardinality=self.cardinality, num_samples=self.num_eval_samples, params=trained_network.collect_params(), kernel_output=self.kernel_output, params_scaling=self.params_scaling, ctx=self.trainer.ctx, float_type=self.float_type, max_iter_jitter=self.max_iter_jitter, jitter_method=self.jitter_method, sample_noise=self.sample_noise, ) copy_parameters(net_source=trained_network, net_dest=prediction_network) return RepresentableBlockPredictor( input_transform=transformation, prediction_net=prediction_network, batch_size=self.trainer.batch_size, freq=self.freq, prediction_length=self.prediction_length, ctx=self.trainer.ctx, float_type=self.float_type, )
def create_predictor(self, transformation: Transformation, trained_network: HybridBlock) -> Predictor: prediction_splitter = self._create_instance_splitter("test") prediction_network = NBEATSPredictionNetwork( prediction_length=self.prediction_length, context_length=self.context_length, num_stacks=self.num_stacks, widths=self.widths, num_blocks=self.num_blocks, num_block_layers=self.num_block_layers, expansion_coefficient_lengths=self.expansion_coefficient_lengths, sharing=self.sharing, stack_types=self.stack_types, params=trained_network.collect_params(), scale=self.scale, ) return RepresentableBlockPredictor( input_transform=transformation + prediction_splitter, prediction_net=prediction_network, batch_size=self.batch_size, freq=self.freq, prediction_length=self.prediction_length, ctx=self.trainer.ctx, )
def __init__(self, nn: HybridBlock, freq: int): """ :param nn: Model to plot parameters of. :param freq: Plotting frequency. """ self._params = nn.collect_params() self._freq = freq self._last_call = 0
def print_summary(net: gluon.HybridBlock, ipt_shape=(1, 3, 416, 416)): ctx = net.collect_params().list_ctx()[0] ipt = mx.random.uniform(shape=ipt_shape, ctx=ctx) net.summary(ipt) table = compute_net_params(net) logging.info("Parameter Statistics\n" + table.table) if wandb.run: headers = table.table_data[0] data = table.table_data[1:] wandb_table = wandb.Table(columns=headers, data=data) wandb.log({"Parameters Statistics": wandb_table}, commit=False)
def build_optimizer(cfg: dict, net: gluon.HybridBlock): lrs = build_lr_scheduler(cfg.pop('lr_scheduler', None)) cfg['optimizer_params']['lr_scheduler'] = lrs net.backbone.collect_params().setattr('lr_mult', cfg.pop('backbone_lr_mult', 1.0)) net.backbone.collect_params().setattr('wd_mult', cfg.pop('backbone_wd_mult', 1.0)) if cfg.pop('no_wd', False): net.collect_params('.*beta|.*gamma|.*bias').setattr('wd_mult', 0.0) opt = cfg.pop('type', 'sgd') optimizer_params = cfg.pop('optimizer_params', {}) if amp._amp_initialized: cfg['update_on_kvstore'] = False trainer = gluon.Trainer(net.collect_params(), opt, optimizer_params=optimizer_params, **cfg) if amp._amp_initialized: amp.init_trainer(trainer) return trainer
def create_predictor(self, transformation: Transformation, trained_network: HybridBlock) -> Predictor: prediction_network = SimpleFeedForwardPredictionNetwork( num_hidden_dimensions=self.num_hidden_dimensions, prediction_length=self.prediction_length, context_length=self.context_length, distr_output=self.distr_output, batch_normalization=self.batch_normalization, mean_scaling=self.mean_scaling, params=trained_network.collect_params(), num_parallel_samples=self.num_parallel_samples, ) return RepresentableBlockPredictor( input_transform=transformation, prediction_net=prediction_network, batch_size=self.trainer.batch_size, freq=self.freq, prediction_length=self.prediction_length, ctx=self.trainer.ctx, )
def __init__(self, name: str, model: gluon.HybridBlock, input_shapes: List[List[int]]): self._name = name self._sym = self._get_onnx_sym(model, len(input_shapes)) self._param_dict = model.collect_params() self._input_shapes = input_shapes