pub fn run_get_many<'a>(
        &mut self,
        inputs: Vec<(&'a str, Tensor)>,
        targets: Vec<&'a str>,
    ) -> Result<HashMap<&'a str, Vec<Tensor>>> {
        let mut input_pairs: Vec<(&str, TensorHolder)> = Vec::new();
        let mut excluded = HashSet::new();

        for (name, mat) in inputs {
            input_pairs.push((name, mat.into()));
            excluded.insert(name.to_string());
        }

        let mut step = SessionRunArgs::new();
        for t in &input_pairs {
            let op = self.graph.operation_by_name_required(t.0)?;
            match t.1 {
                TensorHolder::Bool(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::U8(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::U16(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::I8(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::I16(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::I32(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::I64(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::F16(_) => unimplemented!(),
                TensorHolder::F32(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::F64(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::String(ref it) => step.add_feed(&op, 0, &it),
            }
        }

        let mut tokens = HashMap::new();
        trace!("Targets: {:?}", targets);
        for name in targets {
            if excluded.contains(name) {
                continue;
            }

            if let Some(operation) =
                self.graph.operation_by_name(name).map_err(|e| format!("TfError: {:?}", e))?
            {
                // switch only computes one of its outputs. tf explodes during
                // the call to run() if we registers them
                if operation.op_type()? == "Switch" {
                    continue;
                }

                // this one pretends to have 5 outputs, but has only one
                if operation.op_type()? == "FusedBatchNorm" {
                    continue;
                }

                let outputs = (0..operation.num_outputs())
                    .map(|ix| step.request_fetch(&operation, ix as i32))
                    .collect::<Vec<_>>();

                tokens.insert(name, outputs);
            }
        }
        trace!("Generated all output tokens");
        trace!("{:?}", tokens);

        // Execute the graph using tensorflow.
        self.session.run(&mut step)?;
        trace!("Tensorflow ran succesfully");

        // Return the output for every node.
        let mut outputs = HashMap::new();
        for (name, tokens) in tokens {
            let tensors = tokens
                .iter()
                .enumerate()
                .map(|(ix, tok)| {
                    let output_type =
                        &self.graph.operation_by_name_required(&name)?.output_type(ix);
                    convert_output(&mut step, output_type, *tok)
                })
                .collect::<Result<Vec<_>>>()?;
            outputs.insert(name, tensors);
        }

        Ok(outputs)
    }
/// Executes the graph in one batch, and returns the output for every node but the inputs.
Executes the graph in one batch, and returns the output for every node but the inputs.
Executes the graph in one batch and returns the output for every node but the inputs .
pub fn run_get_many<'a>(
        &mut self,
        inputs: Vec<(&'a str, Tensor)>,
        targets: Vec<&'a str>,
    ) -> Result<HashMap<&'a str, Vec<Tensor>>> {
        let mut input_pairs: Vec<(&str, TensorHolder)> = Vec::new();
        let mut excluded = HashSet::new();
        for (name, mat) in inputs {
            input_pairs.push((name, mat.into()));
            excluded.insert(name.to_string());
        }
        let mut step = SessionRunArgs::new();
        for t in &input_pairs {
            let op = self.graph.operation_by_name_required(t.0)?;
            match t.1 {
                TensorHolder::Bool(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::U8(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::U16(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::I8(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::I16(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::I32(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::I64(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::F16(_) => unimplemented!(),
                TensorHolder::F32(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::F64(ref it) => step.add_feed(&op, 0, &it),
                TensorHolder::String(ref it) => step.add_feed(&op, 0, &it),
            }
        }
        let mut tokens = HashMap::new();
        trace!("Targets: {:?}", targets);
        for name in targets {
            if excluded.contains(name) {
                continue;
            }
            if let Some(operation) =
                self.graph.operation_by_name(name).map_err(|e| format!("TfError: {:?}", e))?
            {
                // switch only computes one of its outputs. tf explodes during
                // the call to run() if we registers them
                if operation.op_type()? == "Switch" {
                    continue;
                }
                // this one pretends to have 5 outputs, but has only one
                if operation.op_type()? == "FusedBatchNorm" {
                    continue;
                }
                let outputs = (0..operation.num_outputs())
                    .map(|ix| step.request_fetch(&operation, ix as i32))
                    .collect::<Vec<_>>();
                tokens.insert(name, outputs);
            }
        }
        trace!("Generated all output tokens");
        trace!("{:?}", tokens);
        // Execute the graph using tensorflow.
        self.session.run(&mut step)?;
        trace!("Tensorflow ran succesfully");
        // Return the output for every node.
        let mut outputs = HashMap::new();
        for (name, tokens) in tokens {
            let tensors = tokens
                .iter()
                .enumerate()
                .map(|(ix, tok)| {
                    let output_type =
                        &self.graph.operation_by_name_required(&name)?.output_type(ix);
                    convert_output(&mut step, output_type, *tok)
                })
                .collect::<Result<Vec<_>>>()?;
            outputs.insert(name, tensors);
        }
        Ok(outputs)
    }
pub fn run_get_many < ' a > ( & mut self , inputs : Vec < ( & ' a str , Tensor ) > , targets : Vec < & ' a str > , ) -> Result < HashMap < & ' a str , Vec < Tensor > > > { let mut input_pairs : Vec < ( & str , TensorHolder ) > = Vec :: new ( ) ; let mut excluded = HashSet :: new ( ) ; for ( name , mat ) in inputs { input_pairs . push ( ( name , mat . into ( ) ) ) ; excluded . insert ( name . to_string ( ) ) ; } let mut step = SessionRunArgs :: new ( ) ; for t in & input_pairs { let op = self . graph . operation_by_name_required ( t . 0 ) ? ; match t . 1 { TensorHolder :: Bool ( ref it ) => step . add_feed ( & op , 0 , & it ) , TensorHolder :: U8 ( ref it ) => step . add_feed ( & op , 0 , & it ) , TensorHolder :: U16 ( ref it ) => step . add_feed ( & op , 0 , & it ) , TensorHolder :: I8 ( ref it ) => step . add_feed ( & op , 0 , & it ) , TensorHolder :: I16 ( ref it ) => step . add_feed ( & op , 0 , & it ) , TensorHolder :: I32 ( ref it ) => step . add_feed ( & op , 0 , & it ) , TensorHolder :: I64 ( ref it ) => step . add_feed ( & op , 0 , & it ) , TensorHolder :: F16 ( _ ) => unimplemented ! ( ) , TensorHolder :: F32 ( ref it ) => step . add_feed ( & op , 0 , & it ) , TensorHolder :: F64 ( ref it ) => step . add_feed ( & op , 0 , & it ) , TensorHolder :: String ( ref it ) => step . add_feed ( & op , 0 , & it ) , } } let mut tokens = HashMap :: new ( ) ; trace ! ( " " targets ) ; for name in targets { if excluded . contains ( name ) { continue ; } if let Some ( operation ) = self . graph . operation_by_name ( name ) . map_err ( | e | format ! ( " " e ) ) ? { // switch only computes one of its outputs. tf explodes during // the call to run() if we registers them if operation . op_type ( ) ? == " " { continue ; } // this one pretends to have 5 outputs, but has only one if operation . op_type ( ) ? == " " { continue ; } let outputs = ( 0 .. operation . num_outputs ( ) ) . map ( | ix | step . request_fetch ( & operation , ix as i32 ) ) . collect :: < Vec < _ > > ( ) ; tokens . insert ( name , outputs ) ; } } trace ! ( " " ) ; trace ! ( " " tokens ) ; // Execute the graph using tensorflow. self . session . run ( & mut step ) ? ; trace ! ( " " ) ; // Return the output for every node. let mut outputs = HashMap :: new ( ) ; for ( name , tokens ) in tokens { let tensors = tokens . iter ( ) . enumerate ( ) . map ( | ( ix , tok ) | { let output_type = & self . graph . operation_by_name_required ( & name ) ? . output_type ( ix ) ; convert_output ( & mut step , output_type , * tok ) } ) . collect :: < Result < Vec < _ > > > ( ) ? ; outputs . insert ( name , tensors ) ; } Ok ( outputs ) }
Executes the graph in one batch, and returns the output for every node but the inputs.
Executes the graph in one batch and returns the output for every node but the inputs .
&mut self
inputs
Vec<(&'a str, Tensor)>
targets
Vec<&'a str>
&mut self
inputs
Vec<(&'a str, Tensor)>
targets
Vec<&'a str>