diff --git a/src/TensorFlowNET.Core/Graphs/Graph.Operation.cs b/src/TensorFlowNET.Core/Graphs/Graph.Operation.cs index 3cda8074..75f46a59 100644 --- a/src/TensorFlowNET.Core/Graphs/Graph.Operation.cs +++ b/src/TensorFlowNET.Core/Graphs/Graph.Operation.cs @@ -59,14 +59,28 @@ namespace Tensorflow return return_opers; } + /// + /// Get operation with given + /// + /// When is not found current graph. + /// When tf.get_default_graph() is not current graph. + /// + /// graph.GetOperationByName("CustomInputName"); + /// public Operation OperationByName(string operName) { + if (operName == null) + throw new ArgumentNullException(nameof(operName)); + var handle = c_api.TF_GraphOperationByName(_handle, operName); + if (handle == IntPtr.Zero) + throw new ValueError($"Could not find operation \"{operName}\" inside graph \"{_graph_key}\"."); + var defaultKey = tf.get_default_graph().graph_key; if (graph_key != defaultKey) { //Console.WriteLine($"Current graph is not default graph."); - throw new ValueError($"Current graph is not default graph. Default Graph Key: {defaultKey}, Current Graph Key: {graph_key}"); + throw new RuntimeError($"Current graph is not default graph. Default Graph Key: {defaultKey}, Current Graph Key: {graph_key}"); } return new Operation(handle, g: this);