Code Monkey home page Code Monkey logo

Comments (4)

mdreves avatar mdreves commented on August 15, 2024

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.

thisisandreeeee avatar thisisandreeeee commented on August 15, 2024

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.

mdreves avatar mdreves commented on August 15, 2024

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.

thisisandreeeee avatar thisisandreeeee commented on August 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.