Ejemplo n.º 1
0
def main(server):

    num_rows = 7000
    num_features = 32
    num_epoch = 5
    batch_size = 100
    num_batches = (num_rows // batch_size) * num_epoch

    #who shall receive the output
    model_owner = ModelOwner('alice')

    data_schema0 = DataSchema([tf.float64] * 16, [0.0] * 16)
    data_schema1 = DataSchema([tf.int64] + [tf.float64] * 16, [0] + [0.0] * 16)
    data_owner_0 = DataOwner('alice',
                             'aliceTrainFile.csv',
                             data_schema0,
                             batch_size=batch_size)
    data_owner_1 = DataOwner('bob',
                             'bobTrainFileWithLabel.csv',
                             data_schema1,
                             batch_size=batch_size)

    tfe.set_protocol(
        tfe.protocol.Pond(
            tfe.get_config().get_player(data_owner_0.player_name),
            tfe.get_config().get_player(data_owner_1.player_name)))

    x_train_0 = tfe.define_private_input(data_owner_0.player_name,
                                         data_owner_0.provide_data)
    x_train_1 = tfe.define_private_input(data_owner_1.player_name,
                                         data_owner_1.provide_data)
    y_train = tfe.gather(x_train_1, 0, axis=1)
    y_train = tfe.reshape(y_train, [batch_size, 1])

    #Remove bob's first column (which is label)
    x_train_1 = tfe.strided_slice(x_train_1, [0, 1],
                                  [x_train_1.shape[0], x_train_1.shape[1]],
                                  [1, 1])

    x_train = tfe.concat([x_train_0, x_train_1], axis=1)

    model = LogisticRegression(num_features)
    reveal_weights_op = model_owner.receive_weights(model.weights)

    with tfe.Session() as sess:
        sess.run(tfe.global_variables_initializer(), tag='init')

        model.fit(sess, x_train, y_train, num_batches)
        # TODO(Morten)
        # each evaluation results in nodes for a forward pass being added to the graph;
        # maybe there's some way to avoid this, even if it means only if the shapes match
        # model.evaluate(sess, x_train, y_train, data_owner_0)
        # model.evaluate(sess, x_train, y_train, data_owner_1)

        sess.run(reveal_weights_op, tag='reveal')
Ejemplo n.º 2
0
tfe.set_protocol(tfe.protocol.Pond(
    tfe.get_config().get_player(data_owner_0.player_name),
    tfe.get_config().get_player(data_owner_1.player_name)
))

x_train_0, y_train_0 = data_owner_0.provide_training_data()
x_train_1, y_train_1 = data_owner_1.provide_training_data()

x_test_0, y_test_0 = data_owner_0.provide_testing_data()
x_test_1, y_test_1 = data_owner_1.provide_testing_data()

x_train = tfe.concat([x_train_0, x_train_1], axis=0)
y_train = tfe.concat([y_train_0, y_train_1], axis=0)

model = LogisticRegression(num_features)
reveal_weights_op = model_owner.receive_weights(model.weights)

with tfe.Session() as sess:
  sess.run([tfe.global_variables_initializer(),
            data_owner_0.initializer,
            data_owner_1.initializer],
           tag='init')

  model.fit(sess, x_train, y_train, num_batches)
  # TODO(Morten)
  # each evaluation results in nodes for a forward pass being added to the graph;
  # maybe there's some way to avoid this, even if it means only if the shapes match
  model.evaluate(sess, x_test_0, y_test_0, data_owner_0)
  model.evaluate(sess, x_test_1, y_test_1, data_owner_1)
Ejemplo n.º 3
0
"""Private prediction with a single clients"""
import tf_encrypted as tfe

from common import LogisticRegression, PredictionClient

num_features = 10

model = LogisticRegression(num_features)
prediction_client = PredictionClient('prediction-client', num_features)

x = tfe.define_private_input(prediction_client.player_name,
                             prediction_client.provide_input)

y = model.forward(x)

reveal_output = tfe.define_output(prediction_client.player_name, y,
                                  prediction_client.receive_output)

with tfe.Session() as sess:
    sess.run(tfe.global_variables_initializer(), tag='init')

    sess.run(reveal_output, tag='predict')