Skip to content

Commit a7f9599

Browse files
committed
Fix RunInAutoMode.
1 parent 77e6bb5 commit a7f9599

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/TensorFlowNET.Core/Contexts/Context.AutoMode.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,25 @@ public T RunInAutoMode<T>(Func<T> graphAction, Func<T> eagerAction, params objec
3232
{
3333
if (tf.Context.has_graph_arg(args))
3434
{
35-
return graphAction();
35+
if (executing_eagerly())
36+
{
37+
graph_mode();
38+
var result = graphAction();
39+
restore_mode();
40+
return result;
41+
}
42+
else
43+
{
44+
return graphAction();
45+
}
3646
}
3747
else
3848
{
39-
try
49+
if (tf.Context.executing_eagerly())
4050
{
4151
return eagerAction();
4252
}
43-
catch (InvalidArgumentError ex)
44-
{
45-
throw ex;
46-
}
47-
catch (Exception ex)
53+
else
4854
{
4955
return graphAction();
5056
}

src/TensorFlowNET.Core/Variables/BaseResourceVariable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void variable_accessed(BaseResourceVariable variable)
162162
/// read the value only after some condition is true.
163163
/// </summary>
164164
/// <returns></returns>
165-
Tensor read_value()
165+
protected Tensor read_value()
166166
=> tf_with(ops.name_scope("Read"), delegate
167167
{
168168
var value = _read_variable_op();

src/TensorFlowNET.Core/Variables/ResourceVariable.Implicit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public Tensor _TensorConversionFunction(TF_DataType dtype = TF_DataType.DtInvali
3636
if (as_ref)
3737
return handle;
3838
else
39-
return AsTensor();
39+
return GraphElement ?? read_value();
4040
}
4141
}
4242
}

0 commit comments

Comments
 (0)