Пример #1
0
    def __init__(self, params=None, layer_config=None, model_builder=None):
        self.nn_define = layer_config
        self.layer_config = layer_config

        self.host_input_shape = None
        self.guest_input_shape = None
        self.model = None
        self.rng_generator = random_number_generator.RandomNumberGenerator()
        self.model_builder = model_builder
        self.transfer_variable = None
        self.learning_rate = params.interactive_layer_lr
        self.encrypted_host_dense_output = None

        self.encrypted_host_input = None
        self.guest_input = None
        self.guest_output = None
        self.host_output = None

        self.dense_output_data = None

        self.guest_model = None
        self.host_model = None

        self.partitions = 0
        self.do_backward_select_strategy = False
        self.encrypted_host_input_cached = None
        self.drop_out_keep_rate = params.drop_out_keep_rate
        self.drop_out = None

        self.fixed_point_encoder = None if params.floating_point_precision is None else FixedPointEncoder(
            2**params.floating_point_precision)

        self.sync_output_unit = False
Пример #2
0
    def _init_model(self, param: FTLParam):

        self.nn_define = param.nn_define
        self.alpha = param.alpha
        self.tol = param.tol
        self.n_iter_no_change = param.n_iter_no_change
        self.validation_freqs = param.validation_freqs
        self.optimizer = param.optimizer
        self.intersect_param = param.intersect_param
        self.config_type = param.config_type
        self.batch_size = param.batch_size
        self.epochs = param.epochs
        self.mode = param.mode
        self.comm_eff = param.communication_efficient
        self.local_round = param.local_round

        assert 'learning_rate' in self.optimizer.kwargs, 'optimizer setting must contain learning_rate'
        self.learning_rate = self.optimizer.kwargs['learning_rate']

        if not self.comm_eff:
            self.local_round = 1
            LOGGER.debug(
                'communication efficient mode is not enabled, local_round set as 1'
            )

        self.encrypted_mode_calculator_param = param.encrypted_mode_calculator_param
        self.encrypter = self.generate_encrypter(param)
        self.predict_param = param.predict_param
        self.rng_generator = random_number_generator.RandomNumberGenerator()
Пример #3
0
    def test_tensor_op(self):

        arr1 = np.ones((10, 1, 3))
        arr1[0] = np.array([[2, 3, 4]])
        arr2 = np.ones((10, 3, 3))
        arr3 = np.ones([1, 1, 3])

        arr4 = np.ones([50, 1])
        arr5 = np.ones([32])

        pt = PaillierTensor(arr1)
        pt2 = PaillierTensor(arr2)
        pt3 = PaillierTensor(arr3)

        pt4 = PaillierTensor(arr4)
        pt5 = PaillierTensor(arr5)

        encrypter = PaillierEncrypt()
        encrypter.generate_key(EncryptParam().key_length)
        encrypted_calculator = EncryptModeCalculator(
            encrypter,
            EncryptedModeCalculatorParam().mode,
            EncryptedModeCalculatorParam().re_encrypted_rate)
        rs1 = pt * arr2
        rs2 = pt * pt2
        rs3 = pt.matmul_3d(pt2)
        enpt = pt2.encrypt(encrypted_calculator)
        enrs = enpt.matmul_3d(arr1, multiply='right')

        rng_generator = random_number_generator.RandomNumberGenerator()

        enpt2 = pt4.encrypt(encrypted_calculator)
        random_num = rng_generator.generate_random_number(enpt2.shape)
Пример #4
0
 def __init__(self, param):
     self.acc_noise = None
     self.learning_rate = param.interactive_layer_lr
     self.encrypted_mode_calculator_param = param.encrypted_model_calculator_param
     self.encrypter = self.generate_encrypter(param)
     self.train_encrypted_calculator = []
     self.predict_encrypted_calculator = []
     self.transfer_variable = None
     self.partitions = 1
     self.input_shape = None
     self.output_unit = None
     self.rng_generator = random_number_generator.RandomNumberGenerator()
Пример #5
0
    def __init__(self, params):
        self.acc_noise = None
        self.learning_rate = params.interactive_layer_lr
        self.encrypter = self.generate_encrypter(params)
        self.transfer_variable = None
        self.partitions = 1
        self.input_shape = None
        self.output_unit = None
        self.rng_generator = random_number_generator.RandomNumberGenerator()
        self.do_backward_select_strategy = False
        self.drop_out_keep_rate = params.drop_out_keep_rate

        self.fixed_point_encoder = None if params.floating_point_precision is None else FixedPointEncoder(
            2**params.floating_point_precision)
        self.mask_table = None
Пример #6
0
    def __init__(self, params=None, layer_config=None, model_builder=None):
        self.nn_define = layer_config
        self.layer_config = layer_config

        self.host_input_shape = None
        self.guest_input_shape = None
        self.model = None
        self.rng_generator = random_number_generator.RandomNumberGenerator()
        self.model_builder = model_builder
        self.transfer_variable = None
        self.learning_rate = params.interactive_layer_lr
        self.encrypted_host_dense_output = None

        self.encrypted_host_input = None
        self.guest_input = None
        self.guest_output = None
        self.host_output = None

        self.dense_output_data = None

        self.guest_model = None
        self.host_model = None

        self.partitions = 0