{"id":5648357,"date":"2023-07-04T06:46:00","date_gmt":"2023-07-04T10:46:00","guid":{"rendered":"https:\/\/lightning.ai\/pages\/?p=5648357"},"modified":"2023-07-05T07:12:27","modified_gmt":"2023-07-05T11:12:27","slug":"torchmetrics-v1.0-100-metrics-and-plotting","status":"publish","type":"post","link":"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/","title":{"rendered":"Torchmetrics v1.0: Visualize model performance with 100+ metrics"},"content":{"rendered":"<div class=\"group w-full text-gray-800 dark:text-gray-100 border-b border-black\/10 dark:border-gray-900\/50 bg-gray-50 dark:bg-[#444654]\">\n<div class=\"flex p-4 gap-4 text-base md:gap-6 md:max-w-2xl lg:max-w-[38rem] xl:max-w-3xl md:py-6 lg:px-0 m-auto\">\n<div class=\"relative flex w-[calc(100%-50px)] flex-col gap-1 md:gap-3 lg:w-[calc(100%-115px)]\">\n<div class=\"flex flex-grow flex-col gap-3\">\n<div class=\"min-h-[20px] flex items-start overflow-x-auto whitespace-pre-wrap break-words flex-col gap-4\">\n<div class=\"markdown prose w-full break-words dark:prose-invert dark\">\n<p>We are happy to announce that the first major release of <a href=\"https:\/\/lightning.ai\/pages\/open-source\/torchmetrics\/\">TorchMetrics<\/a>, version v1.0, is now publicly available. We have worked hard on a couple of new features for this milestone release, and for v1.0.0, we have also managed to implement over <strong>100<\/strong> metrics in torchmetrics.<\/p>\n<p><strong>In this blogpost we go over some of the new features and improvements to the library.<\/strong><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h2 dir=\"auto\"><\/h2>\n<h2 dir=\"auto\"><a id=\"user-content-plotting\" class=\"anchor\" href=\"https:\/\/github.com\/Lightning-AI\/torchmetrics\/blob\/blogv1\/docs\/blogs\/blogpost_v1.0.0.md#plotting\" aria-hidden=\"true\"><\/a>Plotting<\/h2>\n<p dir=\"auto\">The big new feature of v1.0 is a build-in plotting feature. As the old saying goes:\u00a0<em>&#8220;A picture is worth a thousand words&#8221;<\/em>. Within machine learning, this is definitely also true for many things. Metrics are one area that in some cases are definitely better showcased in a figure than as list of floats. The only requirement for getting started with the plotting feature is installing\u00a0<code>matplotlib<\/code>. Either install with\u00a0<code>pip install matplotlib<\/code>\u00a0or\u00a0<code>pip install torchmetrics[visual]<\/code>\u00a0(the latter option also installs\u00a0<a href=\"https:\/\/github.com\/garrettj403\/SciencePlots\">Scienceplots<\/a>\u00a0and uses that as default plotting style).<\/p>\n<p dir=\"auto\">The basic interface is the same for\u00a0<strong>any<\/strong>\u00a0metric. Just call the new\u00a0<code>.plot<\/code>\u00a0method:<\/p>\n<pre class=\"highlight highlight-source-python notranslate position-relative overflow-auto hljs collapse-false language-python\" dir=\"auto\"><span class=\"pl-s1\">metric<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-v\">AnyMetricYouLike<\/span>()\r\n<span class=\"pl-k\">for<\/span> <span class=\"pl-s1\">_<\/span> <span class=\"pl-c1\">in<\/span> <span class=\"pl-en\">range<\/span>(<span class=\"pl-s1\">num_updates<\/span>):\r\n    <span class=\"pl-s1\">metric<\/span>.<span class=\"pl-en\">update<\/span>(<span class=\"pl-s1\">preds<\/span>[<span class=\"pl-s1\">i<\/span>], <span class=\"pl-s1\">target<\/span>[<span class=\"pl-s1\">i<\/span>])\r\n<span class=\"pl-s1\">fig<\/span>, <span class=\"pl-s1\">ax<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">metric<\/span>.<span class=\"pl-en\">plot<\/span>()<\/pre>\n<div class=\"zeroclipboard-container\"><\/div>\n<p dir=\"auto\">The\u00a0<code>plot<\/code>\u00a0method by default does not require any arguments and will automatically call\u00a0<code>metric.compute<\/code>\u00a0internally on whatever metric states have been accumulated.<\/p>\n<p dir=\"auto\">At the most basic level, the plot method can be used to used to plot the value from a single step:<\/p>\n<div class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\">\n<pre class=\"hljs collapse-false language-python\"><span class=\"pl-s1\">metric<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">torchmetrics<\/span>.<span class=\"pl-v\">Accuracy<\/span>(<span class=\"pl-s1\">task<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s\">\"binary\"<\/span>)\r\n<span class=\"pl-k\">for<\/span> <span class=\"pl-s1\">_<\/span> <span class=\"pl-c1\">in<\/span> <span class=\"pl-en\">range<\/span>(<span class=\"pl-s1\">num_updates<\/span>):\r\n    <span class=\"pl-s1\">metric<\/span>.<span class=\"pl-en\">update<\/span>(<span class=\"pl-s1\">torch<\/span>.<span class=\"pl-en\">rand<\/span>(<span class=\"pl-c1\">10<\/span>,), <span class=\"pl-s1\">torch<\/span>.<span class=\"pl-en\">randint<\/span>(<span class=\"pl-c1\">2<\/span>, (<span class=\"pl-c1\">10<\/span>,)))\r\n<span class=\"pl-s1\">fig<\/span>, <span class=\"pl-s1\">ax<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">metric<\/span>.<span class=\"pl-en\">plot<\/span>()\r\n\r\n<\/pre>\n<\/div>\n<pre dir=\"auto\">which would generate a plot like<\/pre>\n<p dir=\"auto\"><a href=\"https:\/\/github.com\/Lightning-AI\/torchmetrics\/blob\/blogv1\/docs\/blogs\/v1.0.0_plot_1.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/github.com\/Lightning-AI\/torchmetrics\/raw\/blogv1\/docs\/blogs\/v1.0.0_plot_1.png\" alt=\"plot\" \/><\/a><\/p>\n<p dir=\"auto\">A single point plot is not that informative in itself, but if available we will try to include additional information such as the lower and upper bounds the particular metric can take and if the metric should be minimized or maximized to be optimal. For experience users this may not have that big of an value, but for newcomers to machine learning or just somebody wanting to learn about a new metric, this can be beneficial.<\/p>\n<p dir=\"auto\">If a metric returns multiple values these can also be plotted, such that each value will be plotted individually and labeled:<\/p>\n<div class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\">\n<pre class=\"hljs collapse-false language-python\"><span class=\"pl-s1\">metric<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">torchmetrics<\/span>.<span class=\"pl-v\">Accuracy<\/span>(<span class=\"pl-s1\">task<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s\">\"multiclass\"<\/span>, <span class=\"pl-s1\">num_classes<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-c1\">3<\/span>, <span class=\"pl-s1\">average<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-c1\">None<\/span>)\r\n<span class=\"pl-k\">for<\/span> <span class=\"pl-s1\">_<\/span> <span class=\"pl-c1\">in<\/span> <span class=\"pl-en\">range<\/span>(<span class=\"pl-s1\">num_updates<\/span>):\r\n    <span class=\"pl-s1\">metric<\/span>.<span class=\"pl-en\">update<\/span>(<span class=\"pl-s1\">torch<\/span>.<span class=\"pl-en\">randint<\/span>(<span class=\"pl-c1\">3<\/span>, (<span class=\"pl-c1\">10<\/span>,)), <span class=\"pl-s1\">torch<\/span>.<span class=\"pl-en\">randint<\/span>(<span class=\"pl-c1\">3<\/span>, (<span class=\"pl-c1\">10<\/span>,)))\r\n<span class=\"pl-s1\">fig<\/span>, <span class=\"pl-s1\">ax<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">metric<\/span>.<span class=\"pl-en\">plot<\/span>()<\/pre>\n<div class=\"zeroclipboard-container\"><\/div>\n<\/div>\n<p dir=\"auto\"><a href=\"https:\/\/github.com\/Lightning-AI\/torchmetrics\/blob\/blogv1\/docs\/blogs\/v1.0.0_plot_2.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/github.com\/Lightning-AI\/torchmetrics\/raw\/blogv1\/docs\/blogs\/v1.0.0_plot_2.png\" alt=\"plot\" \/><\/a><\/p>\n<p dir=\"auto\">Finally, common practice is to plot a sequence of metric outputs like the progress over a training run. The\u00a0<code>.plot<\/code>\u00a0method support the user providing such a sequence of outputs, which will then be plotted as a line:ne:<\/p>\n<div class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\">\n<pre class=\"hljs collapse-false language-python\"><span class=\"pl-s1\">metric<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">torchmetrics<\/span>.<span class=\"pl-v\">Accuracy<\/span>(<span class=\"pl-s1\">task<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s\">\"binary\"<\/span>)\r\n<span class=\"pl-s1\">values<\/span> <span class=\"pl-c1\">=<\/span> [ ]\r\n<span class=\"pl-k\">for<\/span> <span class=\"pl-s1\">step<\/span> <span class=\"pl-c1\">in<\/span> <span class=\"pl-en\">range<\/span>(<span class=\"pl-s1\">num_steps<\/span>):\r\n    <span class=\"pl-k\">for<\/span> <span class=\"pl-s1\">_<\/span> <span class=\"pl-c1\">in<\/span> <span class=\"pl-en\">range<\/span>(<span class=\"pl-s1\">num_updates<\/span>):\r\n        <span class=\"pl-s1\">metric<\/span>.<span class=\"pl-en\">update<\/span>(<span class=\"pl-en\">preds<\/span>(<span class=\"pl-s1\">step<\/span>), <span class=\"pl-en\">target<\/span>(<span class=\"pl-s1\">step<\/span>))\r\n    <span class=\"pl-s1\">values<\/span>.<span class=\"pl-en\">append<\/span>(<span class=\"pl-s1\">metric<\/span>.<span class=\"pl-en\">compute<\/span>())  <span class=\"pl-c\"># save value<\/span>\r\n    <span class=\"pl-s1\">metric<\/span>.<span class=\"pl-en\">reset<\/span>()\r\n<span class=\"pl-s1\">fig<\/span>, <span class=\"pl-s1\">ax<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">metric<\/span>.<span class=\"pl-en\">plot<\/span>(<span class=\"pl-s1\">values<\/span>)<\/pre>\n<div class=\"zeroclipboard-container\"><\/div>\n<\/div>\n<p dir=\"auto\"><a href=\"https:\/\/github.com\/Lightning-AI\/torchmetrics\/blob\/blogv1\/docs\/blogs\/v1.0.0_plot_3.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/github.com\/Lightning-AI\/torchmetrics\/raw\/blogv1\/docs\/blogs\/v1.0.0_plot_3.png\" alt=\"plot\" \/><\/a><\/p>\n<p dir=\"auto\">Where the plotting feature really shines are metrics that are not represented by a single or a few numerical values. Two good examples are the classical\u00a0<code>ConfusionMatrix<\/code>\u00a0and\u00a0<code>ROC<\/code>\u00a0metrics. For metrics like these, we have written custom plot routines to generate the appropriate plots, with the interface still only being the\u00a0<code>.plot<\/code>\u00a0method:<\/p>\n<div class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\">\n<pre class=\"hljs collapse-false language-python\"><span class=\"pl-s1\">metric<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">torchmetrics<\/span>.<span class=\"pl-v\">ConfusionMatrix<\/span>(<span class=\"pl-s1\">task<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s\">\"multiclass\"<\/span>, <span class=\"pl-s1\">num_classes<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-c1\">3<\/span>)\r\n<span class=\"pl-k\">for<\/span> <span class=\"pl-s1\">_<\/span> <span class=\"pl-c1\">in<\/span> <span class=\"pl-en\">range<\/span>(<span class=\"pl-v\">N<\/span>):\r\n    <span class=\"pl-s1\">metric<\/span>.<span class=\"pl-en\">update<\/span>(<span class=\"pl-s1\">torch<\/span>.<span class=\"pl-en\">randint<\/span>(<span class=\"pl-c1\">3<\/span>, (<span class=\"pl-c1\">10<\/span>,)), <span class=\"pl-s1\">torch<\/span>.<span class=\"pl-en\">randint<\/span>(<span class=\"pl-c1\">3<\/span>, (<span class=\"pl-c1\">10<\/span>,)))\r\n<span class=\"pl-s1\">metric<\/span>.<span class=\"pl-en\">plot<\/span>(<span class=\"pl-s1\">ax<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">ax<\/span>)<\/pre>\n<div class=\"zeroclipboard-container\"><\/div>\n<\/div>\n<p dir=\"auto\"><a href=\"https:\/\/github.com\/Lightning-AI\/torchmetrics\/blob\/blogv1\/docs\/blogs\/v1.0.0_plot_4.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/github.com\/Lightning-AI\/torchmetrics\/raw\/blogv1\/docs\/blogs\/v1.0.0_plot_4.png\" alt=\"plot\" \/><\/a><\/p>\n<div class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\">\n<pre class=\"hljs collapse-false language-python\"><span class=\"pl-s1\">metric<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">torchmetrics<\/span>.<span class=\"pl-v\">ROC<\/span>(<span class=\"pl-s1\">task<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s\">\"binary\"<\/span>)\r\n<span class=\"pl-k\">for<\/span> <span class=\"pl-s1\">_<\/span> <span class=\"pl-c1\">in<\/span> <span class=\"pl-en\">range<\/span>(<span class=\"pl-v\">N<\/span>):\r\n    <span class=\"pl-s1\">metric<\/span>.<span class=\"pl-en\">update<\/span>(<span class=\"pl-s1\">torch<\/span>.<span class=\"pl-en\">rand<\/span>(<span class=\"pl-c1\">10<\/span>), <span class=\"pl-s1\">torch<\/span>.<span class=\"pl-en\">randint<\/span>(<span class=\"pl-c1\">2<\/span>, (<span class=\"pl-c1\">10<\/span>,)))\r\n<span class=\"pl-s1\">metric<\/span>.<span class=\"pl-en\">plot<\/span>(<span class=\"pl-s1\">ax<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">ax<\/span>)<\/pre>\n<div class=\"zeroclipboard-container\"><\/div>\n<\/div>\n<p dir=\"auto\"><a href=\"https:\/\/github.com\/Lightning-AI\/torchmetrics\/blob\/blogv1\/docs\/blogs\/v1.0.0_plot_5.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/github.com\/Lightning-AI\/torchmetrics\/raw\/blogv1\/docs\/blogs\/v1.0.0_plot_5.png\" alt=\"plot\" \/><\/a><\/p>\n<p dir=\"auto\">This feature is not meant (for now) to create publishing ready figures out of the box. Instead it is meant as an quick-and-dirty way to visualize any metric in Torchmetrics. If you have suggestion for how to improve the quality of the plots or make them more informative in some way, feel free to reach out to us.<\/p>\n<p dir=\"auto\">For a more explanation on this feature, visit our documentation:\u00a0<a href=\"https:\/\/torchmetrics.readthedocs.io\/en\/latest\/pages\/plotting.html\" rel=\"nofollow\">https:\/\/torchmetrics.readthedocs.io\/en\/latest\/pages\/plotting.html<\/a><\/p>\n<h2 dir=\"auto\"><a id=\"user-content-new-metrics\" class=\"anchor\" href=\"https:\/\/github.com\/Lightning-AI\/torchmetrics\/blob\/blogv1\/docs\/blogs\/blogpost_v1.0.0.md#new-metrics\" aria-hidden=\"true\"><\/a>New metrics<\/h2>\n<p dir=\"auto\">As already stated, for Torchmetrics v1.0 we have also crossed the milestone of having over 100 unique metrics. These metrics are divided between 12 different sub categories of metrics. Since the last release these 15 new metrics have been added to Torchmetrics:<\/p>\n<ul dir=\"auto\">\n<li>\n<p dir=\"auto\"><code>ComplexScaleInvariantSignalNoiseRatio<\/code>\u00a0have been added to\u00a0<code>audio<\/code>\u00a0subpackage<\/p>\n<\/li>\n<li>\n<p dir=\"auto\"><code>Running<\/code>\u00a0and\u00a0<code>MultitaskWrapper<\/code>\u00a0have been added to the metric\u00a0<code>wrapper<\/code>\u00a0subpackage. Here we want to highlight the\u00a0<code>Running<\/code>\u00a0wrapper that allows our users to calculate running averages over any metric the like.<\/p>\n<div class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\">\n<pre class=\"hljs collapse-false language-python\"><span class=\"pl-c\"># Running sum metric<\/span>\r\n<span class=\"pl-k\">from<\/span> <span class=\"pl-s1\">torchmetrics<\/span>.<span class=\"pl-s1\">wrappers<\/span> <span class=\"pl-k\">import<\/span> <span class=\"pl-v\">Running<\/span>\r\n<span class=\"pl-k\">from<\/span> <span class=\"pl-s1\">torchmetrics<\/span>.<span class=\"pl-s1\">aggregation<\/span> <span class=\"pl-k\">import<\/span> <span class=\"pl-v\">SumMetric<\/span>\r\n<span class=\"pl-c\"># Only calculate over last two samples<\/span>\r\n<span class=\"pl-s1\">metric<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-v\">Running<\/span>(<span class=\"pl-v\">SumMetric<\/span>(), <span class=\"pl-s1\">window<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-c1\">2<\/span>)\r\n<span class=\"pl-k\">for<\/span> <span class=\"pl-s1\">x<\/span> <span class=\"pl-c1\">in<\/span> [<span class=\"pl-c1\">1<\/span>, <span class=\"pl-c1\">2<\/span>, <span class=\"pl-c1\">3<\/span>, <span class=\"pl-c1\">4<\/span>]:\r\n    <span class=\"pl-s1\">metric<\/span>.<span class=\"pl-en\">update<\/span>(<span class=\"pl-s1\">x<\/span>)\r\n<span class=\"pl-s1\">res<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">metric<\/span>.<span class=\"pl-en\">compute<\/span>()  <span class=\"pl-c\"># res=7=3+4<\/span><\/pre>\n<div class=\"zeroclipboard-container\"><\/div>\n<\/div>\n<\/li>\n<li>\n<p dir=\"auto\"><code>SpecificityAtSensitivity<\/code>,\u00a0<code>BinaryGroupFairness<\/code>\u00a0and\u00a0<code>PrecisionAtFixedRecall<\/code>\u00a0have been added to the\u00a0<code>classification<\/code>\u00a0subpackage. Here we want to highlight the\u00a0<code>BinaryGroupFairness<\/code>\u00a0metric that is useful for determining the fairness of your machine learning algorithms and if they seem to have any kind of bias.<\/p>\n<\/li>\n<li>\n<p dir=\"auto\"><code>MinkowskiDistance<\/code>\u00a0and\u00a0<code>RelativeSquaredError<\/code>\u00a0have been added to\u00a0<code>regression<\/code>\u00a0subpackage<\/p>\n<\/li>\n<li>\n<p dir=\"auto\"><code>PSNRB<\/code>\u00a0have been added to the\u00a0<code>image<\/code>\u00a0subpackage.<\/p>\n<\/li>\n<li>\n<p dir=\"auto\"><code>IntersectionOverUnion<\/code>,\u00a0<code>GeneralizedIntersectionOverUnion<\/code>,\u00a0<code>CompleteIntersectionOverUnion<\/code>,\u00a0<code>DistanceIntersectionOverUnion<\/code>,\u00a0<code>PanopticQuality<\/code>\u00a0and\u00a0<code>ModifiedPanopticQuality<\/code>\u00a0have been added to the\u00a0<code>detection<\/code>\u00a0subpackage.<\/p>\n<\/li>\n<\/ul>\n<h2 dir=\"auto\"><a id=\"user-content-other-important-changes\" class=\"anchor\" href=\"https:\/\/github.com\/Lightning-AI\/torchmetrics\/blob\/blogv1\/docs\/blogs\/blogpost_v1.0.0.md#other-important-changes\" aria-hidden=\"true\"><\/a>Other important changes<\/h2>\n<p dir=\"auto\">In addition to the new plotting feature and newly added metrics, the following changes in v1.0 is also worth noticing:<\/p>\n<ul dir=\"auto\">\n<li>\n<p dir=\"auto\">We added official support for python 3.11 and have removed support for python 3.7<\/p>\n<\/li>\n<li>\n<p dir=\"auto\">We have deprecated importing most metrics from the root of\u00a0<code>torchmetrics<\/code>. Therefore, from the next release, import statements of the type\u00a0<code>from torchmetrics import ...<\/code>\u00a0is no longer possible for any metric from the subpackages: Audio, Detection, Image, Retrieval, Text. Instead these should be imported from their subpackages:\u00a0<code>from torchmetrics.subdomain import ...<\/code>. An example:<\/p>\n<div class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\">\n<pre class=\"hljs collapse-false language-python\"><span class=\"pl-c\"># versions below v1.0<\/span>\r\n<span class=\"pl-k\">from<\/span> <span class=\"pl-s1\">torchmetrics<\/span> <span class=\"pl-k\">import<\/span> <span class=\"pl-v\">PSNR<\/span>\r\n<span class=\"pl-c\"># version above v1.0<\/span>\r\n<span class=\"pl-k\">from<\/span> <span class=\"pl-s1\">torchmetrics<\/span>.<span class=\"pl-s1\">image<\/span> <span class=\"pl-k\">import<\/span> <span class=\"pl-v\">PSNR<\/span><\/pre>\n<div class=\"zeroclipboard-container\"><\/div>\n<\/div>\n<p dir=\"auto\">we have kept metrics from the classification and regression packages as these can be considered meta domains e.g. if working on image data you may need to use a combination of classification and image metrics to evaluate your machine learning models.<\/p>\n<\/li>\n<li>\n<p dir=\"auto\">The\u00a0<code>MeanAveragePrecision<\/code>\u00a0metric for the detection subpackage, now requires pycocotools to be installed. We have for the longest time tried to have a pure-torch implementation as the back engine, however that has been hard to maintain, wrong in corner cases and much slower than the official implementation. We now use pycocotools as the back engine for doing the calculation, while still providing the exact same interface as user have been used to.<\/p>\n<\/li>\n<\/ul>\n<p dir=\"auto\">For a list of all new features, changes, deprecations and bug fixes we refer to the changelog:\u00a0<a href=\"https:\/\/github.com\/Lightning-AI\/torchmetrics\/blob\/master\/CHANGELOG.md\">https:\/\/github.com\/Lightning-AI\/torchmetrics\/blob\/master\/CHANGELOG.md<\/a><\/p>\n<h2 dir=\"auto\"><a id=\"user-content-future-goals\" class=\"anchor\" href=\"https:\/\/github.com\/Lightning-AI\/torchmetrics\/blob\/blogv1\/docs\/blogs\/blogpost_v1.0.0.md#future-goals\" aria-hidden=\"true\"><\/a>Future goals<\/h2>\n<p dir=\"auto\">v1.0 officially marks the first stable release of Torchmetrics. However, the truth is that the API has not really changed since v0.1 and we have considered it stable for at least a couple of releases.<\/p>\n<p dir=\"auto\">For the future we plan on expanding to even more metrics, making sure that if you ever need a metric for measuring the performance of your machine learning models, you can find it in Torchmetrics.<\/p>\n<h2 dir=\"auto\"><a id=\"user-content-thank-you\" class=\"anchor\" href=\"https:\/\/github.com\/Lightning-AI\/torchmetrics\/blob\/blogv1\/docs\/blogs\/blogpost_v1.0.0.md#thank-you\" aria-hidden=\"true\"><\/a>Thank you!<\/h2>\n<p dir=\"auto\">Big thanks to all our community members for their contributions and feedback. If you have any recommendations for the next metric that we should try to tackle, please open an issue in the\u00a0<a href=\"https:\/\/github.com\/Lightning-AI\/metrics\">repo<\/a>.<\/p>\n<p dir=\"auto\">We are happy to see a continued adaption of TorchMetrics in over 12000+ projects, and this release also marks the point where we crossed 1500+ GitHub stars.<\/p>\n<p dir=\"auto\">Finally, If you would like to give open source a try, we have the\u00a0<code>#want-to-contribute<\/code> and\u00a0<code>#torchmetrics<\/code> channel on the Lightning AI <a href=\"https:\/\/discord.gg\/TKRzyC5hxW\">Discord<\/a>\u00a0where you can ask a question and get guidance.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We are happy to announce that the first major release of TorchMetrics, version v1.0, is now publicly available. We have worked hard on a couple of new features for this milestone release, and for v1.0.0, we have also managed to implement over 100 metrics in torchmetrics. In this blogpost we go over some of the<a class=\"excerpt-read-more\" href=\"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/\" title=\"ReadTorchmetrics v1.0: Visualize model performance with 100+ metrics\">&#8230; Read more &raquo;<\/a><\/p>\n","protected":false},"author":39,"featured_media":5648360,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":"","_links_to":"","_links_to_target":""},"categories":[101,29,106,41],"tags":[237],"glossary":[],"acf":{"additional_authors":[{"author_name":"Nicki Skafte Detlefsen","author_url":""}],"mathjax":false,"default_editor":true,"show_table_of_contents":false,"hide_from_archive":false,"content_type":"Blog Post","sticky":false,"custom_styles":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Torchmetrics v1.0: Visualize model performance with 100+ metrics - Lightning AI<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Torchmetrics v1.0: Visualize model performance with 100+ metrics - Lightning AI\" \/>\n<meta property=\"og:description\" content=\"We are happy to announce that the first major release of TorchMetrics, version v1.0, is now publicly available. We have worked hard on a couple of new features for this milestone release, and for v1.0.0, we have also managed to implement over 100 metrics in torchmetrics. In this blogpost we go over some of the... Read more &raquo;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/\" \/>\n<meta property=\"og:site_name\" content=\"Lightning AI\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-04T10:46:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-05T11:12:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/lightningaidev.wpengine.com\/wp-content\/uploads\/2023\/07\/4-july-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1600\" \/>\n\t<meta property=\"og:image:height\" content=\"900\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Lightning.ai\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@LightningAI\" \/>\n<meta name=\"twitter:site\" content=\"@LightningAI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Lightning.ai\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/\"},\"author\":{\"name\":\"Lightning.ai\",\"@id\":\"https:\/\/lightning.ai\/pages\/#\/schema\/person\/d53c9386be275d278c59022570c0d859\"},\"headline\":\"Torchmetrics v1.0: Visualize model performance with 100+ metrics\",\"datePublished\":\"2023-07-04T10:46:00+00:00\",\"dateModified\":\"2023-07-05T11:12:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/\"},\"wordCount\":982,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/lightning.ai\/pages\/#organization\"},\"image\":{\"@id\":\"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/lightningaidev.wpengine.com\/wp-content\/uploads\/2023\/07\/4-july-2.png\",\"keywords\":[\"torchmetrics\"],\"articleSection\":[\"Announcements\",\"Blog\",\"Community\",\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/\",\"url\":\"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/\",\"name\":\"Torchmetrics v1.0: Visualize model performance with 100+ metrics - Lightning AI\",\"isPartOf\":{\"@id\":\"https:\/\/lightning.ai\/pages\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/lightningaidev.wpengine.com\/wp-content\/uploads\/2023\/07\/4-july-2.png\",\"datePublished\":\"2023-07-04T10:46:00+00:00\",\"dateModified\":\"2023-07-05T11:12:27+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/#primaryimage\",\"url\":\"https:\/\/lightningaidev.wpengine.com\/wp-content\/uploads\/2023\/07\/4-july-2.png\",\"contentUrl\":\"https:\/\/lightningaidev.wpengine.com\/wp-content\/uploads\/2023\/07\/4-july-2.png\",\"width\":1600,\"height\":900},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/lightning.ai\/pages\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Torchmetrics v1.0: Visualize model performance with 100+ metrics\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/lightning.ai\/pages\/#website\",\"url\":\"https:\/\/lightning.ai\/pages\/\",\"name\":\"Lightning AI\",\"description\":\"The platform for teams to build AI.\",\"publisher\":{\"@id\":\"https:\/\/lightning.ai\/pages\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/lightning.ai\/pages\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/lightning.ai\/pages\/#organization\",\"name\":\"Lightning AI\",\"url\":\"https:\/\/lightning.ai\/pages\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/lightning.ai\/pages\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/lightningaidev.wpengine.com\/wp-content\/uploads\/2023\/02\/image-17.png\",\"contentUrl\":\"https:\/\/lightningaidev.wpengine.com\/wp-content\/uploads\/2023\/02\/image-17.png\",\"width\":1744,\"height\":856,\"caption\":\"Lightning AI\"},\"image\":{\"@id\":\"https:\/\/lightning.ai\/pages\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/LightningAI\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/lightning.ai\/pages\/#\/schema\/person\/d53c9386be275d278c59022570c0d859\",\"name\":\"Lightning.ai\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/lightning.ai\/pages\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b75fef9be69cb600f385dfba5525cf77?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b75fef9be69cb600f385dfba5525cf77?s=96&d=mm&r=g\",\"caption\":\"Lightning.ai\"},\"url\":\"https:\/\/lightning.ai\/pages\/author\/lightning-ai\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Torchmetrics v1.0: Visualize model performance with 100+ metrics - Lightning AI","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/","og_locale":"en_US","og_type":"article","og_title":"Torchmetrics v1.0: Visualize model performance with 100+ metrics - Lightning AI","og_description":"We are happy to announce that the first major release of TorchMetrics, version v1.0, is now publicly available. We have worked hard on a couple of new features for this milestone release, and for v1.0.0, we have also managed to implement over 100 metrics in torchmetrics. In this blogpost we go over some of the... Read more &raquo;","og_url":"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/","og_site_name":"Lightning AI","article_published_time":"2023-07-04T10:46:00+00:00","article_modified_time":"2023-07-05T11:12:27+00:00","og_image":[{"width":1600,"height":900,"url":"https:\/\/lightningaidev.wpengine.com\/wp-content\/uploads\/2023\/07\/4-july-2.png","type":"image\/png"}],"author":"Lightning.ai","twitter_card":"summary_large_image","twitter_creator":"@LightningAI","twitter_site":"@LightningAI","twitter_misc":{"Written by":"Lightning.ai","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/#article","isPartOf":{"@id":"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/"},"author":{"name":"Lightning.ai","@id":"https:\/\/lightning.ai\/pages\/#\/schema\/person\/d53c9386be275d278c59022570c0d859"},"headline":"Torchmetrics v1.0: Visualize model performance with 100+ metrics","datePublished":"2023-07-04T10:46:00+00:00","dateModified":"2023-07-05T11:12:27+00:00","mainEntityOfPage":{"@id":"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/"},"wordCount":982,"commentCount":0,"publisher":{"@id":"https:\/\/lightning.ai\/pages\/#organization"},"image":{"@id":"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/#primaryimage"},"thumbnailUrl":"https:\/\/lightningaidev.wpengine.com\/wp-content\/uploads\/2023\/07\/4-july-2.png","keywords":["torchmetrics"],"articleSection":["Announcements","Blog","Community","Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/","url":"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/","name":"Torchmetrics v1.0: Visualize model performance with 100+ metrics - Lightning AI","isPartOf":{"@id":"https:\/\/lightning.ai\/pages\/#website"},"primaryImageOfPage":{"@id":"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/#primaryimage"},"image":{"@id":"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/#primaryimage"},"thumbnailUrl":"https:\/\/lightningaidev.wpengine.com\/wp-content\/uploads\/2023\/07\/4-july-2.png","datePublished":"2023-07-04T10:46:00+00:00","dateModified":"2023-07-05T11:12:27+00:00","breadcrumb":{"@id":"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/#primaryimage","url":"https:\/\/lightningaidev.wpengine.com\/wp-content\/uploads\/2023\/07\/4-july-2.png","contentUrl":"https:\/\/lightningaidev.wpengine.com\/wp-content\/uploads\/2023\/07\/4-july-2.png","width":1600,"height":900},{"@type":"BreadcrumbList","@id":"https:\/\/lightning.ai\/pages\/blog\/torchmetrics-v1.0-100-metrics-and-plotting\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/lightning.ai\/pages\/"},{"@type":"ListItem","position":2,"name":"Torchmetrics v1.0: Visualize model performance with 100+ metrics"}]},{"@type":"WebSite","@id":"https:\/\/lightning.ai\/pages\/#website","url":"https:\/\/lightning.ai\/pages\/","name":"Lightning AI","description":"The platform for teams to build AI.","publisher":{"@id":"https:\/\/lightning.ai\/pages\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/lightning.ai\/pages\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/lightning.ai\/pages\/#organization","name":"Lightning AI","url":"https:\/\/lightning.ai\/pages\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lightning.ai\/pages\/#\/schema\/logo\/image\/","url":"https:\/\/lightningaidev.wpengine.com\/wp-content\/uploads\/2023\/02\/image-17.png","contentUrl":"https:\/\/lightningaidev.wpengine.com\/wp-content\/uploads\/2023\/02\/image-17.png","width":1744,"height":856,"caption":"Lightning AI"},"image":{"@id":"https:\/\/lightning.ai\/pages\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/LightningAI"]},{"@type":"Person","@id":"https:\/\/lightning.ai\/pages\/#\/schema\/person\/d53c9386be275d278c59022570c0d859","name":"Lightning.ai","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lightning.ai\/pages\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b75fef9be69cb600f385dfba5525cf77?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b75fef9be69cb600f385dfba5525cf77?s=96&d=mm&r=g","caption":"Lightning.ai"},"url":"https:\/\/lightning.ai\/pages\/author\/lightning-ai\/"}]}},"_links":{"self":[{"href":"https:\/\/lightning.ai\/pages\/wp-json\/wp\/v2\/posts\/5648357"}],"collection":[{"href":"https:\/\/lightning.ai\/pages\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lightning.ai\/pages\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lightning.ai\/pages\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/lightning.ai\/pages\/wp-json\/wp\/v2\/comments?post=5648357"}],"version-history":[{"count":0,"href":"https:\/\/lightning.ai\/pages\/wp-json\/wp\/v2\/posts\/5648357\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lightning.ai\/pages\/wp-json\/wp\/v2\/media\/5648360"}],"wp:attachment":[{"href":"https:\/\/lightning.ai\/pages\/wp-json\/wp\/v2\/media?parent=5648357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lightning.ai\/pages\/wp-json\/wp\/v2\/categories?post=5648357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lightning.ai\/pages\/wp-json\/wp\/v2\/tags?post=5648357"},{"taxonomy":"glossary","embeddable":true,"href":"https:\/\/lightning.ai\/pages\/wp-json\/wp\/v2\/glossary?post=5648357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}