예제 #1
0
def __test_reduce_op(op_functor, msg, xa, axis=None):
    # max/mean/sum/...
    init = tf.compat.v1.global_variables_initializer()
    sess = tf.compat.v1.Session()
    sess.run(init)

    ###########
    # print("=========================== ", msg, " 1 beg")
    # xc = op_functor(xa, axis=axis)
    # xcc = sess.run(xc)
    # print(xcc)
    # print("=========================== ", msg, " 1 end")

    # axis=None,keep_dims=False,name=None,reduction_indices=None
    print("=========================== ", msg, "BEGIN")
    xc = op_functor(xa, axis=axis)
    #xd = op_functor(xa, axis=axis)
    #xe = op_functor(xa, axis=axis)
    xee = sess.run([xa, xc])
    result = []
    # to support both native TF OP and Rosetta OP test
    if 'latticex.rosetta' in sys.modules:
        import latticex.rosetta as rtt
        reveal_input = sess.run(rtt.SecureReveal(xee[0]))
        reveal_output = sess.run(rtt.SecureReveal(xee[1]))
        print("revealed input:", reveal_input)
        print("revealed output:", reveal_output)
        result = np.array(reveal_output, dtype=np.float)
    else:
        print("input:", xee[0])
        print("output :", xee[1])
        result = np.array(xee[1], dtype=np.float)
    print("=========================== ", msg, " END")
    return result
예제 #2
0
 def run(self):
     with graph.as_default():
         # print("thread:", self.tid, self.name, self.sess)
         # for ii in range(2):
         pred_Y = tf.sigmoid(tf.matmul(X, W) + b)
         reaveal_Y = rtt.SecureReveal(pred_Y)
         res = sess.run(reaveal_Y)
예제 #3
0
def bin_op_rh_const_test(protocol, task_id, tf_op, x_init, y_init, expect_val):
    Result = True
    local_g = tf.Graph()
    with local_g.as_default():
        X = tf.Variable(x_init)
        Z = tf_op(X, y_init)
        rv_Z = rtt.SecureReveal(Z)
        init = tf.compat.v1.global_variables_initializer()

        try:
            rtt.activate(protocol, task_id=task_id)
            config = tf.ConfigProto(inter_op_parallelism_threads=16,
                                    intra_op_parallelism_threads=16)
            with tf.Session(task_id=task_id, config=config) as sess:
                sess.run(init)
                real_Z = sess.run(rv_Z)
                res = check_mpc_results(real_Z, expect_val)
                if (res == False):
                    Result = False
            rtt.deactivate(task_id=task_id)
        except Exception as e:
            print(str(e))
            Result = False

    return Result
예제 #4
0
def test_private_input_op(name):
    in1 = rtt.PrivateInput(tf.Variable([1, 2]), data_owner=0)
    in2 = rtt.PrivateInput(tf.Variable([2, 3]), data_owner=1)
    ret = rtt.SecureReveal(tf.multiply(in1, in2))  # expect [2,6]

    result = create_run_session(ret)
    print("private_input and result: ", result, ", expect: [2,6]")
    print("test_private_input ok.")
예제 #5
0
def classification_loss(logit, label):
    # loss = tf.reduce_mean(
    #     tf.nn.softmax_cross_entropy_with_logits_v2(labels=label, logits=logit))
    softmax_logits = tf.nn.softmax(logit)
    return None, rtt.SecureReveal(softmax_logits)

    prediction = tf.equal(tf.argmax(logit, -1), tf.argmax(label, -1))
    accuracy = tf.reduce_mean(tf.cast(prediction, tf.float32))

    return None, accuracy
예제 #6
0
def test_snn_pow(lh_is_const=False, rh_is_const=True):
    print("---- test snn pow ----")
    in1 = tf.Variable([1, 2], name="in1")
    # in2 = tf.constant(["1","1"], name="in2") # not support now
    # in2 = tf.constant(["1"], name="in2") # not support now
    in2 = tf.constant(1, name="in2")
    c = tf.pow(in1, in2)  #, lh_is_const=False, rh_is_const=True)
    rc = rtt.SecureReveal(c)
    #ret = rtt.secure_reveal(c)
    ## ret = rtt.secure_to_tf(reveal_c, dtype=tf.float64)
    result = create_run_session(rc)
    print("pow result: ", result, ", math.pow(x, 2): ", 2.0, 4.0)
    print("-----   test_pow (OK) -----")
