Skip to content

Concat get_gradient_function not implemented.  #242

Closed

Description

@Rleahy

Attempting to use the minimize function of a gradient decent optimizer on a graph that includes a concat operation throws a Not Implemented error.

Error seems to originate from ops.gradient_function_mapping.cs

Can this be implemented?

Activity

  1. self-assigned this
    on May 8, 2019
  2. added
    enhancement
    on May 8, 2019
  3. ttoowa commented on May 10, 2019

    @ttoowa

    I have same message.
    System.NotImplementedException: 'get_gradient_function Exp'
    위치: Tensorflow.ops.<>c.<get_gradient_function>b__0_0(Operation oper, Tensor[] out_grads)
    위치: Tensorflow.gradients_impl.<>c__DisplayClass1_3.<_GradientsHelper>b__5(NameScope scope1)
    위치: Tensorflow.Python.with[T](T py, Action1 action) 위치: Tensorflow.gradients_impl.<>c__DisplayClass1_0.<_GradientsHelper>b__0(NameScope scope) 위치: Tensorflow.Python.with[T](T py, Action1 action)

  4. Oceania2018 commented on May 11, 2019

    @Oceania2018
    Member

    @Bgoon Could your provide some example code? I can't validate if the implementation is correct. Or you can test by your self.

  5. Oceania2018 commented on May 11, 2019

    @Oceania2018
    Member

    @Rleahy I need to know the name of Gradient. Please copy the exception message like what @Bgoon did. Thanks.

  6. Oceania2018 commented on May 11, 2019

    @Oceania2018
    Member

    @Bgoon Added Exp gradient.

  7. Rleahy commented on May 13, 2019

    @Rleahy
    Author

    @Oceania2018

    Error: System.NotImplementedException

    Message: "get_gradient_function ConcatV2"

    StackTrace: " at Tensorflow.ops.<>c.<get_gradient_function>b__0_0(Operation oper, Tensor[] out_grads)\n at Tensorflow.gradients_impl.<>c__DisplayClass1_3.<_GradientsHelper>b__5(NameScope scope1)\n at Tensorflow.Python.with[T](T py, Action1 action)\n at Tensorflow.gradients_impl.<>c__DisplayClass1_0.<_GradientsHelper>b__0(NameScope scope)\n at Tensorflow.Python.with[T](T py, Action1 action)\n at Tensorflow.gradients_impl._GradientsHelper(Tensor[] ys, Tensor[] xs, Tensor[] grad_ys, String name, Boolean colocate_gradients_with_ops, Boolean gate_gradients, Int32 aggregation_method, Tensor[] stop_gradients, Graph src_graph)\n at Tensorflow.Optimizer.compute_gradients(Tensor loss, List1 var_list, Nullable1 aggregation_method, GateGradientType gate_gradients, Boolean colocate_gradients_with_ops, Tensor[] grad_loss)\n at Tensorflow.Optimizer.minimize(Tensor loss, RefVariable global_step, List1 var_list, GateGradientType gate_gradients, Nullable1 aggregation_method, Boolean colocate_gradients_with_ops, String name, Tensor grad_loss)\n at DeepLearningNetwork.TrainNetwork() in /BeliefRefinery/classes/StoredData/DeepLearningNetwork.cs:line 94\n at TrainNeuralNetwork.CalculateAttribute() in /BeliefRefinery/classes/Attributes/TrainNeuralNetwork.cs:line 21\n at CalculatedAttribute.TryCalculateAttribute() in /BeliefRefinery/classes/framework/CalculatedAttribute.cs:line 149"

  8. ttoowa commented on May 13, 2019

    @ttoowa

    This is my test code.

    private void TrainXor()
            {
                const float LearningLate = 0.01f;
                const int Epochs = 1000;
                const int DisplayStep = 10;
                
                float[][] train_X = new float[][] {
                    new [] {0f, 0f },
                    new [] {1f, 0f },
                    new [] {0f, 1f },
                    new [] {1f, 1f },
                };
                float[] train_Y = new float[]
                {
                    0f,
                    1f,
                    1f,
                    0f,
                };
    
                var X = tf.placeholder(TF_DataType.TF_FLOAT);
                var Y = tf.placeholder(TF_DataType.TF_FLOAT);
    
                var W = tf.Variable(tf.random_uniform(new[] { 1, train_X.Length }, -1f, 1f), name:"weight");
                var B = tf.Variable(-0.73f, name: "bias");
    
                var mul = tf.multiply(X, W);
                var pred = tf.add(mul, B);
    
                var h = tf.matmul(W, X);
                var hypothesis = tf.divide(tf.constant(1f), tf.constant(1f) + tf.exp(-h));
    
                var cost = -tf.reduce_mean(Y * tf.log(hypothesis) + (1 - Y) * tf.log(1 - hypothesis));
    
                var optimizer = tf.train.GradientDescentOptimizer(LearningLate).minimize(cost);
                var init = tf.global_variables_initializer();
    
                with<Session>(tf.Session(), sess =>
                {
                    sess.run(init);
    
                    for (int step = 0; step < Epochs; ++step)
                    {
                        sess.run(optimizer, new FeedItem(train_X, train_Y));
                        if(step % DisplayStep == 0)
                        {
                            Console.WriteLine($"{step} step, {sess.run(cost, new FeedItem(train_X, train_Y))} -> {sess.run(W)}");
                        }
                        var correct_pred = tf.equal(tf.floor(hypothesis + tf.constant(0.5f)), Y);
    
                        var accuracy = tf.reduce_mean(tf.cast(correct_pred, TF_DataType.TF_FLOAT));
                        var param = new[] { hypothesis, tf.floor(hypothesis+tf.constant(0.5f)), correct_pred, accuracy };
                        var result = sess.run(param, new[] { new FeedItem(train_X, train_Y) });
    
                        Console.WriteLine($"Accuracy = {accuracy.eval(new FeedItem(train_X, train_Y))}");
                    }
                });
            }
  9. Oceania2018 commented on May 13, 2019

    @Oceania2018
    Member

    @Rleahy Added ConcatV2 gradient operation.

  10. Oceania2018 commented on May 13, 2019

    @Oceania2018
    Member

    New version v0.7.1 contains those updates.

  11. Oceania2018 commented on May 14, 2019

    @Oceania2018
    Member

    I'll close this issue if no any feedback in 3 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions