mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-15 14:22:14 +00:00
model loading works, but is from a wrong version of tensorflow
This commit is contained in:
1 parent
2982a82999
commit
4f331f3f83
2 files changed
+90
-1
No files matched your search
@@ -117,3 +117,27 @@ PulseAudio's default sampling rate and bit depth are set to 44100Hz @ 16 bits.
|
||||
> 524288 / 1411200 (fragment size)
|
||||
0.37151927437641724 = 372 ms
|
||||
|
||||
|
||||
TensorFlow Model
|
||||
----------------
|
||||
|
||||
Saved model (.pb file) must be in `saved_model/saved_model.pb` or similar.
|
||||
|
||||
Need TensorFlow model tools:
|
||||
|
||||
`bazel build tensorflow/python/tools:saved_model_cli`
|
||||
|
||||
```
|
||||
# NB: Save the graph
|
||||
definition = self.model.sess.graph_def
|
||||
directory = 'output_model_pb'
|
||||
tf.train.write_graph(definition, directory, 'model.pb', as_text=False)
|
||||
|
||||
# https://github.com/tensorflow/models/issues/3530#issuecomment-395968881
|
||||
output_dir = './saved_model/'
|
||||
builder = tf.saved_model.builder.SavedModelBuilder(output_dir)
|
||||
builder.add_meta_graph_and_variables(self.model.sess, [
|
||||
tf.saved_model.tag_constants.SERVING],)
|
||||
builder.save()
|
||||
```
|
||||
|
||||
+66
-1
@@ -3,12 +3,77 @@
|
||||
//! This example records audio and plays it back in real time as it's being recorded.
|
||||
|
||||
extern crate wavy;
|
||||
extern crate tensorflow;
|
||||
|
||||
use wavy::*;
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
use std::process::exit;
|
||||
use tensorflow::Code;
|
||||
use tensorflow::Graph;
|
||||
use tensorflow::ImportGraphDefOptions;
|
||||
use tensorflow::Session;
|
||||
use tensorflow::SessionOptions;
|
||||
use tensorflow::SessionRunArgs;
|
||||
use tensorflow::Status;
|
||||
use tensorflow::Tensor;
|
||||
|
||||
fn main() -> Result<(), AudioError> {
|
||||
fn main() {
|
||||
load_model();
|
||||
//load_model_2();
|
||||
run_audio().expect("should work");
|
||||
run_audio().expect("should work");
|
||||
}
|
||||
|
||||
fn load_model() {
|
||||
let export_dir = "/home/bt/dev/voder/saved_model";
|
||||
|
||||
let mut graph = Graph::new();
|
||||
let session = Session::from_saved_model(
|
||||
&SessionOptions::new(),
|
||||
//&["train", "serve"],
|
||||
&["serve"],
|
||||
&mut graph,
|
||||
export_dir,
|
||||
).expect("Should load");
|
||||
|
||||
}
|
||||
|
||||
fn load_model_2() {
|
||||
// from regression_checkpoint.rs example
|
||||
|
||||
let filename = "/home/bt/dev/voder/saved_model/saved_model.pb";
|
||||
|
||||
let mut graph = Graph::new();
|
||||
let mut proto = Vec::new();
|
||||
|
||||
File::open(filename)
|
||||
.expect("opened")
|
||||
.read_to_end(&mut proto)
|
||||
.expect("cannot read");
|
||||
|
||||
graph.import_graph_def(&proto, &ImportGraphDefOptions::new()).expect("cannot import");
|
||||
|
||||
let session = Session::new(&SessionOptions::new(), &graph).expect("cannot session");
|
||||
|
||||
/*let op_x = graph.operation_by_name_required("x").expect("x");
|
||||
let op_y = graph.operation_by_name_required("y").expect("y");
|
||||
let op_init = graph.operation_by_name_required("init").expect("init");
|
||||
let op_train = graph.operation_by_name_required("train").expect("train");
|
||||
let op_w = graph.operation_by_name_required("w").expect("w");
|
||||
let op_b = graph.operation_by_name_required("b").expect("b");
|
||||
let op_file_path = graph.operation_by_name_required("save/Const").expect("const");
|
||||
let op_save = graph.operation_by_name_required("save/control_dependency").expect("save");*/
|
||||
|
||||
//let file_path_tensor: Tensor<String> =
|
||||
// Tensor::from(String::from("/home/bt/dev/voder/extra_model/sf1_tm1.ckpt.data-00000-of-00001"));
|
||||
//println!("Tensor: {:?}", file_path_tensor);
|
||||
}
|
||||
|
||||
fn run_audio() -> Result<(), AudioError> {
|
||||
println!("Opening microphone system");
|
||||
let mut mic = MicrophoneSystem::new(SampleRate::Normal)?;
|
||||
|
||||
|
||||
Reference in new issue
Block a user