forked from tf-encrypted/tf-encrypted
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraining_single.py
33 lines (25 loc) · 998 Bytes
/
training_single.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Private training on data from a single owner"""
import tf_encrypted as tfe
from common import DataOwner, ModelOwner, LogisticRegression
num_features = 10
training_set_size = 2000
test_set_size = 100
batch_size = 100
num_batches = (training_set_size // batch_size) * 10
model = LogisticRegression(num_features)
model_owner = ModelOwner('model-owner')
data_owner = DataOwner('data-owner',
num_features,
training_set_size,
test_set_size,
batch_size)
x_train, y_train = data_owner.provide_training_data()
x_test, y_test = data_owner.provide_testing_data()
reveal_weights_op = model_owner.receive_weights(model.weights)
with tfe.Session() as sess:
sess.run([tfe.global_variables_initializer(),
data_owner.initializer],
tag='init')
model.fit(sess, x_train, y_train, num_batches)
model.evaluate(sess, x_test, y_test, data_owner)
sess.run(reveal_weights_op, tag='reveal')