{"id":18305299,"url":"https://github.com/guillaumegenthial/tf_metrics","last_synced_at":"2025-10-27T12:20:42.964Z","repository":{"id":48321118,"uuid":"149019728","full_name":"guillaumegenthial/tf_metrics","owner":"guillaumegenthial","description":"Multi-class metrics for Tensorflow","archived":false,"fork":false,"pushed_at":"2022-09-20T09:33:09.000Z","size":16,"stargazers_count":224,"open_issues_count":6,"forks_count":72,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-09T15:07:33.277Z","etag":null,"topics":["f1","metrics","multiclass","precision","recall","tensorflow","tensorflow-estimator"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guillaumegenthial.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-16T17:37:21.000Z","updated_at":"2025-01-17T13:10:58.000Z","dependencies_parsed_at":"2023-01-18T16:31:09.164Z","dependency_job_id":null,"html_url":"https://github.com/guillaumegenthial/tf_metrics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guillaumegenthial%2Ftf_metrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guillaumegenthial%2Ftf_metrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guillaumegenthial%2Ftf_metrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guillaumegenthial%2Ftf_metrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guillaumegenthial","download_url":"https://codeload.github.com/guillaumegenthial/tf_metrics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055284,"owners_count":21040157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["f1","metrics","multiclass","precision","recall","tensorflow","tensorflow-estimator"],"created_at":"2024-11-05T15:33:47.566Z","updated_at":"2025-10-27T12:20:37.923Z","avatar_url":"https://github.com/guillaumegenthial.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TF Metrics\n\n[![Build Status](https://travis-ci.org/guillaumegenthial/tf_metrics.svg?branch=master)](https://travis-ci.org/guillaumegenthial/tf_metrics)\n\nMulti-class metrics for Tensorflow, similar to scikit-learn multi-class metrics.\n\n*Thank you all for making this project live (50-100 clones/day 😎). Contributions welcome!*\n\n## Install\n\nTo add `tf_metrics` to your current python environment, run\n\n```\npip install git+https://github.com/guillaumegenthial/tf_metrics.git\n```\n\nFor a more advanced use (editable mode, for developers)\n\n```\ngit clone https://github.com/guillaumegenthial/tf_metrics.git\ncd tf_metrics\npip install -r requirements.txt\n```\n\n## Example\n\nPre-requisite: understand the general `tf.metrics` API. See for instance [the official guide on custom estimators](https://www.tensorflow.org/guide/custom_estimators#evaluate) or the [official documentation](https://www.tensorflow.org/api_docs/python/tf/metrics/accuracy).\n\n\nSimple example\n\n```python\nimport tensorflow as tf\nimport tf_metrics\n\ny_true = [0, 1, 0, 0, 0, 2, 3, 0, 0, 1]\ny_pred = [0, 1, 0, 0, 1, 2, 0, 3, 3, 1]\npos_indices = [1, 2, 3]  # Class 0 is the 'negative' class\nnum_classes = 4\naverage = 'micro'\n\n# Tuple of (value, update_op)\nprecision = tf_metrics.precision(\n    y_true, y_pred, num_classes, pos_indices, average=average)\nrecall = tf_metrics.recall(\n    y_true, y_pred, num_classes, pos_indices, average=average)\nf2 = tf_metrics.fbeta(\n    y_true, y_pred, num_classes, pos_indices, average=average, beta=2)\nf1 = tf_metrics.f1(\n    y_true, y_pred, num_classes, pos_indices, average=average)\n\n# Run the update op and get the updated value\nwith tf.Session() as sess:\n    sess.run(tf.local_variables_initializer())\n    sess.run(precision[1])\n```\n\n\nIf you want to use it with `tf.estimator.Estimator`, add to your `model_fn`\n\n\n```python\nmetrics = {\n    'precision': precision,\n    'recall': recall,\n    'f1': f1,\n    'f2': f2\n    }\n# For Tensorboard\nfor metric_name, metric in metrics.items():\n    tf.summary.scalar(metric_name, metric[1])\n\nif mode == tf.estimator.ModeKeys.EVAL:\n    return tf.estimator.EstimatorSpec(\n        mode, loss=loss, eval_metric_ops=metrics)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguillaumegenthial%2Ftf_metrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguillaumegenthial%2Ftf_metrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguillaumegenthial%2Ftf_metrics/lists"}