-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keras examples for single input and multiple inputs have been added. #286
base: master
Are you sure you want to change the base?
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function is removed.
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable is renamed now.
let result = session.run(&mut args); | ||
if result.is_err() { | ||
panic!("Error occured during calculations: {:?}", result); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified to:
session.run(&mut args).expect("Error occurred during calculations");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were these commented-out lines intended to be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file name has a typo: signle should be single.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File has been renamed
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't op names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable has been renamed.
let result = session.run(&mut args); | ||
if result.is_err() { | ||
panic!("Error occured during calculations: {:?}", result); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can use expect
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expect has been added.
@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.