예제 #7
0
def test_accumutive_op(opfn, N=2):
    print("---- test snn add_n ----")
    elem = ["1", "2", "3"]
    inputs = []
    for i in range(N):
        inputs.append(elem)

    c = opfn(inputs)
    rc = rtt.SecureReveal(c)
    #ret = rtt.secure_reveal(c)
    ## ret = rtt.secure_to_tf(reveal_c, dtype=tf.float64)
    result = create_run_session(rc)
    print("add result: ", result, ", math.add_n([1,2,3],....): ", 2, 4, 6)
    print("-----   test_add (OK) -----")
예제 #8
0
def test_max_grad(X, axis, out_g, protocol="Helix"):
    cb.activate(protocol)

    global sess
    if sess is not None:
        sess.close()

    # ===========================
    # init global var
    # ===========================
    init = tf.compat.v1.global_variables_initializer()
    sess = tf.compat.v1.Session()
    sess.run(init)

    # ===========================
    # run mpc max grad
    # ===========================
    print("===========================")
    print("# run mpc max(X) grad, axis=", axis)
    mpc_Y = cb.SecureMax(X, axis=axis)
    print(sess.run(cb.SecureReveal(mpc_Y)))
    mpc_g = tf.gradients(mpc_Y, [common.get_var_from_rtt_tensor(X)])
    print(sess.run(mpc_g))
    print("===========================")

    # ===========================
    # check mpcmax grads value
    # ===========================
    mpc_out_g = []
    for i in range(len(mpc_g)):
        print("---------- Reveal mpcmax grad ------------")
        mpc_out_g.append(sess.run(cb.SecureReveal(mpc_g[i])))
        print(mpc_out_g)
        print("------------------------------------------")

    global res_flag
    res_flag = res_flag and common.check_mpc_op_grads(out_g, mpc_out_g)
예제 #9
0
def test_add_grad(X, Y, out_g, protocol="Helix"):
    cb.activate(protocol)

    global sess
    if sess is not None:
        sess.close()

    # ===========================
    # init global var
    # ===========================
    init = tf.compat.v1.global_variables_initializer()
    sess = tf.compat.v1.Session()
    sess.run(init)

    # ===========================
    # run mpc add grad
    # ===========================
    print("===========================")
    print("run mpc add(X + Y) grad")
    mpc_Z = cb.SecureAdd(X, Y)
    mpc_g = tf.gradients(
        mpc_Z,
        [common.get_var_from_rtt_tensor(X),
         common.get_var_from_rtt_tensor(Y)])
    print(sess.run(mpc_g))
    print("===========================")

    # ===========================
    # reveal value
    # ===========================
    mpc_out_g = []
    for i in range(len(mpc_g)):
        print("---------- Reveal mpcadd grad ------------")
        mpc_out_g.append(sess.run(cb.SecureReveal(mpc_g[i])))
        print(mpc_out_g)
        print("------------------------------------------")

    # ===========================
    # check mpc add grads value
    # ===========================
    global res_flag
    res_flag = common.check_mpc_op_grads(out_g, mpc_out_g)
예제 #10
0
def test_sigmoidcrocssentropy_grad(logits, labels, out_g, protocol="Helix"):
    rst.activate(protocol)

    global sess
    if sess is not None:
        sess.close()

    # ===========================
    # init global var
    # ===========================
    init = tf.compat.v1.global_variables_initializer()
    sess = tf.compat.v1.Session()
    sess.run(init)

    # ===========================
    # run mpc SCE grad:
    # ===========================
    print("===========================")
    print("run mpc SCE(X,Y) grad")
    Z_mpc = rst.secure_sigmoid_cross_entropy_with_logits(logits=logits,
                                                         labels=labels)
    mpc_g = tf.gradients(Z_mpc, [
        common.get_var_from_rtt_tensor(logits),
        common.get_var_from_rtt_tensor(labels)
    ])
    print(sess.run(mpc_g))
    print("===========================")

    # ===========================
    # check mpcSCE grads value
    # ===========================
    mpc_out_g = []
    for i in range(len(mpc_g)):
        print("---------- Reveal mpcSCE grad ------------")
        mpc_out_g.append(sess.run(rst.SecureReveal(mpc_g[i])))
        print(mpc_out_g)
        print("------------------------------------------")

    global res_flag
    res_flag = res_flag and common.check_mpc_op_grads(out_g, mpc_out_g)
