java icon indicating copy to clipboard operation
java copied to clipboard

How to represent the [variable_scope] and [get_variable] in tensorflow java ?

Open mullerhai opened this issue 3 years ago • 2 comments

HI : write the tensorflow code in python ,we always use with the variable_scope and get_variable method , like this

        with tf.compat.v1.variable_scope('Qifficulty'):
            question_difficulty_weights = tf.compat.v1.get_variable('weights', [q.get_shape()[-1], 1],
                                                          initializer= tf.initializers.glorot_uniform(seed=0))
                                                          # layers.xavier_initializer(seeed=0))
            question_difficulty_biases = tf.compat.v1.get_variable('biases', [1],
                                                         initializer=tf.compat.v1.zeros_initializer())
            question_difficulty = tf.nn.tanh(tf.matmul(q, question_difficulty_weights) + question_difficulty_biases)
 but in  java ,we can not use  with key word , and   I also can not  find [variable_scope] and [get_variable]  two apis.  

I just want to know How to represent the [variable_scope] and [get_variable] in tensorflow java ,could we give me a damo about these?

mullerhai avatar Mar 14 '22 06:03 mullerhai

We don't have an equivalent of variable scope, though you can name the scope which has a similar effect, but if you have a graph ops instance you can call variable() and pass in an org.tensorflow.framework.initializers instance or do it by hand (e.g. https://github.com/tensorflow/java-models/blob/master/tensorflow-examples/src/main/java/org/tensorflow/model/examples/cnn/lenet/CnnMnist.java#L103).

Craigacp avatar Mar 16 '22 01:03 Craigacp

We don't have an equivalent of variable scope, though you can name the scope which has a similar effect, but if you have a graph ops instance you can call variable() and pass in an org.tensorflow.framework.initializers instance or do it by hand (e.g. https://github.com/tensorflow/java-models/blob/master/tensorflow-examples/src/main/java/org/tensorflow/model/examples/cnn/lenet/CnnMnist.java#L103).

good example project, we need more , thx

mullerhai avatar Mar 16 '22 05:03 mullerhai