Struct tensorflow::SessionRunArgs
source · pub struct SessionRunArgs<'l> { /* private fields */ }
Expand description
Manages the inputs and outputs for a single execution of a graph.
Typical usage involves creating an instance of this struct,
adding some inputs to it, requesting some outputs, passing it to Session::run
and then taking the outputs out of it.
Example:
let mut args = SessionRunArgs::new();
args.add_feed(&op1, 0, &tensor1);
args.add_feed(&op2, 0, &tensor2);
let result_token = args.request_fetch(&op3, 0);
session.run(&mut args)?;
let result_tensor = args.fetch(result_token)?;
See examples/addition.rs for a more concrete example.
Implementations§
source§impl<'l> SessionRunArgs<'l>
impl<'l> SessionRunArgs<'l>
sourcepub fn add_feed<T: TensorType>(
&mut self,
operation: &Operation,
index: c_int,
tensor: &'l Tensor<T>
)
pub fn add_feed<T: TensorType>( &mut self, operation: &Operation, index: c_int, tensor: &'l Tensor<T> )
Adds an input to be fed to the graph. The index selects which output of the operation to feed. For most operations, there is only one output, so the index should be 0.
sourcepub fn add_input<T: TensorType>(
&mut self,
operation: &Operation,
index: c_int,
tensor: &'l Tensor<T>
)
👎Deprecated since 0.10.0: Use add_feed instead.
pub fn add_input<T: TensorType>( &mut self, operation: &Operation, index: c_int, tensor: &'l Tensor<T> )
Deprecated alias for add_feed.
sourcepub fn request_fetch(
&mut self,
operation: &Operation,
index: c_int
) -> FetchToken
pub fn request_fetch( &mut self, operation: &Operation, index: c_int ) -> FetchToken
Requests that an output is fetched from the graph after running this step. The index selects which output of the operation to return. For most operations, there is only one output, so the index should be 0. Returns a token that you can then use to fetch this output from the args after running it.
sourcepub fn request_output(
&mut self,
operation: &Operation,
index: c_int
) -> OutputToken
👎Deprecated since 0.10.0: Use request_fetch instead.
pub fn request_output( &mut self, operation: &Operation, index: c_int ) -> OutputToken
Deprecated alias for request_fetch.
sourcepub fn fetch<T: TensorType>(&mut self, token: FetchToken) -> Result<Tensor<T>>
pub fn fetch<T: TensorType>(&mut self, token: FetchToken) -> Result<Tensor<T>>
Extracts a tensor output given a token. A given token can only be
extracted once per Session::run
. Returns an error if the token is
invalid, output is unavailable or the requested type does not match the
type of the actual tensor.
sourcepub fn take_output<T: TensorType>(
&mut self,
token: OutputToken
) -> Result<Tensor<T>>
👎Deprecated since 0.10.0: Use fetch instead.
pub fn take_output<T: TensorType>( &mut self, token: OutputToken ) -> Result<Tensor<T>>
Deprecated alias for fetch.
sourcepub fn add_target(&mut self, operation: &Operation)
pub fn add_target(&mut self, operation: &Operation)
Adds a target operation to be executed when running the graph.
sourcepub fn output_data_type(&self, output_idx: usize) -> Option<DataType>
pub fn output_data_type(&self, output_idx: usize) -> Option<DataType>
Retuns the type of the tensor given an index.
Returns None
if the index is out of range or the output is not yet available.
sourcepub fn set_run_options(&mut self, run_options: &[u8])
pub fn set_run_options(&mut self, run_options: &[u8])
Sets the RunOptions
. run_options
is a serialized RunOptions
proto.
sourcepub fn get_run_options(&self) -> Option<&[u8]>
pub fn get_run_options(&self) -> Option<&[u8]>
Returns the serialized RunOptions
proto
Returns none if RunOption
are not set.
sourcepub fn get_metadata(&mut self) -> Option<&[u8]>
pub fn get_metadata(&mut self) -> Option<&[u8]>
Returns the serialized RunMetadata
proto
Returns none if self::set_request_metadata
is not set to true.
sourcepub fn set_request_metadata(&mut self, request: bool)
pub fn set_request_metadata(&mut self, request: bool)
Requests run_metadata
. The serialized RunMetadata
proto
can be retrieved via self::get_metadata
after calling Session::run
.
sourcepub fn is_request_metadata(&self) -> bool
pub fn is_request_metadata(&self) -> bool
Returns whether RunMetadata
should be stored.