You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tf.batch_matmul gives "Attempting to capture an EagerTensor without building a function" #755
NDArray ta = new NDArray(new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, new Shape(5, 2));
NDArray tb = new NDArray(new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, new Shape(2, 5));
Tensor result2 = tf.batch_matmul(ta, tb); // this will throw an exception
The exception thrown is:
"Attempting to capture an EagerTensor without building a function." | Tensorflow.RuntimeError
stacktrace:
at Tensorflow.ops.convert_to_tensor(Object value, TF_DataType dtype, String name, Boolean as_ref, TF_DataType preferred_dtype, Context ctx)
at Tensorflow.OpDefLibrary.<>c__DisplayClass1_0.<_apply_op_helper>b__0(NameScope scope)
at Tensorflow.Binding.tf_with[TIn,TOut](TIn py, Func`2 action)
at Tensorflow.OpDefLibrary._apply_op_helper(String op_type_name, String name, Dictionary`2 keywords)
at Tensorflow.OpDefLibrary._apply_op_helper(String op_type_name, String name, Object args)
at Tensorflow.gen_math_ops.batch_mat_mul(Tensor x, Tensor y, Boolean adj_x, Boolean adj_y, String name)
at Tensorflow.tensorflow.batch_matmul(Tensor x, Tensor y)
at VPG.TF.Test2.LinearRegression2() in C:\somepath\TF\Test2.cs:line 240
at VPG.Program.Main(String[] args) in C:\somepath\Program.cs:line 14
Now, if I run it first in a try-catch statement, the second time it is called it works:
NDArray ta = new NDArray(new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, new Shape(5, 2));
NDArray tb = new NDArray(new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, new Shape(2, 5));
try
{
Tensor result = tf.batch_matmul(ta, tb); // this will throw an exception
}
catch
{
}
Tensor result2 = tf.batch_matmul(ta, tb); // this works as expected
I'm new to this library, but so far I don't have this issue with other method calls. For example, I can run tf.matmul without an exception here.
I thought perhaps I misunderstood how to set things up, but then I still get this error if it is run this within a using for a GradientTape, or after I run a different function (such as a simple multiplication or tf.matmul). Any help you can offer would be much appreciated.
Activity
Oceania2018 commentedon Feb 19, 2021
@LeeReidCSIRO Will be fixed for next release.

fix tf.batch_matmul #755
LeeReid1 commentedon Feb 23, 2021
Many thanks