Inputs and tensors appear to be correct - now need to get data/dims

This commit is contained in:
Brandon Thomas committed 2019-12-11 02:42:33 -05:00
1 parent dd9362352e
commit 15570be82d
1 file changed
+76 -4
+76 -4
View File
@@ -2,12 +2,22 @@ extern crate tensorflow;
pub mod model;
use tensorflow::Graph;
use tensorflow::Session;
use tensorflow::SessionOptions;
use tensorflow::{
SessionOptions,
Session,
Graph,
Tensor,
SessionRunArgs
};
use model::print_tensorfow_version;
const INPUT_NAME : &'static str = "inputs";
const INPUT_LENGTHS_NAME : &'static str = "inputs_lengths";
// Tensor("model/griffinlim/Squeeze:0", shape=(?,), dtype=float32)
const OUTPUT_NAME : &'static str = "model/griffinlim/Squeeze";
/**
* To save:
print('Saving model...')
@@ -23,6 +33,11 @@ use model::print_tensorfow_version;
)
builder.save()
# Save the model text labels to dereference
definition = self.session.graph_def
directory = 'saved_model_labels'
tf.train.write_graph(definition, directory, 'model_labels.pb', as_text=True)
*/
pub fn main() {
println!("Tacotron");
@@ -38,5 +53,62 @@ pub fn main() {
dir_name,
).expect("Should load");
println!("Loaded!");
println!("Model Loaded!");
let mut input = Tensor::new(&[1, 24, 10])
.with_values(&[
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
])
.unwrap();
println!(">>> Input tensor dims: {:?}", input.dims());
{
let mut args = SessionRunArgs::new();
// input_A_test:
// Tensor("input_A_test:0", shape=(?, 24, ?), dtype=float32)
args.add_feed(&graph.operation_by_name_required(INPUT_NAME)
.expect(INPUT_NAME), 0, &input);
args.add_feed(&graph.operation_by_name_required(INPUT_NAME)
.expect(INPUT_LENGTHS_NAME), 0, &input);
// generation_B_test:
// Tensor("generator_A2B_3/output_transpose:0", shape=(?, 24, ?), dtype=float32)
let z = args.request_fetch(
&graph.operation_by_name_required(OUTPUT_NAME)
.expect(OUTPUT_NAME), 0);
session.run(&mut args).expect("Run success");
// Check our results.
let z_res = args.fetch::<f32>(z).expect("ret");
println!("z_rez.dims(): {:?}", z_res.dims());
println!("z_rez: {:?}", z_res);
}
}