eq_values = tf.equal(prediction, tf.cast(y_true, tf.int64))
            acc = tf.reduce_mean(tf.cast(eq_values, tf.float32))
            op = tf.Print([], [y_true], summarize=self.BATCH_SIZE, message="EXPECT: ")
            op = tf.Print(op, [prediction], summarize=self.BATCH_SIZE, message="ACTUAL: ")
            op = tf.Print([op], [acc], summarize=self.BATCH_SIZE, message="Acuraccy: ")
            return op


model_trainer = ModelTrainer()
prediction_client = PredictionClient()

# get model parameters as private tensors from model owner
params = tfe.define_private_input('model-trainer', model_trainer.provide_input, masked=True)  # pylint: disable=E0632

# we'll use the same parameters for each prediction so we cache them to avoid re-training each time
params = tfe.cache(params)

# get prediction input from client
x, y = tfe.define_private_input('prediction-client', prediction_client.provide_input, masked=True)  # pylint: disable=E0632

# helpers
conv = lambda x, w, s: tfe.conv2d(x, w, s, 'VALID')
pool = lambda x: tfe.avgpool2d(x, (2, 2), (2, 2), 'VALID')

# compute prediction
Wconv1, bconv1, Wfc1, bfc1, Wfc2, bfc2 = params
bconv1 = tfe.reshape(bconv1, [-1, 1, 1])
layer1 = pool(tfe.relu(conv(x, Wconv1, ModelTrainer.STRIDE) + bconv1))
layer1 = tfe.reshape(layer1, [-1, ModelTrainer.HIDDEN_FC1])
layer2 = tfe.matmul(layer1, Wfc1) + bfc1
logits = tfe.matmul(layer2, Wfc2) + bfc2
Exemple #2
0
    start = time.time()
    model_owner = ModelOwner(player_name="model-owner",
                             local_data_file="./data/train_half.tfrecord")

    prediction_client = PredictionClient(
        player_name="prediction-client",
        local_data_file="./data/test.tfrecord")

    # get model parameters as private tensors from model owner
    params = tfe.define_private_input(model_owner.player_name,
                                      model_owner.provide_input,
                                      masked=True)  # pylint: disable=E0632

    # we'll use the same parameters for each prediction so we cache them to
    # avoid re-training each time
    cache_updater, params = tfe.cache(params)

    # get prediction input from client
    x = tfe.define_private_input(prediction_client.player_name,
                                 prediction_client.provide_input,
                                 masked=True)  # pylint: disable=E0632

    # compute prediction
    w0, b0, w1, b1 = params
    layer0 = tfe.matmul(x, w0) + b0
    layer1 = tfe.sigmoid(layer0 *
                         0.1)  # input normalized to avoid large values
    logits = tfe.matmul(layer1, w1) + b1

    # send prediction output back to client
    prediction_op = tfe.define_output(prediction_client.player_name, logits,