Created
May 13, 2020 12:03
-
-
Save solaris33/11c9aa565ef6abe3b14ff26559b3135a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
in_a = tf.placeholder(dtype=tf.float32, shape=(2)) | |
in_b = tf.placeholder(dtype=tf.float32, shape=(2)) | |
def forward(x): | |
with tf.variable_scope("matmul", reuse=tf.AUTO_REUSE): | |
W = tf.get_variable("W", initializer=tf.ones(shape=(2,2)), | |
regularizer=tf.contrib.layers.l2_regularizer(0.04)) | |
b = tf.get_variable("b", initializer=tf.zeros(shape=(2))) | |
return W * x + b | |
out_a = forward(in_a) | |
out_b = forward(in_b) | |
reg_loss = tf.losses.get_regularization_loss(scope="matmul") | |
with tf.Session() as sess: | |
sess.run(tf.global_variables_initializer()) | |
outs = sess.run([out_a, out_b, reg_loss], feed_dict={in_a: [1, 0], in_b: [0, 1]}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment