def from_base_network(cls, base_network, json_content=None, share_params=False, base_as_calc_step=False, **kwargs): """ :param LayerNetwork base_network: base network to derive from :param dict[str]|None json_content: JSON content for subnetwork. if None, will use from base network :param bool share_params: will use the same params as the base network :param bool base_as_calc_step: base is calc step 0. see below :param dict[str] kwargs: kwargs for __init__ :rtype: LayerNetwork """ if "n_out" in kwargs and "n_in" not in kwargs: kwargs["n_in"] = None network = cls( base_network=base_network, shared_params_network=base_network if share_params else None, **dict_joined(base_network.init_args(), kwargs)) if base_as_calc_step: network.calc_step_base = base_network # used by CalcStepLayer. see also get_calc_step() if json_content is None: json_content = base_network.to_json_content() cls.from_json(json_content, network=network) if share_params: trainable_params = network.get_all_params_vars() assert len(trainable_params) == 0 return network
def from_json_and_config(cls, json_content, config, **kwargs): """ :type config: Config.Config :type json_content: str | dict :rtype: LayerNetwork """ network = cls.from_json(json_content, **dict_joined(kwargs, cls.init_args_from_config(config))) network.recurrent = network.recurrent or config.bool('recurrent', False) return network
def from_base_network(cls, base_network, json_content=None, share_params=False, base_as_calc_step=False, **kwargs): """ :param LayerNetwork base_network: base network to derive from :param dict[str]|None json_content: JSON content for subnetwork. if None, will use from base network :param bool share_params: will use the same params as the base network :param bool base_as_calc_step: base is calc step 0. see below :param dict[str] kwargs: kwargs for __init__ :rtype: LayerNetwork """ network = cls( base_network=base_network, shared_params_network=base_network if share_params else None, **dict_joined(base_network.init_args(), kwargs)) if base_as_calc_step: network.calc_step_base = base_network # used by CalcStepLayer. see also get_calc_step() if json_content is None: json_content = base_network.to_json_content() cls.from_json(json_content, network=network) if share_params: trainable_params = network.get_all_params_vars() assert len(trainable_params) == 0 return network