def __init__(self, name=None, max_iter=100, batch_size=-1, secure_aggregate=True, aggregate_every_n_epoch=1, early_stop="diff", encode_label=False, predict_param=None, cv_param=None, **kwargs): explicit_parameters = kwargs["explict_parameters"] explicit_parameters["optimizer"] = None explicit_parameters["loss"] = None explicit_parameters["metrics"] = None explicit_parameters["nn_define"] = None explicit_parameters["config_type"] = "keras" Component.__init__(self, **explicit_parameters) if "name" in explicit_parameters: del explicit_parameters["name"] for param_key, param_value in explicit_parameters.items(): setattr(self, param_key, param_value) self.optimizer = None self.loss = None self.metrics = None self.nn_define = None self.config_type = "keras" self.input = Input(self.name, data_type="multi") self.output = Output(self.name, data_type='single') self._module_name = "HomoNN" self._model = Sequential()
def __init__(self, epochs=1, batch_size=-1, encrypt_param=None, predict_param=None, cv_param=None, intersect_param={'intersect_method': consts.RSA}, validation_freqs=None, early_stopping_rounds=None, use_first_metric_only=None, mode='plain', communication_efficient=False, n_iter_no_change=False, tol=1e-5, local_round=5, **kwargs): explicit_parameters = kwargs["explict_parameters"] explicit_parameters["optimizer"] = None # explicit_parameters["loss"] = None # explicit_parameters["metrics"] = None explicit_parameters["nn_define"] = None explicit_parameters["config_type"] = "keras" FateComponent.__init__(self, **explicit_parameters) if "name" in explicit_parameters: del explicit_parameters["name"] for param_key, param_value in explicit_parameters.items(): setattr(self, param_key, param_value) self.input = Input(self.name, data_type="multi") self.output = Output(self.name, data_type='single') self._module_name = "FTL" self.optimizer = None self.loss = None self.config_type = "keras" self.metrics = None self.bottom_nn_define = None self.top_nn_define = None self.interactive_layer_define = None self._nn_model = Sequential() self.nn_define = None
class HomoNN(Component): @extract_explicit_parameter def __init__(self, name=None, max_iter=100, batch_size=-1, secure_aggregate=True, aggregate_every_n_epoch=1, early_stop="diff", encode_label=False, predict_param=None, cv_param=None, **kwargs): explicit_parameters = kwargs["explict_parameters"] explicit_parameters["optimizer"] = None explicit_parameters["loss"] = None explicit_parameters["metrics"] = None explicit_parameters["nn_define"] = None explicit_parameters["config_type"] = "keras" Component.__init__(self, **explicit_parameters) if "name" in explicit_parameters: del explicit_parameters["name"] for param_key, param_value in explicit_parameters.items(): setattr(self, param_key, param_value) self.optimizer = None self.loss = None self.metrics = None self.nn_define = None self.config_type = "keras" self.input = Input(self.name, data_type="multi") self.output = Output(self.name, data_type='single') self._module_name = "HomoNN" self._model = Sequential() def set_model(self, model): self._model = model def add(self, layer): self._model.add(layer) return self def compile(self, optimizer, loss=None, metrics=None): if metrics and not isinstance(metrics, list): raise ValueError("metrics should be a list") self.optimizer = self._model.get_optimizer_config(optimizer) self.loss = self._model.get_loss_config(loss) self.metrics = metrics self.config_type = self._model.get_layer_type() self.nn_define = self._model.get_network_config() return self def __getstate__(self): state = dict(self.__dict__) del state["_model"] return state
def __init__(self, task_type="classification", epochs=None, batch_size=-1, early_stop="diff", tol=1e-5, encrypt_param=None, predict_param=None, cv_param=None, interactive_layer_lr=0.1, validation_freqs=None, early_stopping_rounds=None, use_first_metric_only=None, floating_point_precision=23, drop_out_keep_rate=1, selector_param=None, **kwargs): explicit_parameters = kwargs["explict_parameters"] explicit_parameters["optimizer"] = None explicit_parameters["bottom_nn_define"] = None explicit_parameters["top_nn_define"] = None explicit_parameters["interactive_layer_define"] = None explicit_parameters["config_type"] = "keras" FateComponent.__init__(self, **explicit_parameters) if "name" in explicit_parameters: del explicit_parameters["name"] for param_key, param_value in explicit_parameters.items(): setattr(self, param_key, param_value) self.input = Input(self.name, data_type="multi") self.output = Output(self.name, data_type='single') self._module_name = "HeteroNN" self.optimizer = None self.config_type = "keras" self.bottom_nn_define = None self.top_nn_define = None self.interactive_layer_define = None self._bottom_nn_model = Sequential() self._interactive_layer = Sequential() self._top_nn_model = Sequential()
def add_top_model(self, layer): if not hasattr(self, "_top_nn_model"): setattr(self, "_top_nn_model", Sequential()) self._top_nn_model.add(layer)
def set_interactve_layer(self, layer): if not hasattr(self, "_interactive_layer"): setattr(self, "_interactive_layer", Sequential()) self._interactive_layer.add(layer)
def add_bottom_model(self, layer): if not hasattr(self, "_bottom_nn_model"): setattr(self, "_bottom_nn_model", Sequential()) self._bottom_nn_model.add(layer)
class HeteroNN(Component): @extract_explicit_parameter def __init__(self, task_type="classification", epochs=None, batch_size=-1, early_stop="diff", tol=1e-5, encrypt_param=None, predict_param=None, cv_param=None, interactive_layer_lr=0.1, validation_freqs=None, early_stopping_rounds=None, use_first_metric_only=None, **kwargs): explicit_parameters = kwargs["explict_parameters"] explicit_parameters["optimizer"] = None explicit_parameters["loss"] = None explicit_parameters["metrics"] = None explicit_parameters["bottom_nn_define"] = None explicit_parameters["top_nn_define"] = None explicit_parameters["interactive_layer_define"] = None explicit_parameters["config_type"] = "keras" Component.__init__(self, **explicit_parameters) if "name" in explicit_parameters: del explicit_parameters["name"] for param_key, param_value in explicit_parameters.items(): setattr(self, param_key, param_value) self.input = Input(self.name, data_type="multi") self.output = Output(self.name, data_type='single') self._module_name = "HeteroNN" self.optimizer = None self.loss = None self.config_type = "keras" self.metrics = None self.bottom_nn_define = None self.top_nn_define = None self.interactive_layer_define = None self._bottom_nn_model = Sequential() self._interactive_layer = Sequential() self._top_nn_model = Sequential() def add_bottom_model(self, layer): if not hasattr(self, "_bottom_nn_model"): setattr(self, "_bottom_nn_model", Sequential()) self._bottom_nn_model.add(layer) def set_interactve_layer(self, layer): if not hasattr(self, "_interactive_layer"): setattr(self, "_interactive_layer", Sequential()) self._interactive_layer.add(layer) def add_top_model(self, layer): if not hasattr(self, "_top_nn_model"): setattr(self, "_top_nn_model", Sequential()) self._top_nn_model.add(layer) def compile(self, optimizer, loss=None, metrics=None): if metrics and not isinstance(metrics, list): raise ValueError("metrics should be a list") model = self.get_bottom_model() self.optimizer = model.get_optimizer_config(optimizer) self.loss = model.get_loss_config(loss) self.metrics = metrics self.config_type = model.get_layer_type() self._compile_common_network_config() self._compile_role_network_config() def _compile_common_network_config(self): if hasattr( self, "_bottom_nn_model") and not self._bottom_nn_model.is_empty(): self.bottom_nn_define = self._bottom_nn_model.get_network_config() self._component_param["bottom_nn_define"] = self.bottom_nn_define if hasattr(self, "_top_nn_model") and not self._top_nn_model.is_empty(): self.top_nn_define = self._top_nn_model.get_network_config() self._component_param["top_nn_define"] = self.top_nn_define if hasattr(self, "_interactive_layer" ) and not self._interactive_layer.is_empty(): self.interactive_layer_define = self._interactive_layer.get_network_config( ) self._component_param[ "interactive_layer_define"] = self.interactive_layer_define def _compile_role_network_config(self): all_party_instance = self._get_all_party_instance() for role in all_party_instance: for party in all_party_instance[role]["party"].keys(): all_party_instance[role]["party"][ party]._compile_common_network_config() def get_bottom_model(self): if hasattr(self, "_bottom_nn_model") and not getattr( self, "_bottom_nn_model").is_empty(): return getattr(self, "_bottom_nn_model") all_party_instance = self._get_all_party_instance() for role in all_party_instance.keys(): for party in all_party_instance[role]["party"].keys(): if all_party_instance[role]["party"][party].get_bottom_model(): return all_party_instance[role]["party"][ party].get_bottom_model() return None def __getstate__(self): state = dict(self.__dict__) if "_bottom_nn_model" in state: del state["_bottom_nn_model"] if "_interactive_layer" in state: del state["_interactive_layer"] if "_top_nn_model" in state: del state["_top_nn_model"] return state