Keras examples for single input and multiple inputs have been added.#286
Keras examples for single input and multiple inputs have been added.#286justnoxx wants to merge 5 commits intotensorflow:masterfrom
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
|
@googlebot I signed it! |
|
@adamcrume there are some examples related to Keras that I mentioned in #282 /Dmitriy |
adamcrume
left a comment
There was a problem hiding this comment.
Looks good, just a few minor style issues.
Also, please run cargo fmt.
| let save_dir = "examples/keras_multiple_inputs_saved_model"; | ||
| let v1: Vec<f32> = vec![0.1, 0.2, 0.3, 0.4, 0.5]; | ||
| let v2 = vec![0.6, 0.7, 0.8, 0.9, 0.1]; | ||
| let tensor1 = vector_to_tensor(&v1); |
There was a problem hiding this comment.
This can be simplified to:
let tensor1 = Tensor::from(&[0.1, 0.2, 0.3, 0.4, 0.5][..]);
no Vec or vector_to_tensor needed.
| // In this file test_in_input is being used while in the python script, | ||
| // that generates the saved model from Keras model it has a name "test_in". | ||
| // For multiple inputs _input is not being appended to the op name. | ||
| let input_1_op_name = "test_in1"; |
There was a problem hiding this comment.
These aren't op names, they're signature input (or output) parameter names. I know this sounds like nitpicking, but this can be confusing, so it's important to make a clear distinction, so readers don't think they're the same thing.
| let result = session.run(&mut args); | ||
| if result.is_err() { | ||
| panic!("Error occured during calculations: {:?}", result); | ||
| } |
There was a problem hiding this comment.
This can be simplified to:
session.run(&mut args).expect("Error occurred during calculations");
There was a problem hiding this comment.
Simplification has been performed.
| print(x1.shape) | ||
| y = np.random.randn(100, 1) | ||
| # print(v1.shape) | ||
| # print(v2.shape) |
There was a problem hiding this comment.
Were these commented-out lines intended to be removed?
There was a problem hiding this comment.
Obsolete lines have been removed.
| let dimension = v.len(); | ||
| let tensor = Tensor::new(&[1, dimension as u64]).with_values(&v[..]).unwrap(); | ||
| return tensor; | ||
| } |
There was a problem hiding this comment.
This file name has a typo: signle should be single.
| let save_dir = "examples/keras_signle_input_saved_model"; | ||
| let v: Vec<f32> = vec![0.1, 0.2, 0.3, 0.4, 0.5]; | ||
|
|
||
| let tensor = vector_to_tensor(&v); |
There was a problem hiding this comment.
As with the other file, this can be simplified to:
let tensor = Tensor::from(&[0.1, 0.2, 0.3, 0.4, 0.5][..]);
There was a problem hiding this comment.
Well, it did not work for me because your code is creating tensor of dims:[5], but dim:[1, 5] is expected, so I used the following code:
let tensor: Tensor<f32> = Tensor::new(&[1, 5])
.with_values(&[0.1, 0.2, 0.3, 0.4, 0.5])
.expect("Can't create tensor");| // In this file test_in_input is being used while in the python script, | ||
| // that generates the saved model from Keras model it has a name "test_in". | ||
| // For multiple inputs _input is not being appended to the op name. | ||
| let input_op_name = "test_in_input"; |
| let result = session.run(&mut args); | ||
| if result.is_err() { | ||
| panic!("Error occured during calculations: {:?}", result); | ||
| } |
|
@adamcrume sorry for delay, literally did not have time to address that, but now I did the changes that you requested. A file with typo in its name has been renamed. Cargo fmt has been also applied. Please, let me know if I need to do additional updates. |
These examples are explaining how to use saved models created using Keras.
1st example explains how to use the model when there is precisely one input operation.
2nd example shows how to deal with models where more than one input ops.