예제 #11
0
def test_protocol(protocol_name="SecureNN"):
    rst.activate(protocol_name)
    PRI_LOGITS = rst.private_input(0, np_a)
    PRI_LABELS = rst.private_input(1, np_b)

    PRI_logits = tf.Variable(PRI_LOGITS, dtype=tf.string)
    PRI_labels = tf.Variable(PRI_LABELS, dtype=tf.string)

    init = tf.compat.v1.global_variables_initializer()
    PRI_sess = tf.compat.v1.Session()
    PRI_sess.run(init)

    start_t = time.time()
    result_mpc = rst.secure_sigmoid_cross_entropy_with_logits(
        logits=PRI_logits, labels=PRI_labels)
    PRI_sess.run(result_mpc)
    end_t = time.time()
    reveal_op = rst.SecureReveal(result_mpc)
    xcc = PRI_sess.run(reveal_op)
    print(xcc)
    print("{} elapsed: {} ".format(protocol_name, end_t - start_t))
    rst.deactivate()
예제 #12
0
파일: log1p.py 프로젝트: xiaojiqing/Rosetta
#
init = tf.compat.v1.global_variables_initializer()
sess = tf.compat.v1.Session()
sess.run(init)
print("input xa:", sess.run(xa))

###########
print("=========================== tf op log1p 1")
xc = tf.log1p(xa)
xcc = sess.run(xc)
print("=========================== tf op log1p 2")
print("TF Log1p:", xcc)

import latticex.rosetta as rtt
#rtt.py_protocol_handler.set_loglevel(0)
rtt.activate("SecureNN")

xb = tf.Variable([[1.892, 2], [3, 4.43], [.0091, .3]])

init = tf.compat.v1.global_variables_initializer()
sess = tf.compat.v1.Session()
sess.run(init)
print("=========================== mpc op log1p 1")
xc = rtt.SecureReveal(rtt.SecureLog1p(xb))
xcc = sess.run(xc)
print("MPC revealed Log1p:", xcc)
print("=========================== mpc op log1p 2")

###########
예제 #13
0
for n in nodes:
    if n != node:
        rtt.send_msg(n, msgid, node + " to " + n)
for n in nodes:
    if n != node:
        msg = rtt.recv_msg(n, msgid, 2 * len(node) + 4)
        print('get msg from ', n, " msg:", msg)

# Get private data from Alice (input x), Bob (input y)
w = tf.Variable(rtt.private_input(0, [[1, 2], [2, 3]]))
x = tf.Variable(rtt.private_input(1, [[1, 2], [2, 3]]))
y = tf.Variable(rtt.private_input(2, [[1, 2], [2, 3]]))
z = tf.Variable(rtt.private_input('p9', [[1, 2], [2, 3]]))

# Define matmul operation
res = tf.matmul(tf.matmul(w, x), tf.matmul(y, z))

# Start execution
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    res = sess.run(res)

    # Get the result of Rosetta matmul
    # ret: [[b'14.000000' b'20.000000'] [b'20.000000' b'29.000000']]
    receivers = (0, 1, 'p9', 2)
    receivers = 0b011
    receivers = None
    print('matmul:', sess.run(rtt.SecureReveal(res, receive_party=receivers)))

rtt.deactivate()
예제 #14
0
import tensorflow as tf
import sys
import numpy as np
np.set_printoptions(suppress=True)

protocol = "Helix"
rtt.activate(protocol)

x = np.array([[2.0, 2.1], [2.2, 2.3]])
y = np.array([[1, 2.0], [1, 3.0]])
z = np.array([[[0, 1, 2.4, 0, 1, 2.9]], [[0.3, 1, 2, 0, 1.2, 2]]])

input0 = rtt.private_input(0, x)
input1 = rtt.private_input(1, y)
input2 = rtt.private_input(2, z)
print('input0:', type(input0), input0)
print('input1:', type(input1), input1)
print('input2:', type(input2), input2)

i0 = tf.Variable(input0)
i1 = tf.Variable(input1)
i2 = tf.Variable(input2)

ii = rtt.SecureMatMul(i0, i1)
ir_matmul = rtt.SecureReveal(ii)

init = tf.global_variables_initializer()
with tf.Session() as sess1:
    sess1.run(init)
    print('rosetta matmul:', sess1.run(ir_matmul))
