Created
October 17, 2016 12:08
-
-
Save daschl/ef32fdb5197f7beff02923154253fd22 to your computer and use it in GitHub Desktop.
input param not working?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
a = tf.placeholder(tf.int32, name = 'a') | |
b = tf.placeholder(tf.int32, name = 'b') | |
add = tf.add(a, b, name = 'add') | |
tf.initialize_variables(tf.all_variables(), name = 'init') | |
definition = tf.Session().graph_def | |
tf.train.write_graph(definition, 'models', 'arithmetic.pb', as_text=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate tensorflow; | |
use tensorflow::{Session, SessionOptions, Step, Tensor, DataType}; | |
use std::fs::File; | |
use std::io::Read; | |
fn main() { | |
let filename = "examples/models/arithmetic.pb"; | |
let mut a = Tensor::<i32>::new(&[1]); | |
a[0] = 3; | |
let mut b = Tensor::<i32>::new(&[1]); | |
b[0] = 5; | |
// Initialize Session and load the model. | |
let mut session = Session::new(&SessionOptions::new()).unwrap(); | |
let mut model = Vec::new(); | |
File::open(filename).unwrap().read_to_end(&mut model).unwrap(); | |
session.extend_graph(&model).unwrap(); | |
// Set A and B values | |
let mut init_step = Step::new(); | |
init_step.add_input("a", &a).unwrap(); | |
init_step.add_input("b", &b).unwrap(); | |
init_step.add_target("init").unwrap(); | |
session.run(&mut init_step).unwrap(); | |
// Ask for the output and run | |
let mut out_step = Step::new(); | |
let add = out_step.request_output("add").unwrap(); | |
session.run(&mut out_step).unwrap(); | |
// Print the result | |
let result: i32 = out_step.take_output(add).unwrap().data()[0]; | |
println!("{:?}", result); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: {inner:0x7f8b4a2011f0, InvalidArgument: You must feed a value for placeholder tensor 'a' with dtype int32 | |
[[Node: a = Placeholder[dtype=DT_INT32, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]}', ../src/libcore/result.rs:788 | |
stack backtrace: | |
1: 0x1019fdb59 - std::sys::backtrace::tracing::imp::write::h00e948915d1e4c72 | |
2: 0x1019ffc40 - std::panicking::default_hook::_{{closure}}::h7b8a142818383fb8 | |
3: 0x1019ff0e0 - std::panicking::default_hook::h41cf296f654245d7 | |
4: 0x1019ff6a6 - std::panicking::rust_panic_with_hook::h4cbd7ca63ce1aee9 | |
5: 0x1019ff4f4 - std::panicking::begin_panic::h93672d0313d5e8e9 | |
6: 0x1019ff452 - std::panicking::begin_panic_fmt::hd0daa02942245d81 | |
7: 0x1019ff3b7 - rust_begin_unwind | |
8: 0x101a258a0 - core::panicking::panic_fmt::hbfc935564d134c1b | |
9: 0x1019eb4bc - core::result::unwrap_failed::hb73f4a5c3aa2e2c8 | |
10: 0x1019e8f0e - _<core..result..Result<T, E>>::unwrap::hbc6e44d6fbbca03a | |
11: 0x1019ee10b - arithmetic::main::h312dd8515f8f6ba1 | |
12: 0x101a0022a - __rust_maybe_catch_panic | |
13: 0x1019febae - std::rt::lang_start::h53bf99b0829cc03c | |
14: 0x1019ee469 - main | |
error: Process didn't exit successfully: `target/debug/examples/arithmetic` (exit code: 101) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment