Comments (4)
It is a bit confusing. In the case of Estimators, a single output model would output multiple prediction keys (probabilities, classes, etc) but only one of the keys was intended to be used as the prediction (e.g. 'probabilities', 'logistic', etc). If someone customized the name of that key then they would need to update their EvalConfig.model_spec to set the 'prediction_key'. The estimator could also be multi-head (multi-output) in which case there would be multiple dicts each with a set of keys (the 'head' name would correspond to the EvalConfig.metrics_spec.output_name' and the
EvalConfig.model_spec.prediction_key` would refer to the entry representing the prediction under each head).
For keras there is only a single key per output so only the 'EvalConfig.metrics_spec.output_name' applies for these models.
Long story short, AFAICT you have a multi-output model with two possible outputs 'mu' and 'sigma', so you should set the 'EvalConfig.metrics_spec.output_name' to either (or both) outputs. However, if your setup is such that the prediction is always either 'mu' and 'sigma' and the other key is just extra information, then you should set the 'EvalConfig.model_spec.prediction_key' instead.
from model-analysis.
Ah, I see. That is rather confusing indeed 😂 What worked for me was the following:
eval_config = tfma.EvalConfig(
model_specs=[
tfma.ModelSpec(
label_key="my_label_key",
prediction_key="mu" # setting the prediction key
)
],
metrics_specs=[
tfma.MetricsSpec(
output_names=["mu"], # and the output names
metrics=[tfma.MetricConfig(
class_name="MeanSquaredError",
config='"dtype": "float32", "name": "mse"'
)]
)
],
slicing_specs=[tfma.SlicingSpec()]
)
eval_shared_model = tfma.default_eval_shared_model(saved_model_dir, eval_config=eval_config)
What happens if I want to use a custom metric with a update_state
method that has a nonstandard function signature? The typical function signature is:
def update_state(self, y_true, y_pred, sample_weight=None):
However, my custom metric uses the following signature:
def update_state(self, y_true, y_pred, some, other, arguments, sample_weight=None):
I can't seem to figure out (from the TFMA documentation) how to specify a custom metric with a update_state
that has been overridden. As such, when I run the model analysis, I encounter the following error:
TypeError: in user code:
TypeError: tf__update_state() missing 3 required positional arguments: 'some', 'other', and 'arguments'
Do we only have the option to pass kwargs to initialise the metric via EvalConfig.MetricConfig.config
?
from model-analysis.
For keras metrics we currently only support metrics that can be passed to model.compile (i.e. that take the standard arguments: y_true, y_pred, sample_weight). In the future we will support other metrics (i.e. those added via model.add_metric), but those will need to be added as part of your model otherwise we don't know what arguments to pass.
from model-analysis.
I understand. Guess I'll close this issue for now since it doesn't seem like we'll be able to get to a resolution. Thanks @mdreves
from model-analysis.
Related Issues (20)
- Unable to use custom Keras metrics with TFX evaluator component HOT 4
- AttributeError: partially initialized module error, test.py HOT 2
- Incorrect Documentation for MetricConfig
- Custom multilabel Keras metrics: dynamically initialize weight shape HOT 1
- Fairness indicator metrics do not show up HOT 5
- Validation bug when using feature values as slicing specs HOT 2
- No longer compatible with Dataflow runner v1 after v0.29
- Renaming Custom Layer breaks TFMA Evaluator HOT 6
- Error in merge_accumulators when using keras metrics on dataflow HOT 3
- TFMA analyze_raw_data function support with MultiClassConfusionMatrixPlot HOT 3
- Analytics HOT 1
- Breaking changes: tfma.metrics.MetricComputation `preprocessor` argument changed from accepting beam DoFn to `preprocessors` accepting a list of `Preprocessor` HOT 1
- Move to numpy >=1.20 because <1.20 is difficult to build on Apple Silicon HOT 4
- TFMA on Flink does not seems to be parallelizing work. HOT 5
- only integer values should be passed to num_instances metric. HOT 3
- Render_plot is failing HOT 2
- Feat: Have ability to return the HTML rather than creating the plots HOT 1
- CVE in Pyarrow dependency HOT 1
- CNN HOT 2
- pip install tensorflow-model-analysis fails on WSL2 on Windows 11 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from model-analysis.