예제 #15
0
np.set_printoptions(suppress=True)

protocol = "Helix"
rtt.activate(protocol)

patyid = str(rtt.get_party_id())
rtt.set_backend_loglevel(0)
rtt.set_backend_logfile("/tmp/wo-men-dou-shi-hao-hai-zi.log" + patyid)

print("rtt.get_protocol_name():", rtt.get_protocol_name())

X = tf.Variable([[1., 1.], [2., 1.]])
Y = tf.Variable([[1., 3.], [1., 1.]])
z = rtt.SecureMatMul(X, Y)
zr = rtt.SecureReveal(z)

init = tf.global_variables_initializer()
with tf.Session() as sess1:
    sess1.run(init)
    print('zzzzzr:', sess1.run(zr))

rtt.set_backend_loglevel(3)
rtt.set_backend_logfile("/tmp/wo-men-dou-shi-hao-hai-zi-ma.log" + patyid)

with tf.Session() as sess1:
    sess1.run(init)
    print('zzzzzr:', sess1.run(zr))

exit(0)
예제 #16
0
def call_nn(opname, a, b=None):
    if opname in nn_fns:
        if b:
            return rtt.SecureReveal(nn_fns[opname](a, b))
        else:
            return rtt.SecureReveal(nn_fns[opname](a))
예제 #17
0
floor_expected = np.floor_divide(num_a, num_b)

a1 = X / Y
floor1 = tf.floordiv(X, Y)

a2 = X / CY
floor2 = tf.floordiv(X, CY)

# in this case, it is hard to get the correct result from big shared right!
a3 = CX / Y
floor3 = tf.floordiv(CX, Y)

a4 = CX / CY
floor4 = tf.floordiv(CX, CY)

r_a1 = rtt.SecureReveal([a1, floor1])
r_a2 = rtt.SecureReveal([a2, floor2])
r_a3 = rtt.SecureReveal([a3, floor3])
r_a4 = rtt.SecureReveal([a4, floor4])

init = tf.global_variables_initializer()
with tf.Session() as sess1:
    sess1.run(init)
    rr_a1 = sess1.run(r_a1)
    rr_a2 = sess1.run(r_a2)
    rr_a3 = sess1.run(r_a3)
    rr_a4 = sess1.run(r_a4)

    print("expected:", expected)
    print("floor expected:", floor_expected)
예제 #18
0
# 1-d
###############################
print('=================1-d=========================')
x = [1, 8, 3]
print(x)

a = tf.Variable(x, dtype=tf.float64)
aa = tf.reduce_mean(a)
a0 = tf.reduce_mean(a, axis=0)

aa_k = tf.reduce_mean(a, keepdims=True)
a0_k = tf.reduce_mean(a, axis=0, keepdims=True)

with tf.Session() as sess:
    sess.run(tf.compat.v1.global_variables_initializer())
    res_aa = sess.run(rtt.SecureReveal(aa))
    print('tf tf.reduce_mean aa:\n', res_aa)
    res_a0 = sess.run(rtt.SecureReveal(a0))
    print('tf tf.reduce_mean a0:\n', res_a0)

    print('====================================================')
    res_aa_k = sess.run(rtt.SecureReveal(aa_k))
    print('tf tf.reduce_mean aa_k:\n', res_aa_k)
    res_a0_k = sess.run(rtt.SecureReveal(a0_k))
    print('tf tf.reduce_mean a0_k:\n', res_a0_k)
print('====================================================')

###############################
# 2-d
###############################
print('=================2-d=========================')
예제 #19
0
def call_reduce(opname, a, axis=None):
    if opname in reduce_fns:
        if axis:
            return rtt.SecureReveal(reduce_fns[opname](a, axis=axis))
        else:
            return rtt.SecureReveal(reduce_fns[opname](a))
예제 #20
0
import tensorflow as tf
import latticex.rosetta as rtt

print("inputs: ", [1.0, 0.0, 0, 0, -0.0, 0.0001, -0.000001, -0.000125, -1])
inputs = tf.Variable([1.0, 0.0, 0, 0, -0.0, 0.0001, -0.000001, -0.000125, -1], name="input")
relu_prime = rtt.SecureReveal(rtt.SecureReluPrime(inputs))

init = tf.compat.v1.global_variables_initializer()
with tf.compat.v1.Session() as sess:
    sess.run(init)

    ret = sess.run(relu_prime)
    print("relu-prime: {}".format(ret))

