Tensorflow Model Analysis Setup
Stay organized with collections
Save and categorize content based on your preferences.
Configuration
TFMA stores its configuration in a
proto
that is serialized to JSON. This proto consolidates the configuration required
for input data, output data, model specifications, metric specifications, and
slicing specifications.
All TFMA pipelines are associated with a baseline (primary) model and zero or
more candidate (secondary) models. The baseline and candidate model are defined
by the user at the start of the pipeline and each require a unique name. The
following are examples of typical configuration setups a user may use:
- Single model evaluation:
- Validation-based evaluation:
- Model comparison evaluation:
Model Specs
Model specs are of type tfma.ModelSpec
and are used to define the location of
a model as well as other model specific parameters. For example the following
are typical settings that would need to be configured prior to running an
evaluation:
name
- name of model (if multiple models used)
signature_name
- name of signature used for predictions (default is
serving_default
). Use eval
if using an EvalSavedModel.
label_key
- name of the feature associated with the label.
example_weight_key
- name of the feature assocated with the example
weight.
Metrics Specs
Metrics specs are of type tfma.MetricsSpec
and are used to configure the
metrics that will be calculated as part of the evaluation. Different machine
learning problems use different types of metrics and TFMA offers a lot of
options for configuring and customizing the metrics that are computed. Since
metrics are a very large part of TFMA, they are discussed in detail separately
in metrics.
Slicing Specs
Slicing specs are of type tfma.SlicingSpec
and are used to configure the
slices criteria that will be used during the evaluation. Slicing can be done
either by feature_keys
, feature_values
, or both. Some examples of slicing
specs are as follows:
{}
- Slice consisting of overall data.
{ feature_keys: ["country"] }
- Slices for all values in feature "country". For example, we might get
slices "country:us", "country:jp", etc.
{ feature_values: [{key: "country", value: "us"}] }
- Slice consisting of "country:us".
{ feature_keys: ["country", "city"] }
- Slices for all values in feature "country" crossed with all values in
feature "city" (note this may be expensive).
{ feature_keys: ["country"] feature_values: [{key: "age", value: "20"}] }
- Slices for all values in feature "country" crossed with value "age:20"
Note that feature keys may be either transformed features or raw input features.
See tfma.SlicingSpec
for more information.
EvalSharedModel
In addition to the configuration settings, TFMA also requires that an instance
of a tfma.EvalSharedModel
be created for sharing a model between multiple
threads in the same process. The shared model instance includes information
about the type of model (keras, etc) and how to load and configure the model
from its saved location on disk (e.g. tags, etc). The
tfma.default_eval_shared_model
API can be used to create a default instance
given a path and set of tags.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2021-01-28 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2021-01-28 UTC."],[],[],null,["# Tensorflow Model Analysis Setup\n\n\u003cbr /\u003e\n\nConfiguration\n-------------\n\nTFMA stores its configuration in a\n[proto](https://github.com/tensorflow/model-analysis/blob/master/tensorflow_model_analysis/proto/config.proto)\nthat is serialized to JSON. This proto consolidates the configuration required\nfor input data, output data, model specifications, metric specifications, and\nslicing specifications.\n\nAll TFMA pipelines are associated with a baseline (primary) model and zero or\nmore candidate (secondary) models. The baseline and candidate model are defined\nby the user at the start of the pipeline and each require a unique name. The\nfollowing are examples of typical configuration setups a user may use:\n\n- Single model evaluation:\n - N/A (i.e. no name)\n- Validation-based evaluation:\n - `baseline`\n - `candidate`\n- Model comparison evaluation:\n - `my_model_a`\n - `my_model_b`\n\n### Model Specs\n\nModel specs are of type [`tfma.ModelSpec`](https://www.tensorflow.org/tfx/model_analysis/api_docs/python/tfma/ModelSpec) and are used to define the location of\na model as well as other model specific parameters. For example the following\nare typical settings that would need to be configured prior to running an\nevaluation:\n\n- `name` - name of model (if multiple models used)\n- `signature_name` - name of signature used for predictions (default is `serving_default`). Use `eval` if using an EvalSavedModel.\n- `label_key` - name of the feature associated with the label.\n- `example_weight_key` - name of the feature assocated with the example weight.\n\n### Metrics Specs\n\nMetrics specs are of type [`tfma.MetricsSpec`](https://www.tensorflow.org/tfx/model_analysis/api_docs/python/tfma/MetricsSpec) and are used to configure the\nmetrics that will be calculated as part of the evaluation. Different machine\nlearning problems use different types of metrics and TFMA offers a lot of\noptions for configuring and customizing the metrics that are computed. Since\nmetrics are a very large part of TFMA, they are discussed in detail separately\nin [metrics](/tfx/model_analysis/metrics).\n\n### Slicing Specs\n\nSlicing specs are of type [`tfma.SlicingSpec`](https://www.tensorflow.org/tfx/model_analysis/api_docs/python/tfma/SlicingSpec) and are used to configure the\nslices criteria that will be used during the evaluation. Slicing can be done\neither by `feature_keys`, `feature_values`, or both. Some examples of slicing\nspecs are as follows:\n\n- `{}`\n - Slice consisting of overall data.\n- `{ feature_keys: [\"country\"] }`\n - Slices for all values in feature \"country\". For example, we might get slices \"country:us\", \"country:jp\", etc.\n- `{ feature_values: [{key: \"country\", value: \"us\"}] }`\n - Slice consisting of \"country:us\".\n- `{ feature_keys: [\"country\", \"city\"] }`\n - Slices for all values in feature \"country\" crossed with all values in feature \"city\" (note this may be expensive).\n- `{ feature_keys: [\"country\"] feature_values: [{key: \"age\", value: \"20\"}] }`\n - Slices for all values in feature \"country\" crossed with value \"age:20\"\n\nNote that feature keys may be either transformed features or raw input features.\nSee [`tfma.SlicingSpec`](https://www.tensorflow.org/tfx/model_analysis/api_docs/python/tfma/SlicingSpec) for more information.\n\nEvalSharedModel\n---------------\n\nIn addition to the configuration settings, TFMA also requires that an instance\nof a [`tfma.EvalSharedModel`](https://www.tensorflow.org/tfx/model_analysis/api_docs/python/tfma/types/EvalSharedModel) be created for sharing a model between multiple\nthreads in the same process. The shared model instance includes information\nabout the type of model (keras, etc) and how to load and configure the model\nfrom its saved location on disk (e.g. tags, etc). The\n[`tfma.default_eval_shared_model`](https://www.tensorflow.org/tfx/model_analysis/api_docs/python/tfma/default_eval_shared_model) API can be used to create a default instance\ngiven a path and set of tags."]]