secretflow.ml.nn.sl package#
Subpackages#
Submodules#
secretflow.ml.nn.sl.sl_model module#
SLModel
Classes:
|
- class secretflow.ml.nn.sl.sl_model.SLModel(base_model_dict: Dict[Device, Callable[[], tensorflow.keras.Model]] = {}, device_y: PYU = None, model_fuse: Callable[[], tensorflow.keras.Model] = None, compressor: Compressor = None, dp_strategy_dict: Dict[Device, DPStrategy] = None, **kwargs)[源代码]#
基类:
object
Methods:
__init__
([base_model_dict, device_y, ...])handle_data
(x[, y, sample_weight, ...])fit
(x, y[, batch_size, epochs, verbose, ...])Vertical split learning training interface
predict
(x[, batch_size, verbose, ...])Vertical split learning offline prediction interface
evaluate
(x, y[, batch_size, sample_weight, ...])Vertical split learning evaluate interface
save_model
([base_model_path, ...])Vertical split learning save model interface
load_model
([base_model_path, ...])Vertical split learning load model interface
- __init__(base_model_dict: Dict[Device, Callable[[], tensorflow.keras.Model]] = {}, device_y: PYU = None, model_fuse: Callable[[], tensorflow.keras.Model] = None, compressor: Compressor = None, dp_strategy_dict: Dict[Device, DPStrategy] = None, **kwargs)[源代码]#
- handle_data(x: Union[VDataFrame, FedNdarray, List[Union[HDataFrame, VDataFrame, FedNdarray]]], y: Optional[Union[FedNdarray, VDataFrame, PYUObject]] = None, sample_weight: Optional[Union[FedNdarray, VDataFrame]] = None, batch_size=32, shuffle=False, epochs=1, stage='train', random_seed=1234, dataset_builder: Optional[Callable] = None)[源代码]#
- fit(x: Union[VDataFrame, FedNdarray, List[Union[HDataFrame, VDataFrame, FedNdarray]]], y: Union[VDataFrame, FedNdarray, PYUObject], batch_size=32, epochs=1, verbose=1, callbacks=None, validation_data=None, shuffle=False, sample_weight=None, validation_freq=1, dp_spent_step_freq=None, dataset_builder: Optional[Callable[[List], Tuple[int, Iterable]]] = None, audit_log_dir: Optional[str] = None, random_seed: Optional[int] = None)[源代码]#
Vertical split learning training interface
- 参数
x – Input data. It could be:
VDataFrame (-) – a vertically aligned dataframe.
FedNdArray (-) – a vertically aligned ndarray.
List[Union[HDataFrame (-) – list of dataframe or ndarray.
VDataFrame – list of dataframe or ndarray.
FedNdarray]] – list of dataframe or ndarray.
y – Target data. It could be a VDataFrame or FedNdarray which has only one partition, or a PYUObject.
batch_size – Number of samples per gradient update.
epochs – Number of epochs to train the model
verbose – 0, 1. Verbosity mode
callbacks – List of keras.callbacks.Callback instances.
validation_data – Data on which to validate
shuffle – Whether shuffle dataset or not
validation_freq – specifies how many training epochs to run before a new validation run is performed
sample_weight – weights for the training samples
dp_spent_step_freq – specifies how many training steps to check the budget of dp
dataset_builder – Callable function, its input is x or [x, y] if y is set, it should return a iterable dataset which should has steps_per_epoch property. Dataset builder is mainly for building graph dataset.
- predict(x: Union[VDataFrame, FedNdarray, List[Union[HDataFrame, VDataFrame, FedNdarray]]], batch_size=32, verbose=0, dataset_builder: Optional[Callable[[List], Tuple[int, Iterable]]] = None, compress: bool = False)[源代码]#
Vertical split learning offline prediction interface
- 参数
x – Input data. It could be:
VDataFrame (-) – a vertically aligned dataframe.
FedNdArray (-) – a vertically aligned ndarray.
List[Union[HDataFrame (-) – list of dataframe or ndarray.
VDataFrame – list of dataframe or ndarray.
FedNdarray]] – list of dataframe or ndarray.
batch_size – Number of samples per gradient update, Int
verbose – 0, 1. Verbosity mode
dataset_builder – Callable function, its input is x or [x, y] if y is set, it should return steps_per_epoch and iterable dataset. Dataset builder is mainly for building graph dataset.
compress – Whether to use compressor to compress cross device data.
- evaluate(x: Union[VDataFrame, FedNdarray, List[Union[HDataFrame, VDataFrame, FedNdarray]]], y: Union[VDataFrame, FedNdarray, PYUObject], batch_size: int = 32, sample_weight=None, verbose=1, dataset_builder: Callable[[List], Tuple[int, Iterable]] = None, random_seed: int = None, compress: bool = False)[源代码]#
Vertical split learning evaluate interface
- 参数
x – Input data. It could be:
VDataFrame (-) – a vertically aligned dataframe.
FedNdArray (-) – a vertically aligned ndarray.
List[Union[HDataFrame (-) – list of dataframe or ndarray.
VDataFrame – list of dataframe or ndarray.
FedNdarray]] – list of dataframe or ndarray.
y – Target data. It could be a VDataFrame or FedNdarray which has only one partition, or a PYUObject.
batch_size – Integer or Dict. Number of samples per batch of computation. If unspecified, batch_size will default to 32.
sample_weight – Optional Numpy array of weights for the test samples, used for weighting the loss function.
verbose – Verbosity mode. 0 = silent, 1 = progress bar.
dataset_builder – Callable function, its input is x or [x, y] if y is set, it should return steps_per_epoch and iterable dataset. Dataset builder is mainly for building graph dataset.
compress – Whether to use compressor to compress cross device data.
- 返回
federate evaluate result
- 返回类型
metrics
- save_model(base_model_path: Optional[Union[str, Dict[PYU, str]]] = None, fuse_model_path: Optional[str] = None, is_test=False, save_traces=True)[源代码]#
Vertical split learning save model interface
- 参数
base_model_path – base model path,only support format like ‘a/b/c’, where c is the model name
fuse_model_path – fuse model path
is_test – whether is test mode
save_traces – (only applies to SavedModel format) When enabled, the SavedModel will store the function traces for each layer.
- load_model(base_model_path: Optional[Union[str, Dict[PYU, str]]] = None, fuse_model_path: Optional[str] = None, is_test=False, base_custom_objects=None, fuse_custom_objects=None)[源代码]#
Vertical split learning load model interface
- 参数
base_model_path – base model path
fuse_model_path – fuse model path
is_test – whether is test mode
base_custom_objects – Optional dictionary mapping names (strings) to custom classes or functions of the base model to be considered during deserialization
fuse_custom_objects – Optional dictionary mapping names (strings) to custom classes or functions of the base model to be considered during deserialization.