Last active
August 3, 2018 13:54
-
-
Save hccho2/b3d6698dd2a1e8434d23ddd493801a20 to your computer and use it in GitHub Desktop.
This file contains 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
def get_scope_name(scope_name,base_name,mod=1): | |
if scope_name =='': | |
scope_name = base_name | |
else: scope_name = scope_name + '/' + base_name | |
all_vars = tf.global_variables() | |
n = len([var for var in all_vars if var.name.startswith(scope_name)]) | |
if n==0: | |
return base_name | |
else: | |
return base_name + '_' + str(n//mod) | |
def my_layer(input,depth): | |
base_name = 'my_layer' | |
scope_name = get_scope_name(tf.get_variable_scope().name,base_name,mod=2) | |
with tf.variable_scope(scope_name): | |
scale = tf.get_variable('scale', [depth]) | |
offset = tf.get_variable('offset', [depth]) | |
return scale*input + offset | |
x = tf.placeholder(tf.float32,[None,16,16,3]) | |
with tf.variable_scope("AA"): | |
y1 = my_layer(x,3) | |
y2 = my_layer(x,3) | |
with tf.variable_scope("BB"): | |
w1 = my_layer(x,3) | |
w2 = my_layer(x,3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment