-
Notifications
You must be signed in to change notification settings - Fork 45.5k
Add export savedmodel to wide_deep #4041
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,37 @@ Run TensorBoard to inspect the details about the graph and training progression. | |
tensorboard --logdir=/tmp/census_model | ||
``` | ||
|
||
## Inference with SavedModel | ||
You can export the model into Tensorflow [SavedModel](https://www.tensorflow.org/programmers_guide/saved_model) format by using the argument `--export_dir`: | ||
|
||
``` | ||
python wide_deep.py --export_dir /tmp/wide_deep_saved_model | ||
``` | ||
|
||
After the model finishes training, use [`saved_model_cli`](https://www.tensorflow.org/programmers_guide/saved_model#cli_to_inspect_and_execute_savedmodel) to inspect and execute the SavedModel. | ||
|
||
Try the following commands to inspect the SavedModel: | ||
|
||
**Replace `${TIMESTAMP}` with the folder produced (e.g. 1524249124)** | ||
``` | ||
# List possible tag_sets. Only one metagraph is saved, so there will be one option. | ||
saved_model_cli show --dir /tmp/wide_deep_saved_model/${TIMESTAMP}/ | ||
|
||
# Show SignatureDefs for tag_set=serve. SignatureDefs define the outputs to show. | ||
saved_model_cli show --dir /tmp/wide_deep_saved_model/${TIMESTAMP}/ \ | ||
--tag_set serve --all | ||
``` | ||
|
||
### Inference | ||
Let's use the model to predict the income group of two examples: | ||
``` | ||
saved_model_cli run --dir /tmp/wide_deep_saved_model/${TIMESTAMP}/ \ | ||
--tag_set serve --signature_def="predict" \ | ||
--input_examples='examples=[{"age":[46.], "education_num":[10.], "capital_gain":[7688.], "capital_loss":[0.], "hours_per_week":[38.]}, {"age":[24.], "education_num":[13.], "capital_gain":[0.], "capital_loss":[0.], "hours_per_week":[50.]}]' | ||
``` | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great, thanks. |
||
This will print out the predicted classes and class probabilities. Class 0 is the <=50k group and 1 is the >50k group. | ||
|
||
## Additional Links | ||
|
||
If you are interested in distributed training, take a look at [Distributed TensorFlow](https://www.tensorflow.org/deploy/distributed). | ||
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we provide a default directory if user provides none? Not sure if this feature is used frequently by users. If so, I think a default dir may be good.
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.
Considering that the functionality of SavedModel is currently limited to serving, I don't think this feature is frequently used.