print("ok")
print(pred_Y)

# loss
loss = tf.square(Y - pred_Y)
loss = tf.reduce_mean(loss)
print(loss)

# optimizer
train = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss)
print(train)

init = tf.global_variables_initializer()
print(init)

# ########### for test, reveal
reveal_W = rtt.SecureReveal(W)
reveal_b = rtt.SecureReveal(b)
reveal_Y = rtt.SecureReveal(pred_Y)
# ########### for test, reveal

# #############################################################
# save to csv for comparing, for debug
if mpc_player_id == 0:
    scriptname = os.path.basename(sys.argv[0]).split(".")[0]
    csvprefix = "./log/" + scriptname
    os.makedirs(csvprefix, exist_ok=True)
    csvprefix = csvprefix + "/rtt"
# #############################################################

with tf.Session() as sess:
    sess.run(init)
예제 #22
0
rtt.activate(protocol)

input0 = rtt.private_input(0, 1.234)
input1 = rtt.private_input(1, 5.432)
input2 = rtt.private_input(2, 2.222)
print('input0:', input0)
print('input1:', input1)
print('input2:', input2)

i0 = tf.Variable(input0)
i1 = tf.Variable(input1)
i2 = tf.Variable(input2)

ii = rtt.SecureAdd(i0, i1)
ii = rtt.SecureAdd(ii, i2)
ir_add = rtt.SecureReveal(ii)  # i0 + i1 + i2

init = tf.global_variables_initializer()
with tf.Session() as sess1:
    sess1.run(init)
    print('rosetta add:', sess1.run(ir_add))

ii = rtt.SecureMul(i0, i1)
ii = rtt.SecureMul(ii, i2)
ir_mul = rtt.SecureReveal(ii)  # i0 * i1 * i2

init = tf.global_variables_initializer()
with tf.Session() as sess1:
    sess1.run(init)
    print('rosetta mul:', sess1.run(ir_mul))
예제 #23
0
)
xb = tf.Variable(
    [
        [2,  20],
        [-2, -20],
        [4,  -40]
    ]
)


init = tf.compat.v1.global_variables_initializer()
sess = tf.compat.v1.Session()
sess.run(init)
print("=========================== mpc op floordiv 1")
xc = rtt.SecureFloorDiv(xa, xb)
xcc = sess.run(rtt.SecureReveal(xc))
print(xcc)
print("=========================== mpc op floordiv 2")

print("=========================== MPC op divide 1")
xc = rtt.SecureDivide(xa, xb)
xcc = sess.run(rtt.SecureReveal(xc))
print(xcc)
print("=========================== MPC op divide 2")



print("=========================== mpc op high-precision log 1")
xc = rtt.SecureHLog(xa)
xcc = sess.run(rtt.SecureReveal(xc))
print("=========================== mpc op high-precision log 2")
예제 #24
0
rtt_case = TEST_CASES[case_id]
rtt_res_1 = TEST_CASES[case_id]

cipher_var_a = tf.Variable(rtt.private_input(0, rtt_case["input"][0]))
cipher_var_b = tf.Variable(rtt.private_input(1, rtt_case["input"][1]))
cipher_var_c = cipher_var_a / cipher_var_b
cipher_var_c_1 = rtt.SecureReciprocaldiv(cipher_var_a, cipher_var_b)

init = tf.compat.v1.global_variables_initializer()
with tf.compat.v1.Session() as rtt_sess:
    rtt_sess.run(init)
    rtt_res = rtt_sess.run(cipher_var_c)
    rtt_res_1 = rtt_sess.run(cipher_var_c_1)
    # print("local cipher res:", rtt_res)
    # reveal to get the plaintext result
    rtt_res = rtt_sess.run(rtt.SecureReveal(rtt_res))
    rtt_res_1 = rtt_sess.run(rtt.SecureReveal(rtt_res_1))
    rtt_case["rtt_res"] = np.array(rtt_res, dtype=np.float)
    rtt_case["rtt_res_1"] = np.array(rtt_res_1, dtype=np.float)

    print("first case ciphertext result:---------------------")
    print("div:")
    print(rtt_case["rtt_res"])
    print("reci_div:")
    print(rtt_case["rtt_res_1"])
    print("--------------------------------------------------")

