Пример #1
0
 def getParams(self):
     network_params = ll.get_all_params(self.conv_back, trainable=True)
     for p in ll.get_all_params(self.back_nn):
         network_params.append(p)
     for p in ll.get_all_params(self.cell):
         network_params.append(p)
     for p in ll.get_all_params(self.p_out):
         network_params.append(p)
     return network_params
Пример #2
0
def l2(layer, include_biases=False):
    if include_biases:
        all_params = layers.get_all_params(layer)
    else:
        all_params = layers.get_all_non_bias_params(layer)
    
    return sum(T.sum(p**2) for p in all_params)


# TODO: sparsity regularization
Пример #3
0
 def get_params(self):
     network_params = ll.get_all_params(self.conv_layer, trainable=True)
     for p in ll.get_all_params(self.gru_layer):
         network_params.append(p)
     for p in ll.get_all_params(self.p_layer):
         network_params.append(p)
     if self.forw_backw:
         for p in ll.get_all_params(self.back_layer)[-10:]:
             network_params.append(p)
     if self.n_genparams:
         for p in ll.get_all_params(self.gen_mu_layer):
             network_params.append(p)
         for p in ll.get_all_params(self.gen_sig_layer):
             network_params.append(p)
     return network_params
Пример #4
0
    eve_conv_in = eve_hid2.output.reshape(
        (batch_size, 1, comm_len + key_len, 1))
    eve_conv = StandardConvSetup(eve_conv_in, 'eve')
    eve_msg = eve_conv.output.reshape((batch_size, msg_len))

# Eve's loss function is the L1 norm between true and recovered msg
decrypt_err_eve = T.mean(T.abs_(msg_in - eve_msg))

# Bob's loss function is the L1 norm between true and recovered
decrypt_err_bob = T.mean(T.abs_(msg_in - bob_msg))
# plus (N/2 - decrypt_err_eve) ** 2 / (N / 2) ** 2
# --> Bob wants Eve to do only as good as random guessing
loss_bob = decrypt_err_bob + (1. - decrypt_err_eve)**2.

# Get all the parameters for Bob and Alice, make updates, train and pred funcs
params = {'bob': get_all_params([bob_conv, bob_hid, alice_conv, alice_hid])}
updates = {'bob': adam(loss_bob, params['bob'])}
err_fn = {
    'bob': theano.function(inputs=[msg_in, key], outputs=decrypt_err_bob)
}
train_fn = {
    'bob':
    theano.function(inputs=[msg_in, key],
                    outputs=loss_bob,
                    updates=updates['bob'])
}
pred_fn = {'bob': theano.function(inputs=[msg_in, key], outputs=bob_msg)}

# Get all the parameters for Eve, make updates, train and pred funcs
params['eve'] = get_all_params([eve_hid1, eve_hid2, eve_conv])
updates['eve'] = adam(decrypt_err_eve, params['eve'])
Пример #5
0
 def get_params(self):
     network_params = ll.get_all_params(self.NN, trainable=True)
     return network_params