TensorFlow.NET icon indicating copy to clipboard operation
TensorFlow.NET copied to clipboard

Scope is totally ignored.

Open Tomazzzzz opened this issue 3 years ago • 3 comments

The scope in graph is totally ignored when I try to get variables defined in a scope.

The scope input in following methods are ignored as a result there is now way to get variables per scope

//Graph.cs
public partial class Graph 	 
{
	public object get_collection(string name, string scope = null)..
	public List<T> get_collection<T>(string name, string scope = null)	 ..
}

//tf.variable.cs
public partial class tensorflow
{
	 public IVariableV1[] trainable_variables(string scope = null)=> (variables.trainable_variables() as List<IVariableV1>).ToArray();
}

Please implement the use of scope or provide alternative. THNX

Tomazzzzz avatar Jan 14 '23 07:01 Tomazzzzz

Hello, could you please provide some python code examples of the scope you tend to use?

In tensorflow python, there are many usages of with xxx as xx to declare a scope (or context). I couldn't see which scope to implement.

SanftMonster avatar Feb 08 '23 05:02 SanftMonster

Hello,

The code bellow, gets same tensors from 2 networks to update values from DQNetwork to TargetNetwork.

def update_target_graph():
    
    # Get the parameters of our DQNNetwork
    from_vars = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, "DQNetwork")
    
    # Get the parameters of our Target_network
    to_vars = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, "TargetNetwork")

    op_holder = []
    
    # Update our target_network parameters with DQNNetwork parameters
    for from_var,to_var in zip(from_vars,to_vars):
        op_holder.append(to_var.assign(from_var))
    return op_holder

THNX

Tomazzzzz avatar Feb 08 '23 12:02 Tomazzzzz

@Oceania2018 What do you think of this feature? I'd like to try to implement it if there is no conflict with the current framework.

SanftMonster avatar Feb 08 '23 17:02 SanftMonster