#### 2.2 second case
case_id += 1
rtt_case = TEST_CASES[case_id]
rtt_res_1 = TEST_CASES[case_id]
예제 #25
0
init = tf.compat.v1.global_variables_initializer()
sess = tf.compat.v1.Session()
sess.run(init)

# print("X:\n", sess.run(xa * 2))
###########
print("=========================== tf op sigmoid 1")
xc = tf.sigmoid(ret)
# xc = tf.nn.sigmoid(ret)
xcc = sess.run(xc)
print("=========================== tf op sigmoid 2")
print(xcc)

# print("=========================== mpc op sigmoid 1")
start = time.time()
xc = rtt.SecureReveal(tf.sigmoid(ret))
xcc = sess.run(xc)
print("secure_sigmoid cost: ", time.time() - start)
# print("=========================== mpc op sigmoid 2")
print(xcc)

# print("=========================== mpc op sigmoidV2 1")
start = time.time()
xc = rtt.SecureReveal(rtt.SecureSigmoidV2(ret))
xcc = sess.run(xc)
print("secure_sigmoid_6Pieces_Python cost: ", time.time() - start)
# print("=========================== mpc op sigmoid 2")
print(xcc)

# print("=========================== mpc op sigmoidV2 1")
start = time.time()
예제 #26
0
import tensorflow as tf
import latticex.rosetta as rtt

rtt.activate("SecureNN")
X = tf.Variable([1.0, 0.0, 0.0, 1.0], name='x')
# Y = tf.Variable([1.0, 0.0, 1.0, 0.0], name='y')
Z = tf.logical_not(X)
Z2 = tf.logical_not(tf.cast(X, tf.bool))

# try:
#     train_step = tf.train.GradientDescentOptimizer(0.01).minimize(Z)
#     print("Pass")
# except Exception:
#     print("Fail")

reveal_Z = rtt.SecureReveal(Z)
reveal_Z2 = rtt.SecureReveal(Z2)

try:
    init = tf.global_variables_initializer()
    with tf.Session() as sess:
        sess.run(init)
        print(sess.run(Z))
        print(sess.run(reveal_Z))
        print(sess.run(Z2))
        print(sess.run(reveal_Z2))

    print("Pass")
except Exception:
    print("Fail")
예제 #27
0
next_x = iter_x.get_next()
next_y = iter_y.get_next()
print("--------------------------------")
print("create get next.")
print(next_x)
print(next_y)
print("--------------------------------")

# Define matmul operation
res = tf.multiply(next_x, next_y)
print("create res=next_x * next_y")

# Start execution
try:
    with tf.Session() as sess:
        print("to run session...")
        sess.run(tf.global_variables_initializer())

        print("global initialized and to make iterator initialization....")
        sess.run([iter_x.initializer, iter_y.initializer])

        print('matmul:', sess.run(rtt.SecureReveal(res)))
    print("Pass")
except:
    print("Fail")


rtt.deactivate()
Writer = tf.summary.FileWriter("log/iter", tf.get_default_graph())
Writer.close()
예제 #28
0
def call_binary(opname, a, b, is_reveal):
    if opname in binary_fns:
        if is_reveal:
            return rtt.SecureReveal(binary_fns[opname](a, b))
        else:
            return binary_fns[opname](a, b)
loss = tf.square(Y - pred_Y)
loss = tf.reduce_mean(loss)
print(loss)

# optimizer
train = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss)
print(train)

# save
saver = tf.train.Saver(var_list=None, max_to_keep=5, name='v2')
os.makedirs("./log/ckpt" + str(mpc_player_id), exist_ok=True)

# init
init = tf.global_variables_initializer()
print(init)
reveal_Y = rtt.SecureReveal(pred_Y)

with tf.Session() as sess:
    sess.run(init)
    xW, xb = sess.run([W, b])
    print("init weight:{} \nbias:{}".format(xW, xb))

    # train
    BATCHES = math.ceil(len(real_X) / BATCH_SIZE)
    for e in range(EPOCHES):
        for i in range(BATCHES):
            bX = real_X[(i * BATCH_SIZE):(i + 1) * BATCH_SIZE]
            bY = real_Y[(i * BATCH_SIZE):(i + 1) * BATCH_SIZE]
            sess.run(train, feed_dict={X: bX, Y: bY})

            j = e * BATCHES + i
예제 #30
0
def call_unary(opname, b):
    if opname in unary_fns:
        return rtt.SecureReveal(unary_fns[opname](b))