-
-
Notifications
You must be signed in to change notification settings - Fork 636
/
Copy pathmetrics.html
1437 lines (1211 loc) · 126 KB
/
metrics.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="author" content="PyTorch-Ignite Contributors">
<meta name="creator" content="PyTorch-Ignite Contributors">
<meta name="publisher" content="PyTorch-Ignite Contributors">
<meta name="generator" content="Sphinx 5.3.0">
<meta name="description" content="High-level library to help with training and evaluating neural networks in PyTorch flexibly and transparently.">
<meta name="keywords" content="pytorch, pytorch ignite, ignite, engine, events, handlers, metrics">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#ee4c2c">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@pytorch_ignite">
<meta name="twitter:creator" content="@pytorch_ignite">
<meta name="twitter:description" content="High-level library to help with training and evaluating neural networks in PyTorch flexibly and transparently.">
<meta name="twitter:title" content="ignite.metrics — PyTorch-Ignite v0.5.1 Documentation">
<meta name="twitter:image" content="https://raw.githubusercontent.com/pytorch/ignite/master/assets/logo/ignite_logo.png">
<meta name="twitter:image:alt" content="PyTorch-Ignite logo">
<meta property="og:title" content="ignite.metrics — PyTorch-Ignite v0.5.1 Documentation">
<meta property="og:type" content="website">
<meta property="og:url" content="https://pytorch.org/ignite/">
<meta property="og:site_name" content="PyTorch-Ignite">
<meta property="og:image" content="https://raw.githubusercontent.com/pytorch/ignite/master/assets/logo/ignite_logo.png">
<meta property="og:image:alt" content="PyTorch-Ignite logo">
<meta property="og:description" content="High-level library to help with training and evaluating neural networks in PyTorch flexibly and transparently.">
<link rel="preconnect" href="https://BH4D9OD16A-dsn.algolia.net" crossorigin />
<title>ignite.metrics — PyTorch-Ignite v0.5.1 Documentation</title>
<link rel="shortcut icon" type="image/svg+xml" href="_static/ignite_logomark.svg"/>
<link rel="canonical" href="https://pytorch.org/ignite/metrics.html"/>
<link rel="preload" href="_static/css/theme.css" as="style" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!-- <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> -->
<link rel="preload" href="_static/pygments.css" as="style" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="preload" href="_static/css/theme.css" as="style" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="preload" href="_static/copybutton.css" as="style" />
<link rel="stylesheet" href="_static/copybutton.css" type="text/css" />
<link rel="preload" href="_static/togglebutton.css" as="style" />
<link rel="stylesheet" href="_static/togglebutton.css" type="text/css" />
<link rel="preload" href="_static/banner.css" as="style" />
<link rel="stylesheet" href="_static/banner.css" type="text/css" />
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" as="style" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" type="text/css" />
<link rel="preload" href="_static/katex-math.css" as="style" />
<link rel="stylesheet" href="_static/katex-math.css" type="text/css" />
<link rel="preload" href="_static/sphinx-design.5ea377869091fd0449014c60fc090103.min.css" as="style" />
<link rel="stylesheet" href="_static/sphinx-design.5ea377869091fd0449014c60fc090103.min.css" type="text/css" />
<link rel="preload" href="_static/css/ignite_theme.css" as="style" />
<link rel="stylesheet" href="_static/css/ignite_theme.css" type="text/css" />
<link rel="preload" href="https://cdn.jsdelivr.net/npm/@docsearch/css@3" as="style" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@docsearch/css@3" type="text/css" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Average" href="generated/ignite.metrics.Average.html" />
<link rel="prev" title="MultiStepStateScheduler" href="generated/ignite.handlers.state_param_scheduler.MultiStepStateScheduler.html" />
<!-- katex links / this needs to be loaded before fonts.html -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" crossorigin="anonymous">
<script async src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" crossorigin="anonymous"></script>
<!-- Preload the theme fonts -->
<link rel="preload" href="_static/fonts/FreightSans/freight-sans-book.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="_static/fonts/FreightSans/freight-sans-medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="_static/fonts/IBMPlexMono/IBMPlexMono-Medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="_static/fonts/FreightSans/freight-sans-bold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="_static/fonts/FreightSans/freight-sans-medium-italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="_static/fonts/IBMPlexMono/IBMPlexMono-SemiBold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="_static/fonts/IBMPlexMono/IBMPlexMono-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<!-- Preload the katex fonts -->
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Math-Italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-Bold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size1-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size4-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size2-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size3-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Caligraphic-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-5FELLLFHCP"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-5FELLLFHCP');
</script>
</head>
<div class="container-fluid header-holder tutorials-header" id="header-holder">
<div class="container">
<a class="header-logo" href="/ignite" aria-label="PyTorch-Ignite"></a>
<div class="header-container">
<div class="main-menu">
<ul>
<li>
<a href="https://pytorch-ignite.ai/tutorials/beginner/01-getting-started/">Quickstart</a>
</li>
<li>
<a href="https://pytorch-ignite.ai/concepts/">Concepts</a>
</li>
<!-- <li>
<a href="https://pytorch-ignite.ai/tutorials/beginner/01-getting-started/#complete-code">Examples</a>
</li> -->
<li>
<a href="https://pytorch-ignite.ai/how-to-guides/">FAQ</a>
</li>
<li>
<a href="https://github.com/pytorch/ignite" target="_blank" rel="noopener noreferrer">GitHub</a>
</li>
<li>
<a href="https://pytorch-ignite.ai/about/community/">About us</a>
</li>
<li>
<a href="https://pytorch-ignite.ai">⊳ pytorch-ignite.ai</a>
</li>
</ul>
</div>
<!-- <a class="main-menu-open-button" href="#" data-behavior="open-mobile-menu"></a> -->
</div>
</div>
</div>
<body class="pytorch-body">
<div class="table-of-contents-link-wrapper">
<span>Table of Contents</span>
<div class="toggle-table-of-contents" data-behavior="toggle-table-of-contents"></div>
</div>
<nav data-toggle="wy-nav-shift" class="pytorch-left-menu" id="pytorch-left-menu">
<div class="pytorch-side-scroll">
<div class="pytorch-menu pytorch-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<div class="pytorch-left-menu-search">
<div class="version">
v0.5.1
</div>
<div id="docsearch"></div>
</div>
<p class="caption" role="heading"><span class="caption-text">Package Reference</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="engine.html">ignite.engine</a></li>
<li class="toctree-l1"><a class="reference internal" href="handlers.html">ignite.handlers</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">ignite.metrics</a></li>
<li class="toctree-l1"><a class="reference internal" href="distributed.html">ignite.distributed</a></li>
<li class="toctree-l1"><a class="reference internal" href="exceptions.html">ignite.exceptions</a></li>
<li class="toctree-l1"><a class="reference internal" href="utils.html">ignite.utils</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Contrib Package Reference</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="contrib/engines.html">ignite.contrib.engines</a></li>
<li class="toctree-l1"><a class="reference internal" href="contrib/metrics.html">ignite.contrib.metrics</a></li>
<li class="toctree-l1"><a class="reference internal" href="contrib/handlers.html">ignite.contrib.handlers</a></li>
</ul>
</div>
</div>
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="versions">
<span class="rst-current-version" data-toggle="rst-current-version">
<span class="fa fa-book"> Other Versions</span>
v: v0.5.1
<span class="fa fa-caret-down"></span>
</span>
<div class="rst-other-versions">
<dl>
<dt>Tags</dt>
<dd><a href="v0.3.0/metrics.html">v0.3.0</a></dd>
<dd><a href="v0.4.0.post1/metrics.html">v0.4.0.post1</a></dd>
<dd><a href="v0.4.1/metrics.html">v0.4.1</a></dd>
<dd><a href="v0.4.10/metrics.html">v0.4.10</a></dd>
<dd><a href="v0.4.11/metrics.html">v0.4.11</a></dd>
<dd><a href="v0.4.12/metrics.html">v0.4.12</a></dd>
<dd><a href="v0.4.13/metrics.html">v0.4.13</a></dd>
<dd><a href="v0.4.2/metrics.html">v0.4.2</a></dd>
<dd><a href="v0.4.3/metrics.html">v0.4.3</a></dd>
<dd><a href="v0.4.4.post1/metrics.html">v0.4.4.post1</a></dd>
<dd><a href="v0.4.5/metrics.html">v0.4.5</a></dd>
<dd><a href="v0.4.6/metrics.html">v0.4.6</a></dd>
<dd><a href="v0.4.7/metrics.html">v0.4.7</a></dd>
<dd><a href="v0.4.8/metrics.html">v0.4.8</a></dd>
<dd><a href="v0.4.9/metrics.html">v0.4.9</a></dd>
<dd><a href="v0.4rc.0.post1/metrics.html">v0.4rc.0.post1</a></dd>
<dd><a href="v0.5.0.post2/metrics.html">v0.5.0.post2</a></dd>
<dd><a href="v0.5.1/metrics.html">v0.5.1</a></dd>
</dl>
<dl>
<dt>Branches</dt>
<dd><a href="master/metrics.html">master</a></dd>
</dl>
</div>
</div>
</nav>
<div class="pytorch-container">
<div class="pytorch-page-level-bar" id="pytorch-page-level-bar">
<div class="pytorch-breadcrumbs-wrapper">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="pytorch-breadcrumbs">
<li>
<a href="index.html">
Docs
</a> >
</li>
<li>ignite.metrics</li>
<li class="pytorch-breadcrumbs-aside">
<a href="_sources/metrics.rst.txt" rel="nofollow"><img src="_static/images/view-page-source-icon.svg"></a>
</li>
</ul>
</div>
</div>
<div class="pytorch-shortcuts-wrapper" id="pytorch-shortcuts-wrapper">
Shortcuts
</div>
</div>
<section data-toggle="wy-nav-shift" id="pytorch-content-wrap" class="pytorch-content-wrap">
<div class="pytorch-content-left">
<div class="rst-content">
<div role="main" class="main-content" itemscope="itemscope" itemtype="http://schema.org/Article">
<article itemprop="articleBody" id="pytorch-article" class="pytorch-article">
<section id="ignite-metrics">
<h1>ignite.metrics<a class="headerlink" href="#ignite-metrics" title="Permalink to this heading">#</a></h1>
<p>Metrics provide a way to compute various quantities of interest in an online
fashion without having to store the entire output history of a model.</p>
<section id="attach-engine-api">
<span id="attach-engine"></span><h2>Attach Engine API<a class="headerlink" href="#attach-engine-api" title="Permalink to this heading">#</a></h2>
<p>The metrics as stated above are computed in a online fashion, which means that the metric instance accumulates some internal counters on
each iteration and metric value is computed once the epoch is ended. Internal counters are reset after every epoch. In practice, this is done with the
help of three methods: <a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.reset" title="ignite.metrics.metric.Metric.reset"><code class="xref py py-meth docutils literal notranslate"><span class="pre">reset()</span></code></a>, <a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.update" title="ignite.metrics.metric.Metric.update"><code class="xref py py-meth docutils literal notranslate"><span class="pre">update()</span></code></a> and <a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.compute" title="ignite.metrics.metric.Metric.compute"><code class="xref py py-meth docutils literal notranslate"><span class="pre">compute()</span></code></a>.</p>
<p>Therefore, a user needs to attach the metric instance to the engine so that the above three methods can be triggered on execution of certain <a class="reference internal" href="generated/ignite.engine.events.Events.html#ignite.engine.events.Events" title="ignite.engine.events.Events"><code class="xref py py-class docutils literal notranslate"><span class="pre">Events</span></code></a>.
The <a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.reset" title="ignite.metrics.metric.Metric.reset"><code class="xref py py-meth docutils literal notranslate"><span class="pre">reset()</span></code></a> method is triggered on <code class="docutils literal notranslate"><span class="pre">EPOCH_STARTED</span></code> event and it is responsible to reset the metric to its initial state. The <a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.update" title="ignite.metrics.metric.Metric.update"><code class="xref py py-meth docutils literal notranslate"><span class="pre">update()</span></code></a> method is triggered
on <code class="docutils literal notranslate"><span class="pre">ITERATION_COMPLETED</span></code> event as it updates the state of the metric using the passed batch output. And <a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.compute" title="ignite.metrics.metric.Metric.compute"><code class="xref py py-meth docutils literal notranslate"><span class="pre">compute()</span></code></a> is triggered on <code class="docutils literal notranslate"><span class="pre">EPOCH_COMPLETED</span></code>
event. It computes the metric based on its accumulated states. The metric value is computed using the output of the engine’s <code class="docutils literal notranslate"><span class="pre">process_function</span></code>:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">ignite.engine</span><span class="w"> </span><span class="kn">import</span> <span class="n">Engine</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">ignite.metrics</span><span class="w"> </span><span class="kn">import</span> <span class="n">Accuracy</span>
<span class="k">def</span><span class="w"> </span><span class="nf">process_function</span><span class="p">(</span><span class="n">engine</span><span class="p">,</span> <span class="n">batch</span><span class="p">):</span>
<span class="c1"># ...</span>
<span class="k">return</span> <span class="n">y_pred</span><span class="p">,</span> <span class="n">y</span>
<span class="n">engine</span> <span class="o">=</span> <span class="n">Engine</span><span class="p">(</span><span class="n">process_function</span><span class="p">)</span>
<span class="n">metric</span> <span class="o">=</span> <span class="n">Accuracy</span><span class="p">()</span>
<span class="n">metric</span><span class="o">.</span><span class="n">attach</span><span class="p">(</span><span class="n">engine</span><span class="p">,</span> <span class="s2">"accuracy"</span><span class="p">)</span>
<span class="c1"># ...</span>
<span class="n">state</span> <span class="o">=</span> <span class="n">engine</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Accuracy: </span><span class="si">{</span><span class="n">state</span><span class="o">.</span><span class="n">metrics</span><span class="p">[</span><span class="s1">'accuracy'</span><span class="p">]</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
</pre></div>
</div>
<p>If the engine’s output is not in the format <code class="docutils literal notranslate"><span class="pre">(y_pred,</span> <span class="pre">y)</span></code> or <code class="docutils literal notranslate"><span class="pre">{'y_pred':</span> <span class="pre">y_pred,</span> <span class="pre">'y':</span> <span class="pre">y,</span> <span class="pre">...}</span></code>, the user can
use the <code class="docutils literal notranslate"><span class="pre">output_transform</span></code> argument to transform it:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">ignite.engine</span><span class="w"> </span><span class="kn">import</span> <span class="n">Engine</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">ignite.metrics</span><span class="w"> </span><span class="kn">import</span> <span class="n">Accuracy</span>
<span class="k">def</span><span class="w"> </span><span class="nf">process_function</span><span class="p">(</span><span class="n">engine</span><span class="p">,</span> <span class="n">batch</span><span class="p">):</span>
<span class="c1"># ...</span>
<span class="k">return</span> <span class="p">{</span><span class="s1">'y_pred'</span><span class="p">:</span> <span class="n">y_pred</span><span class="p">,</span> <span class="s1">'y_true'</span><span class="p">:</span> <span class="n">y</span><span class="p">,</span> <span class="o">...</span><span class="p">}</span>
<span class="n">engine</span> <span class="o">=</span> <span class="n">Engine</span><span class="p">(</span><span class="n">process_function</span><span class="p">)</span>
<span class="k">def</span><span class="w"> </span><span class="nf">output_transform</span><span class="p">(</span><span class="n">output</span><span class="p">):</span>
<span class="c1"># `output` variable is returned by above `process_function`</span>
<span class="n">y_pred</span> <span class="o">=</span> <span class="n">output</span><span class="p">[</span><span class="s1">'y_pred'</span><span class="p">]</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">output</span><span class="p">[</span><span class="s1">'y_true'</span><span class="p">]</span>
<span class="k">return</span> <span class="n">y_pred</span><span class="p">,</span> <span class="n">y</span> <span class="c1"># output format is according to `Accuracy` docs</span>
<span class="n">metric</span> <span class="o">=</span> <span class="n">Accuracy</span><span class="p">(</span><span class="n">output_transform</span><span class="o">=</span><span class="n">output_transform</span><span class="p">)</span>
<span class="n">metric</span><span class="o">.</span><span class="n">attach</span><span class="p">(</span><span class="n">engine</span><span class="p">,</span> <span class="s2">"accuracy"</span><span class="p">)</span>
<span class="c1"># ...</span>
<span class="n">state</span> <span class="o">=</span> <span class="n">engine</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Accuracy: </span><span class="si">{</span><span class="n">state</span><span class="o">.</span><span class="n">metrics</span><span class="p">[</span><span class="s1">'accuracy'</span><span class="p">]</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Please, be careful when using <code class="docutils literal notranslate"><span class="pre">lambda</span></code> functions to setup multiple <code class="docutils literal notranslate"><span class="pre">output_transform</span></code> for multiple metrics</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Wrong</span>
<span class="c1"># metrics_group = [Accuracy(output_transform=lambda output: output[name]) for name in names]</span>
<span class="c1"># As lambda can not store `name` and all `output_transform` will use the last `name`</span>
<span class="c1"># A correct way. For example, using functools.partial</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">functools</span><span class="w"> </span><span class="kn">import</span> <span class="n">partial</span>
<span class="k">def</span><span class="w"> </span><span class="nf">ot_func</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
<span class="k">return</span> <span class="n">output</span><span class="p">[</span><span class="n">name</span><span class="p">]</span>
<span class="n">metrics_group</span> <span class="o">=</span> <span class="p">[</span><span class="n">Accuracy</span><span class="p">(</span><span class="n">output_transform</span><span class="o">=</span><span class="n">partial</span><span class="p">(</span><span class="n">ot_func</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">))</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">names</span><span class="p">]</span>
</pre></div>
</div>
<p>For more details, see <a class="reference external" href="https://discuss.pytorch.org/t/evaluate-multiple-models-with-one-evaluator-results-weird-metrics/96695">here</a></p>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Most of implemented metrics are adapted to distributed computations and reduce their internal states across supported
devices before computing metric value. This can be helpful to run the evaluation on multiple nodes/GPU instances/TPUs
with a distributed data sampler. Following code snippet shows in detail how to use metrics:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">device</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"cuda:</span><span class="si">{</span><span class="n">local_rank</span><span class="si">}</span><span class="s2">"</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">nn</span><span class="o">.</span><span class="n">parallel</span><span class="o">.</span><span class="n">DistributedDataParallel</span><span class="p">(</span><span class="n">model</span><span class="p">,</span>
<span class="n">device_ids</span><span class="o">=</span><span class="p">[</span><span class="n">local_rank</span><span class="p">,</span> <span class="p">],</span>
<span class="n">output_device</span><span class="o">=</span><span class="n">local_rank</span><span class="p">)</span>
<span class="n">test_sampler</span> <span class="o">=</span> <span class="n">DistributedSampler</span><span class="p">(</span><span class="n">test_dataset</span><span class="p">)</span>
<span class="n">test_loader</span> <span class="o">=</span> <span class="n">DataLoader</span><span class="p">(</span>
<span class="n">test_dataset</span><span class="p">,</span>
<span class="n">batch_size</span><span class="o">=</span><span class="n">batch_size</span><span class="p">,</span>
<span class="n">sampler</span><span class="o">=</span><span class="n">test_sampler</span><span class="p">,</span>
<span class="n">num_workers</span><span class="o">=</span><span class="n">num_workers</span><span class="p">,</span>
<span class="n">pin_memory</span><span class="o">=</span><span class="kc">True</span>
<span class="p">)</span>
<span class="n">evaluator</span> <span class="o">=</span> <span class="n">create_supervised_evaluator</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">metrics</span><span class="o">=</span><span class="p">{</span><span class="s1">'accuracy'</span><span class="p">:</span> <span class="n">Accuracy</span><span class="p">()},</span> <span class="n">device</span><span class="o">=</span><span class="n">device</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Metrics cannot be serialized using <cite>pickle</cite> module because the implementation is based on lambda functions.
Therefore, use the third party library <cite>dill</cite> to overcome the limitation of <cite>pickle</cite>.</p>
</div>
</section>
<section id="reset-update-compute-api">
<h2>Reset, Update, Compute API<a class="headerlink" href="#reset-update-compute-api" title="Permalink to this heading">#</a></h2>
<p>User can also call directly the following methods on the metric:</p>
<ul class="simple">
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.reset" title="ignite.metrics.metric.Metric.reset"><code class="xref py py-meth docutils literal notranslate"><span class="pre">reset()</span></code></a> : resets internal variables and accumulators</p></li>
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.update" title="ignite.metrics.metric.Metric.update"><code class="xref py py-meth docutils literal notranslate"><span class="pre">update()</span></code></a> : updates internal variables and accumulators with provided batch output <code class="docutils literal notranslate"><span class="pre">(y_pred,</span> <span class="pre">y)</span></code></p></li>
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.compute" title="ignite.metrics.metric.Metric.compute"><code class="xref py py-meth docutils literal notranslate"><span class="pre">compute()</span></code></a> : computes custom metric and return the result</p></li>
</ul>
<p>This API gives a more fine-grained/custom usage on how to compute a metric. For example:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">ignite.metrics</span><span class="w"> </span><span class="kn">import</span> <span class="n">Precision</span>
<span class="c1"># Define the metric</span>
<span class="n">precision</span> <span class="o">=</span> <span class="n">Precision</span><span class="p">()</span>
<span class="c1"># Start accumulation:</span>
<span class="k">for</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="ow">in</span> <span class="n">data</span><span class="p">:</span>
<span class="n">y_pred</span> <span class="o">=</span> <span class="n">model</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="n">precision</span><span class="o">.</span><span class="n">update</span><span class="p">((</span><span class="n">y_pred</span><span class="p">,</span> <span class="n">y</span><span class="p">))</span>
<span class="c1"># Compute the result</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Precision: "</span><span class="p">,</span> <span class="n">precision</span><span class="o">.</span><span class="n">compute</span><span class="p">())</span>
<span class="c1"># Reset metric</span>
<span class="n">precision</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
<span class="c1"># Start new accumulation:</span>
<span class="k">for</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="ow">in</span> <span class="n">data</span><span class="p">:</span>
<span class="n">y_pred</span> <span class="o">=</span> <span class="n">model</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="n">precision</span><span class="o">.</span><span class="n">update</span><span class="p">((</span><span class="n">y_pred</span><span class="p">,</span> <span class="n">y</span><span class="p">))</span>
<span class="c1"># Compute new result</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Precision: "</span><span class="p">,</span> <span class="n">precision</span><span class="o">.</span><span class="n">compute</span><span class="p">())</span>
</pre></div>
</div>
</section>
<section id="metric-arithmetics">
<h2>Metric arithmetics<a class="headerlink" href="#metric-arithmetics" title="Permalink to this heading">#</a></h2>
<p>Metrics could be combined together to form new metrics. This could be done through arithmetics, such
as <code class="docutils literal notranslate"><span class="pre">metric1</span> <span class="pre">+</span> <span class="pre">metric2</span></code>, use PyTorch operators, such as <code class="docutils literal notranslate"><span class="pre">(metric1</span> <span class="pre">+</span> <span class="pre">metric2).pow(2).mean()</span></code>,
or use a lambda function, such as <code class="docutils literal notranslate"><span class="pre">MetricsLambda(lambda</span> <span class="pre">a,</span> <span class="pre">b:</span> <span class="pre">torch.mean(a</span> <span class="pre">+</span> <span class="pre">b),</span> <span class="pre">metric1,</span> <span class="pre">metric2)</span></code>.</p>
<p>For example:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">ignite.metrics</span><span class="w"> </span><span class="kn">import</span> <span class="n">Precision</span><span class="p">,</span> <span class="n">Recall</span>
<span class="n">precision</span> <span class="o">=</span> <span class="n">Precision</span><span class="p">(</span><span class="n">average</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">recall</span> <span class="o">=</span> <span class="n">Recall</span><span class="p">(</span><span class="n">average</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">F1</span> <span class="o">=</span> <span class="p">(</span><span class="n">precision</span> <span class="o">*</span> <span class="n">recall</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">/</span> <span class="p">(</span><span class="n">precision</span> <span class="o">+</span> <span class="n">recall</span><span class="p">))</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This example computes the mean of F1 across classes. To combine
precision and recall to get F1 or other F metrics, we have to be careful
that <code class="docutils literal notranslate"><span class="pre">average=False</span></code>, i.e. to use the unaveraged precision and recall,
otherwise we will not be computing F-beta metrics.</p>
</div>
<p>Metrics also support indexing operation (if metric’s result is a vector/matrix/tensor). For example, this can be useful to compute mean metric (e.g. precision, recall or IoU) ignoring the background:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">ignite.metrics</span><span class="w"> </span><span class="kn">import</span> <span class="n">ConfusionMatrix</span>
<span class="n">cm</span> <span class="o">=</span> <span class="n">ConfusionMatrix</span><span class="p">(</span><span class="n">num_classes</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
<span class="n">iou_metric</span> <span class="o">=</span> <span class="n">IoU</span><span class="p">(</span><span class="n">cm</span><span class="p">)</span>
<span class="n">iou_no_bg_metric</span> <span class="o">=</span> <span class="n">iou_metric</span><span class="p">[:</span><span class="mi">9</span><span class="p">]</span> <span class="c1"># We assume that the background index is 9</span>
<span class="n">mean_iou_no_bg_metric</span> <span class="o">=</span> <span class="n">iou_no_bg_metric</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span>
<span class="c1"># mean_iou_no_bg_metric.compute() -> tensor(0.12345)</span>
</pre></div>
</div>
</section>
<section id="how-to-create-a-custom-metric">
<h2>How to create a custom metric<a class="headerlink" href="#how-to-create-a-custom-metric" title="Permalink to this heading">#</a></h2>
<p>To create a custom metric one needs to create a new class inheriting from <a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric" title="ignite.metrics.metric.Metric"><code class="xref py py-class docutils literal notranslate"><span class="pre">Metric</span></code></a> and override
three methods :</p>
<ul class="simple">
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.reset" title="ignite.metrics.metric.Metric.reset"><code class="xref py py-meth docutils literal notranslate"><span class="pre">reset()</span></code></a> : resets internal variables and accumulators</p></li>
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.update" title="ignite.metrics.metric.Metric.update"><code class="xref py py-meth docutils literal notranslate"><span class="pre">update()</span></code></a> : updates internal variables and accumulators with provided batch output <code class="docutils literal notranslate"><span class="pre">(y_pred,</span> <span class="pre">y)</span></code></p></li>
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.compute" title="ignite.metrics.metric.Metric.compute"><code class="xref py py-meth docutils literal notranslate"><span class="pre">compute()</span></code></a> : computes custom metric and return the result</p></li>
</ul>
<p>For example, we would like to implement for illustration purposes a multi-class accuracy metric with some
specific condition (e.g. ignore user-defined classes):</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">ignite.metrics</span><span class="w"> </span><span class="kn">import</span> <span class="n">Metric</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">ignite.exceptions</span><span class="w"> </span><span class="kn">import</span> <span class="n">NotComputableError</span>
<span class="c1"># These decorators helps with distributed settings</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">ignite.metrics.metric</span><span class="w"> </span><span class="kn">import</span> <span class="n">sync_all_reduce</span><span class="p">,</span> <span class="n">reinit__is_reduced</span>
<span class="k">class</span><span class="w"> </span><span class="nc">CustomAccuracy</span><span class="p">(</span><span class="n">Metric</span><span class="p">):</span>
<span class="k">def</span><span class="w"> </span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ignored_class</span><span class="p">,</span> <span class="n">output_transform</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">,</span> <span class="n">device</span><span class="o">=</span><span class="s2">"cpu"</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ignored_class</span> <span class="o">=</span> <span class="n">ignored_class</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_num_correct</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_num_examples</span> <span class="o">=</span> <span class="kc">None</span>
<span class="nb">super</span><span class="p">(</span><span class="n">CustomAccuracy</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">output_transform</span><span class="o">=</span><span class="n">output_transform</span><span class="p">,</span> <span class="n">device</span><span class="o">=</span><span class="n">device</span><span class="p">)</span>
<span class="nd">@reinit__is_reduced</span>
<span class="k">def</span><span class="w"> </span><span class="nf">reset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_num_correct</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">tensor</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">device</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_num_examples</span> <span class="o">=</span> <span class="mi">0</span>
<span class="nb">super</span><span class="p">(</span><span class="n">CustomAccuracy</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
<span class="nd">@reinit__is_reduced</span>
<span class="k">def</span><span class="w"> </span><span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">output</span><span class="p">):</span>
<span class="n">y_pred</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">output</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">detach</span><span class="p">(),</span> <span class="n">output</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">detach</span><span class="p">()</span>
<span class="n">indices</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">y_pred</span><span class="p">,</span> <span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="n">mask</span> <span class="o">=</span> <span class="p">(</span><span class="n">y</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ignored_class</span><span class="p">)</span>
<span class="n">mask</span> <span class="o">&=</span> <span class="p">(</span><span class="n">indices</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ignored_class</span><span class="p">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="n">mask</span><span class="p">]</span>
<span class="n">indices</span> <span class="o">=</span> <span class="n">indices</span><span class="p">[</span><span class="n">mask</span><span class="p">]</span>
<span class="n">correct</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">eq</span><span class="p">(</span><span class="n">indices</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_num_correct</span> <span class="o">+=</span> <span class="n">torch</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">correct</span><span class="p">)</span><span class="o">.</span><span class="n">to</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_num_examples</span> <span class="o">+=</span> <span class="n">correct</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="nd">@sync_all_reduce</span><span class="p">(</span><span class="s2">"_num_examples"</span><span class="p">,</span> <span class="s2">"_num_correct:SUM"</span><span class="p">)</span>
<span class="k">def</span><span class="w"> </span><span class="nf">compute</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_num_examples</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">NotComputableError</span><span class="p">(</span><span class="s1">'CustomAccuracy must have at least one example before it can be computed.'</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_num_correct</span><span class="o">.</span><span class="n">item</span><span class="p">()</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">_num_examples</span>
</pre></div>
</div>
<p>We imported necessary classes as <a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric" title="ignite.metrics.metric.Metric"><code class="xref py py-class docutils literal notranslate"><span class="pre">Metric</span></code></a>, <a class="reference internal" href="exceptions.html#ignite.exceptions.NotComputableError" title="ignite.exceptions.NotComputableError"><code class="xref py py-class docutils literal notranslate"><span class="pre">NotComputableError</span></code></a> and
decorators to adapt the metric for distributed setting. In <code class="docutils literal notranslate"><span class="pre">reset</span></code> method, we reset internal variables <code class="docutils literal notranslate"><span class="pre">_num_correct</span></code>
and <code class="docutils literal notranslate"><span class="pre">_num_examples</span></code> which are used to compute the custom metric. In <code class="docutils literal notranslate"><span class="pre">updated</span></code> method we define how to update
the internal variables. And finally in <code class="docutils literal notranslate"><span class="pre">compute</span></code> method, we compute metric value.</p>
<p>Notice that <code class="docutils literal notranslate"><span class="pre">_num_correct</span></code> is a tensor, since in <code class="docutils literal notranslate"><span class="pre">update</span></code> we accumulate tensor values. <code class="docutils literal notranslate"><span class="pre">_num_examples</span></code> is a python
scalar since we accumulate normal integers. For differentiable metrics, you must detach the accumulated values before
adding them to the internal variables.</p>
<p>We can check this implementation in a simple case:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">torch</span>
<span class="n">torch</span><span class="o">.</span><span class="n">manual_seed</span><span class="p">(</span><span class="mi">8</span><span class="p">)</span>
<span class="n">m</span> <span class="o">=</span> <span class="n">CustomAccuracy</span><span class="p">(</span><span class="n">ignored_class</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="n">batch_size</span> <span class="o">=</span> <span class="mi">4</span>
<span class="n">num_classes</span> <span class="o">=</span> <span class="mi">5</span>
<span class="n">y_pred</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="n">batch_size</span><span class="p">,</span> <span class="n">num_classes</span><span class="p">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">num_classes</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="n">batch_size</span><span class="p">,</span> <span class="p">))</span>
<span class="n">m</span><span class="o">.</span><span class="n">update</span><span class="p">((</span><span class="n">y_pred</span><span class="p">,</span> <span class="n">y</span><span class="p">))</span>
<span class="n">res</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">compute</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">torch</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">y_pred</span><span class="p">,</span> <span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">))</span>
<span class="c1"># Out: tensor([2, 2, 2, 3]) tensor([2, 1, 0, 0])</span>
<span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">_num_correct</span><span class="p">,</span> <span class="n">m</span><span class="o">.</span><span class="n">_num_examples</span><span class="p">,</span> <span class="n">res</span><span class="p">)</span>
<span class="c1"># Out: 1 3 0.3333333333333333</span>
</pre></div>
</div>
</section>
<section id="metrics-and-its-usages">
<h2>Metrics and its usages<a class="headerlink" href="#metrics-and-its-usages" title="Permalink to this heading">#</a></h2>
<p>By default, <cite>Metrics</cite> are epoch-wise, it means</p>
<ul class="simple">
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.reset" title="ignite.metrics.metric.Metric.reset"><code class="xref py py-meth docutils literal notranslate"><span class="pre">reset()</span></code></a> is triggered every <code class="docutils literal notranslate"><span class="pre">EPOCH_STARTED</span></code> (See <a class="reference internal" href="generated/ignite.engine.events.Events.html#ignite.engine.events.Events" title="ignite.engine.events.Events"><code class="xref py py-class docutils literal notranslate"><span class="pre">Events</span></code></a>).</p></li>
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.update" title="ignite.metrics.metric.Metric.update"><code class="xref py py-meth docutils literal notranslate"><span class="pre">update()</span></code></a> is triggered every <code class="docutils literal notranslate"><span class="pre">ITERATION_COMPLETED</span></code>.</p></li>
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.compute" title="ignite.metrics.metric.Metric.compute"><code class="xref py py-meth docutils literal notranslate"><span class="pre">compute()</span></code></a> is triggered every <code class="docutils literal notranslate"><span class="pre">EPOCH_COMPLETED</span></code>.</p></li>
</ul>
<p>Usages can be user defined by creating a class inheriting for <a class="reference internal" href="#ignite.metrics.metric.MetricUsage" title="ignite.metrics.metric.MetricUsage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MetricUsage</span></code></a>. See the list below of usages.</p>
<section id="complete-list-of-usages">
<h3>Complete list of usages<a class="headerlink" href="#complete-list-of-usages" title="Permalink to this heading">#</a></h3>
<blockquote>
<div><ul class="simple">
<li><p><a class="reference internal" href="#ignite.metrics.metric.MetricUsage" title="ignite.metrics.metric.MetricUsage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MetricUsage</span></code></a></p></li>
<li><p><a class="reference internal" href="#ignite.metrics.metric.EpochWise" title="ignite.metrics.metric.EpochWise"><code class="xref py py-class docutils literal notranslate"><span class="pre">EpochWise</span></code></a></p></li>
<li><p><a class="reference internal" href="#ignite.metrics.metric.RunningEpochWise" title="ignite.metrics.metric.RunningEpochWise"><code class="xref py py-class docutils literal notranslate"><span class="pre">RunningEpochWise</span></code></a></p></li>
<li><p><a class="reference internal" href="#ignite.metrics.metric.BatchWise" title="ignite.metrics.metric.BatchWise"><code class="xref py py-class docutils literal notranslate"><span class="pre">BatchWise</span></code></a></p></li>
<li><p><a class="reference internal" href="#ignite.metrics.metric.RunningBatchWise" title="ignite.metrics.metric.RunningBatchWise"><code class="xref py py-class docutils literal notranslate"><span class="pre">RunningBatchWise</span></code></a></p></li>
<li><p><a class="reference internal" href="#ignite.metrics.metric.SingleEpochRunningBatchWise" title="ignite.metrics.metric.SingleEpochRunningBatchWise"><code class="xref py py-class docutils literal notranslate"><span class="pre">SingleEpochRunningBatchWise</span></code></a></p></li>
<li><p><a class="reference internal" href="#ignite.metrics.metric.BatchFiltered" title="ignite.metrics.metric.BatchFiltered"><code class="xref py py-class docutils literal notranslate"><span class="pre">BatchFiltered</span></code></a></p></li>
</ul>
</div></blockquote>
</section>
</section>
<section id="metrics-and-distributed-computations">
<h2>Metrics and distributed computations<a class="headerlink" href="#metrics-and-distributed-computations" title="Permalink to this heading">#</a></h2>
<p>In the above example, <code class="docutils literal notranslate"><span class="pre">CustomAccuracy</span></code> has <code class="docutils literal notranslate"><span class="pre">reset</span></code>, <code class="docutils literal notranslate"><span class="pre">update</span></code>, <code class="docutils literal notranslate"><span class="pre">compute</span></code> methods decorated
with <a class="reference internal" href="#ignite.metrics.metric.reinit__is_reduced" title="ignite.metrics.metric.reinit__is_reduced"><code class="xref py py-meth docutils literal notranslate"><span class="pre">reinit__is_reduced()</span></code></a>, <a class="reference internal" href="#ignite.metrics.metric.sync_all_reduce" title="ignite.metrics.metric.sync_all_reduce"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sync_all_reduce()</span></code></a>. The purpose of these features is to adapt metrics in distributed
computations on supported backend and devices (see <a class="reference internal" href="distributed.html"><span class="doc">ignite.distributed</span></a> for more details). More precisely, in the above
example we added <code class="docutils literal notranslate"><span class="pre">@sync_all_reduce("_num_examples",</span> <span class="pre">"_num_correct:SUM")</span></code> over <code class="docutils literal notranslate"><span class="pre">compute</span></code> method. This means that when <code class="docutils literal notranslate"><span class="pre">compute</span></code>
method is called, metric’s interal variables <code class="docutils literal notranslate"><span class="pre">self._num_examples</span></code> and <code class="docutils literal notranslate"><span class="pre">self._num_correct:SUM</span></code> are summed up over all participating
devices. We specify the reduction operation <code class="docutils literal notranslate"><span class="pre">self._num_correct:SUM</span></code> or we keep the default <code class="docutils literal notranslate"><span class="pre">self._num_examples</span></code> as the default is <code class="docutils literal notranslate"><span class="pre">SUM</span></code>.
We currently support four reduction operations (SUM, MAX, MIN, PRODUCT).
Therefore, once collected, these internal variables can be used to compute the final metric value.</p>
</section>
<section id="complete-list-of-metrics">
<h2>Complete list of metrics<a class="headerlink" href="#complete-list-of-metrics" title="Permalink to this heading">#</a></h2>
<table class="autosummary longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.Average.html#ignite.metrics.Average" title="ignite.metrics.Average"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Average</span></code></a></p></td>
<td><p>Helper class to compute arithmetic average of a single variable.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.GeometricAverage.html#ignite.metrics.GeometricAverage" title="ignite.metrics.GeometricAverage"><code class="xref py py-obj docutils literal notranslate"><span class="pre">GeometricAverage</span></code></a></p></td>
<td><p>Helper class to compute geometric average of a single variable.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.VariableAccumulation.html#ignite.metrics.VariableAccumulation" title="ignite.metrics.VariableAccumulation"><code class="xref py py-obj docutils literal notranslate"><span class="pre">VariableAccumulation</span></code></a></p></td>
<td><p>Single variable accumulator helper to compute (arithmetic, geometric, harmonic) average of a single variable.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.Accuracy.html#ignite.metrics.Accuracy" title="ignite.metrics.Accuracy"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Accuracy</span></code></a></p></td>
<td><p>Calculates the accuracy for binary, multiclass and multilabel data.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.confusion_matrix.ConfusionMatrix.html#ignite.metrics.confusion_matrix.ConfusionMatrix" title="ignite.metrics.confusion_matrix.ConfusionMatrix"><code class="xref py py-obj docutils literal notranslate"><span class="pre">confusion_matrix.ConfusionMatrix</span></code></a></p></td>
<td><p>Calculates confusion matrix for multi-class data.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.ClassificationReport.html#ignite.metrics.ClassificationReport" title="ignite.metrics.ClassificationReport"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ClassificationReport</span></code></a></p></td>
<td><p>Build a text report showing the main classification metrics.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.DiceCoefficient.html#ignite.metrics.DiceCoefficient" title="ignite.metrics.DiceCoefficient"><code class="xref py py-obj docutils literal notranslate"><span class="pre">DiceCoefficient</span></code></a></p></td>
<td><p>Calculates Dice Coefficient for a given <a class="reference internal" href="generated/ignite.metrics.confusion_matrix.ConfusionMatrix.html#ignite.metrics.confusion_matrix.ConfusionMatrix" title="ignite.metrics.confusion_matrix.ConfusionMatrix"><code class="xref py py-class docutils literal notranslate"><span class="pre">ConfusionMatrix</span></code></a> metric.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.JaccardIndex.html#ignite.metrics.JaccardIndex" title="ignite.metrics.JaccardIndex"><code class="xref py py-obj docutils literal notranslate"><span class="pre">JaccardIndex</span></code></a></p></td>
<td><p>Calculates the Jaccard Index using <a class="reference internal" href="generated/ignite.metrics.confusion_matrix.ConfusionMatrix.html#ignite.metrics.confusion_matrix.ConfusionMatrix" title="ignite.metrics.confusion_matrix.ConfusionMatrix"><code class="xref py py-class docutils literal notranslate"><span class="pre">ConfusionMatrix</span></code></a> metric.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.IoU.html#ignite.metrics.IoU" title="ignite.metrics.IoU"><code class="xref py py-obj docutils literal notranslate"><span class="pre">IoU</span></code></a></p></td>
<td><p>Calculates Intersection over Union using <a class="reference internal" href="generated/ignite.metrics.confusion_matrix.ConfusionMatrix.html#ignite.metrics.confusion_matrix.ConfusionMatrix" title="ignite.metrics.confusion_matrix.ConfusionMatrix"><code class="xref py py-class docutils literal notranslate"><span class="pre">ConfusionMatrix</span></code></a> metric.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.mIoU.html#ignite.metrics.mIoU" title="ignite.metrics.mIoU"><code class="xref py py-obj docutils literal notranslate"><span class="pre">mIoU</span></code></a></p></td>
<td><p>Calculates mean Intersection over Union using <a class="reference internal" href="generated/ignite.metrics.confusion_matrix.ConfusionMatrix.html#ignite.metrics.confusion_matrix.ConfusionMatrix" title="ignite.metrics.confusion_matrix.ConfusionMatrix"><code class="xref py py-class docutils literal notranslate"><span class="pre">ConfusionMatrix</span></code></a> metric.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.EpochMetric.html#ignite.metrics.EpochMetric" title="ignite.metrics.EpochMetric"><code class="xref py py-obj docutils literal notranslate"><span class="pre">EpochMetric</span></code></a></p></td>
<td><p>Class for metrics that should be computed on the entire output history of a model.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.Fbeta.html#ignite.metrics.Fbeta" title="ignite.metrics.Fbeta"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Fbeta</span></code></a></p></td>
<td><p>Calculates F-beta score.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.Frequency.html#ignite.metrics.Frequency" title="ignite.metrics.Frequency"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Frequency</span></code></a></p></td>
<td><p>Provides metrics for the number of examples processed per second.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.Loss.html#ignite.metrics.Loss" title="ignite.metrics.Loss"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Loss</span></code></a></p></td>
<td><p>Calculates the average loss according to the passed loss_fn.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.MeanAbsoluteError.html#ignite.metrics.MeanAbsoluteError" title="ignite.metrics.MeanAbsoluteError"><code class="xref py py-obj docutils literal notranslate"><span class="pre">MeanAbsoluteError</span></code></a></p></td>
<td><p>Calculates <a class="reference external" href="https://en.wikipedia.org/wiki/Mean_absolute_error">the mean absolute error</a>.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.MeanPairwiseDistance.html#ignite.metrics.MeanPairwiseDistance" title="ignite.metrics.MeanPairwiseDistance"><code class="xref py py-obj docutils literal notranslate"><span class="pre">MeanPairwiseDistance</span></code></a></p></td>
<td><p>Calculates the mean <a class="reference external" href="https://pytorch.org/docs/stable/generated/torch.nn.PairwiseDistance.html#torch.nn.PairwiseDistance" title="(in PyTorch v2.6)"><code class="xref py py-class docutils literal notranslate"><span class="pre">PairwiseDistance</span></code></a>.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.MeanSquaredError.html#ignite.metrics.MeanSquaredError" title="ignite.metrics.MeanSquaredError"><code class="xref py py-obj docutils literal notranslate"><span class="pre">MeanSquaredError</span></code></a></p></td>
<td><p>Calculates the <a class="reference external" href="https://en.wikipedia.org/wiki/Mean_squared_error">mean squared error</a>.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric" title="ignite.metrics.metric.Metric"><code class="xref py py-obj docutils literal notranslate"><span class="pre">metric.Metric</span></code></a></p></td>
<td><p>Base class for all Metrics.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.metric_group.MetricGroup.html#ignite.metrics.metric_group.MetricGroup" title="ignite.metrics.metric_group.MetricGroup"><code class="xref py py-obj docutils literal notranslate"><span class="pre">metric_group.MetricGroup</span></code></a></p></td>
<td><p>A class for grouping metrics so that user could manage them easier.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.metrics_lambda.MetricsLambda.html#ignite.metrics.metrics_lambda.MetricsLambda" title="ignite.metrics.metrics_lambda.MetricsLambda"><code class="xref py py-obj docutils literal notranslate"><span class="pre">metrics_lambda.MetricsLambda</span></code></a></p></td>
<td><p>Apply a function to other metrics to obtain a new metric.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.MultiLabelConfusionMatrix.html#ignite.metrics.MultiLabelConfusionMatrix" title="ignite.metrics.MultiLabelConfusionMatrix"><code class="xref py py-obj docutils literal notranslate"><span class="pre">MultiLabelConfusionMatrix</span></code></a></p></td>
<td><p>Calculates a confusion matrix for multi-labelled, multi-class data.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.MutualInformation.html#ignite.metrics.MutualInformation" title="ignite.metrics.MutualInformation"><code class="xref py py-obj docutils literal notranslate"><span class="pre">MutualInformation</span></code></a></p></td>
<td><p>Calculates the <a class="reference external" href="https://en.wikipedia.org/wiki/Mutual_information">mutual information</a> between input <span class="math"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>X</mi></mrow><annotation encoding="application/x-tex">X</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.07847em;">X</span></span></span></span></span> and prediction <span class="math"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>Y</mi></mrow><annotation encoding="application/x-tex">Y</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.22222em;">Y</span></span></span></span></span>.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.precision.Precision.html#ignite.metrics.precision.Precision" title="ignite.metrics.precision.Precision"><code class="xref py py-obj docutils literal notranslate"><span class="pre">precision.Precision</span></code></a></p></td>
<td><p>Calculates precision for binary, multiclass and multilabel data.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.PSNR.html#ignite.metrics.PSNR" title="ignite.metrics.PSNR"><code class="xref py py-obj docutils literal notranslate"><span class="pre">PSNR</span></code></a></p></td>
<td><p>Computes average <a class="reference external" href="https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio">Peak signal-to-noise ratio (PSNR)</a>.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.recall.Recall.html#ignite.metrics.recall.Recall" title="ignite.metrics.recall.Recall"><code class="xref py py-obj docutils literal notranslate"><span class="pre">recall.Recall</span></code></a></p></td>
<td><p>Calculates recall for binary, multiclass and multilabel data.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.RootMeanSquaredError.html#ignite.metrics.RootMeanSquaredError" title="ignite.metrics.RootMeanSquaredError"><code class="xref py py-obj docutils literal notranslate"><span class="pre">RootMeanSquaredError</span></code></a></p></td>
<td><p>Calculates the <a class="reference external" href="https://en.wikipedia.org/wiki/Root-mean-square_deviation">root mean squared error</a>.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.RunningAverage.html#ignite.metrics.RunningAverage" title="ignite.metrics.RunningAverage"><code class="xref py py-obj docutils literal notranslate"><span class="pre">RunningAverage</span></code></a></p></td>
<td><p>Compute running average of a metric or the output of process function.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.SSIM.html#ignite.metrics.SSIM" title="ignite.metrics.SSIM"><code class="xref py py-obj docutils literal notranslate"><span class="pre">SSIM</span></code></a></p></td>
<td><p>Computes Structural Similarity Index Measure</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.TopKCategoricalAccuracy.html#ignite.metrics.TopKCategoricalAccuracy" title="ignite.metrics.TopKCategoricalAccuracy"><code class="xref py py-obj docutils literal notranslate"><span class="pre">TopKCategoricalAccuracy</span></code></a></p></td>
<td><p>Calculates the top-k categorical accuracy.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.Bleu.html#ignite.metrics.Bleu" title="ignite.metrics.Bleu"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Bleu</span></code></a></p></td>
<td><p>Calculates the <a class="reference external" href="https://en.wikipedia.org/wiki/BLEU">BLEU score</a>.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.Rouge.html#ignite.metrics.Rouge" title="ignite.metrics.Rouge"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Rouge</span></code></a></p></td>
<td><p>Calculates the Rouge score for multiples Rouge-N and Rouge-L metrics.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.RougeL.html#ignite.metrics.RougeL" title="ignite.metrics.RougeL"><code class="xref py py-obj docutils literal notranslate"><span class="pre">RougeL</span></code></a></p></td>
<td><p>Calculates the Rouge-L score.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.RougeN.html#ignite.metrics.RougeN" title="ignite.metrics.RougeN"><code class="xref py py-obj docutils literal notranslate"><span class="pre">RougeN</span></code></a></p></td>
<td><p>Calculates the Rouge-N score.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.InceptionScore.html#ignite.metrics.InceptionScore" title="ignite.metrics.InceptionScore"><code class="xref py py-obj docutils literal notranslate"><span class="pre">InceptionScore</span></code></a></p></td>
<td><p>Calculates Inception Score.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.FID.html#ignite.metrics.FID" title="ignite.metrics.FID"><code class="xref py py-obj docutils literal notranslate"><span class="pre">FID</span></code></a></p></td>
<td><p>Calculates Frechet Inception Distance.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.CosineSimilarity.html#ignite.metrics.CosineSimilarity" title="ignite.metrics.CosineSimilarity"><code class="xref py py-obj docutils literal notranslate"><span class="pre">CosineSimilarity</span></code></a></p></td>
<td><p>Calculates the mean of the <a class="reference external" href="https://en.wikipedia.org/wiki/Cosine_similarity">cosine similarity</a>.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.Entropy.html#ignite.metrics.Entropy" title="ignite.metrics.Entropy"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Entropy</span></code></a></p></td>
<td><p>Calculates the mean of <a class="reference external" href="https://en.wikipedia.org/wiki/Entropy_(information_theory)">entropy</a>.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.KLDivergence.html#ignite.metrics.KLDivergence" title="ignite.metrics.KLDivergence"><code class="xref py py-obj docutils literal notranslate"><span class="pre">KLDivergence</span></code></a></p></td>
<td><p>Calculates the mean of <a class="reference external" href="https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence">Kullback-Leibler (KL) divergence</a>.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.JSDivergence.html#ignite.metrics.JSDivergence" title="ignite.metrics.JSDivergence"><code class="xref py py-obj docutils literal notranslate"><span class="pre">JSDivergence</span></code></a></p></td>
<td><p>Calculates the mean of <a class="reference external" href="https://en.wikipedia.org/wiki/Jensen%E2%80%93Shannon_divergence">Jensen-Shannon (JS) divergence</a>.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.MaximumMeanDiscrepancy.html#ignite.metrics.MaximumMeanDiscrepancy" title="ignite.metrics.MaximumMeanDiscrepancy"><code class="xref py py-obj docutils literal notranslate"><span class="pre">MaximumMeanDiscrepancy</span></code></a></p></td>
<td><p>Calculates the mean of <a class="reference external" href="https://www.onurtunali.com/ml/2019/03/08/maximum-mean-discrepancy-in-machine-learning.html">maximum mean discrepancy (MMD)</a>.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.AveragePrecision.html#ignite.metrics.AveragePrecision" title="ignite.metrics.AveragePrecision"><code class="xref py py-obj docutils literal notranslate"><span class="pre">AveragePrecision</span></code></a></p></td>
<td><p>Computes Average Precision accumulating predictions and the ground-truth during an epoch and applying <a class="reference external" href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.average_precision_score.html#sklearn.metrics.average_precision_score">sklearn.metrics.average_precision_score</a> .</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.CohenKappa.html#ignite.metrics.CohenKappa" title="ignite.metrics.CohenKappa"><code class="xref py py-obj docutils literal notranslate"><span class="pre">CohenKappa</span></code></a></p></td>
<td><p>Compute different types of Cohen's Kappa: Non-Wieghted, Linear, Quadratic.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.GpuInfo.html#ignite.metrics.GpuInfo" title="ignite.metrics.GpuInfo"><code class="xref py py-obj docutils literal notranslate"><span class="pre">GpuInfo</span></code></a></p></td>
<td><p>Provides GPU information: a) used memory percentage, b) gpu utilization percentage values as Metric on each iterations.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.PrecisionRecallCurve.html#ignite.metrics.PrecisionRecallCurve" title="ignite.metrics.PrecisionRecallCurve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">PrecisionRecallCurve</span></code></a></p></td>
<td><p>Compute precision-recall pairs for different probability thresholds for binary classification task by accumulating predictions and the ground-truth during an epoch and applying <a class="reference external" href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_recall_curve.html#sklearn.metrics.precision_recall_curve">sklearn.metrics.precision_recall_curve</a> .</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.RocCurve.html#ignite.metrics.RocCurve" title="ignite.metrics.RocCurve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">RocCurve</span></code></a></p></td>
<td><p>Compute Receiver operating characteristic (ROC) for binary classification task by accumulating predictions and the ground-truth during an epoch and applying <a class="reference external" href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_curve.html#sklearn.metrics.roc_curve">sklearn.metrics.roc_curve</a> .</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.ROC_AUC.html#ignite.metrics.ROC_AUC" title="ignite.metrics.ROC_AUC"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ROC_AUC</span></code></a></p></td>
<td><p>Computes Area Under the Receiver Operating Characteristic Curve (ROC AUC) accumulating predictions and the ground-truth during an epoch and applying <a class="reference external" href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_auc_score.html#sklearn.metrics.roc_auc_score">sklearn.metrics.roc_auc_score</a> .</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.regression.CanberraMetric.html#ignite.metrics.regression.CanberraMetric" title="ignite.metrics.regression.CanberraMetric"><code class="xref py py-obj docutils literal notranslate"><span class="pre">regression.CanberraMetric</span></code></a></p></td>
<td><p>Calculates the Canberra Metric.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.regression.FractionalAbsoluteError.html#ignite.metrics.regression.FractionalAbsoluteError" title="ignite.metrics.regression.FractionalAbsoluteError"><code class="xref py py-obj docutils literal notranslate"><span class="pre">regression.FractionalAbsoluteError</span></code></a></p></td>
<td><p>Calculates the Fractional Absolute Error.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.regression.FractionalBias.html#ignite.metrics.regression.FractionalBias" title="ignite.metrics.regression.FractionalBias"><code class="xref py py-obj docutils literal notranslate"><span class="pre">regression.FractionalBias</span></code></a></p></td>
<td><p>Calculates the Fractional Bias.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.regression.GeometricMeanAbsoluteError.html#ignite.metrics.regression.GeometricMeanAbsoluteError" title="ignite.metrics.regression.GeometricMeanAbsoluteError"><code class="xref py py-obj docutils literal notranslate"><span class="pre">regression.GeometricMeanAbsoluteError</span></code></a></p></td>
<td><p>Calculates the Geometric Mean Absolute Error.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.regression.GeometricMeanRelativeAbsoluteError.html#ignite.metrics.regression.GeometricMeanRelativeAbsoluteError" title="ignite.metrics.regression.GeometricMeanRelativeAbsoluteError"><code class="xref py py-obj docutils literal notranslate"><span class="pre">regression.GeometricMeanRelativeAbsoluteError</span></code></a></p></td>
<td><p>Calculates the Geometric Mean Relative Absolute Error.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.regression.ManhattanDistance.html#ignite.metrics.regression.ManhattanDistance" title="ignite.metrics.regression.ManhattanDistance"><code class="xref py py-obj docutils literal notranslate"><span class="pre">regression.ManhattanDistance</span></code></a></p></td>
<td><p>Calculates the Manhattan Distance.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.regression.MaximumAbsoluteError.html#ignite.metrics.regression.MaximumAbsoluteError" title="ignite.metrics.regression.MaximumAbsoluteError"><code class="xref py py-obj docutils literal notranslate"><span class="pre">regression.MaximumAbsoluteError</span></code></a></p></td>
<td><p>Calculates the Maximum Absolute Error.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.regression.MeanAbsoluteRelativeError.html#ignite.metrics.regression.MeanAbsoluteRelativeError" title="ignite.metrics.regression.MeanAbsoluteRelativeError"><code class="xref py py-obj docutils literal notranslate"><span class="pre">regression.MeanAbsoluteRelativeError</span></code></a></p></td>
<td><p>Calculate Mean Absolute Relative Error (MARE), also known as Mean Absolute Percentage Error (MAPE).</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.regression.MeanError.html#ignite.metrics.regression.MeanError" title="ignite.metrics.regression.MeanError"><code class="xref py py-obj docutils literal notranslate"><span class="pre">regression.MeanError</span></code></a></p></td>
<td><p>Calculates the Mean Error.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.regression.MeanNormalizedBias.html#ignite.metrics.regression.MeanNormalizedBias" title="ignite.metrics.regression.MeanNormalizedBias"><code class="xref py py-obj docutils literal notranslate"><span class="pre">regression.MeanNormalizedBias</span></code></a></p></td>
<td><p>Calculates the Mean Normalized Bias.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.regression.MedianAbsoluteError.html#ignite.metrics.regression.MedianAbsoluteError" title="ignite.metrics.regression.MedianAbsoluteError"><code class="xref py py-obj docutils literal notranslate"><span class="pre">regression.MedianAbsoluteError</span></code></a></p></td>
<td><p>Calculates the Median Absolute Error.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.regression.MedianAbsolutePercentageError.html#ignite.metrics.regression.MedianAbsolutePercentageError" title="ignite.metrics.regression.MedianAbsolutePercentageError"><code class="xref py py-obj docutils literal notranslate"><span class="pre">regression.MedianAbsolutePercentageError</span></code></a></p></td>
<td><p>Calculates the Median Absolute Percentage Error.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.regression.MedianRelativeAbsoluteError.html#ignite.metrics.regression.MedianRelativeAbsoluteError" title="ignite.metrics.regression.MedianRelativeAbsoluteError"><code class="xref py py-obj docutils literal notranslate"><span class="pre">regression.MedianRelativeAbsoluteError</span></code></a></p></td>
<td><p>Calculates the Median Relative Absolute Error.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.regression.PearsonCorrelation.html#ignite.metrics.regression.PearsonCorrelation" title="ignite.metrics.regression.PearsonCorrelation"><code class="xref py py-obj docutils literal notranslate"><span class="pre">regression.PearsonCorrelation</span></code></a></p></td>
<td><p>Calculates the <a class="reference external" href="https://en.wikipedia.org/wiki/Pearson_correlation_coefficient">Pearson correlation coefficient</a>.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/ignite.metrics.regression.R2Score.html#ignite.metrics.regression.R2Score" title="ignite.metrics.regression.R2Score"><code class="xref py py-obj docutils literal notranslate"><span class="pre">regression.R2Score</span></code></a></p></td>
<td><p>Calculates the R-Squared, the <a class="reference external" href="https://en.wikipedia.org/wiki/Coefficient_of_determination">coefficient of determination</a>.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/ignite.metrics.regression.WaveHedgesDistance.html#ignite.metrics.regression.WaveHedgesDistance" title="ignite.metrics.regression.WaveHedgesDistance"><code class="xref py py-obj docutils literal notranslate"><span class="pre">regression.WaveHedgesDistance</span></code></a></p></td>
<td><p>Calculates the Wave Hedges Distance.</p></td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Module ignite.metrics.regression provides implementations of metrics useful
for regression tasks. Definitions of metrics are based on
<a class="reference external" href="https://arxiv.org/abs/1809.03006">Botchkarev 2018</a>, page 30 “Appendix 2. Metrics mathematical definitions”.</p>
</div>
</section>
<section id="helpers-for-customizing-metrics">
<h2>Helpers for customizing metrics<a class="headerlink" href="#helpers-for-customizing-metrics" title="Permalink to this heading">#</a></h2>
<section id="metricusage">
<h3>MetricUsage<a class="headerlink" href="#metricusage" title="Permalink to this heading">#</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="ignite.metrics.metric.MetricUsage">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">ignite.metrics.metric.</span></span><span class="sig-name descname"><span class="pre">MetricUsage</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">started</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">completed</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">iteration_completed</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/ignite/metrics/metric.html#MetricUsage"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ignite.metrics.metric.MetricUsage" title="Permalink to this definition">#</a></dt>
<dd><p>Base class for all usages of metrics.</p>
<p>A usage of metric defines the events when a metric starts to compute, updates and completes.
Valid events are from <a class="reference internal" href="generated/ignite.engine.events.Events.html#ignite.engine.events.Events" title="ignite.engine.events.Events"><code class="xref py py-class docutils literal notranslate"><span class="pre">Events</span></code></a>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>started</strong> (<a class="reference internal" href="generated/ignite.engine.events.Events.html#ignite.engine.events.Events" title="ignite.engine.events.Events"><em>Events</em></a>) – event when the metric starts to compute. This event will be associated to
<a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.started" title="ignite.metrics.metric.Metric.started"><code class="xref py py-meth docutils literal notranslate"><span class="pre">started()</span></code></a>.</p></li>
<li><p><strong>completed</strong> (<a class="reference internal" href="generated/ignite.engine.events.Events.html#ignite.engine.events.Events" title="ignite.engine.events.Events"><em>Events</em></a>) – event when the metric completes. This event will be associated to
<a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.completed" title="ignite.metrics.metric.Metric.completed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">completed()</span></code></a>.</p></li>
<li><p><strong>iteration_completed</strong> (<a class="reference internal" href="generated/ignite.engine.events.CallableEventWithFilter.html#ignite.engine.events.CallableEventWithFilter" title="ignite.engine.events.CallableEventWithFilter"><em>CallableEventWithFilter</em></a>) – event when the metric updates. This event will be associated to
<a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.iteration_completed" title="ignite.metrics.metric.Metric.iteration_completed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">iteration_completed()</span></code></a>.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
</section>
<section id="epochwise">
<h3>EpochWise<a class="headerlink" href="#epochwise" title="Permalink to this heading">#</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="ignite.metrics.metric.EpochWise">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">ignite.metrics.metric.</span></span><span class="sig-name descname"><span class="pre">EpochWise</span></span><a class="reference internal" href="_modules/ignite/metrics/metric.html#EpochWise"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ignite.metrics.metric.EpochWise" title="Permalink to this definition">#</a></dt>
<dd><p>Epoch-wise usage of Metrics. It’s the default and most common usage of metrics.</p>
<p>Metric’s methods are triggered on the following engine events:</p>
<ul class="simple">
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.started" title="ignite.metrics.metric.Metric.started"><code class="xref py py-meth docutils literal notranslate"><span class="pre">started()</span></code></a> on every <code class="docutils literal notranslate"><span class="pre">EPOCH_STARTED</span></code>
(See <a class="reference internal" href="generated/ignite.engine.events.Events.html#ignite.engine.events.Events" title="ignite.engine.events.Events"><code class="xref py py-class docutils literal notranslate"><span class="pre">Events</span></code></a>).</p></li>
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.iteration_completed" title="ignite.metrics.metric.Metric.iteration_completed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">iteration_completed()</span></code></a> on every <code class="docutils literal notranslate"><span class="pre">ITERATION_COMPLETED</span></code>.</p></li>
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.completed" title="ignite.metrics.metric.Metric.completed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">completed()</span></code></a> on every <code class="docutils literal notranslate"><span class="pre">EPOCH_COMPLETED</span></code>.</p></li>
</ul>
<dl class="field-list simple">
</dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="ignite.metrics.metric.EpochWise.usage_name">
<span class="sig-name descname"><span class="pre">usage_name</span></span><a class="headerlink" href="#ignite.metrics.metric.EpochWise.usage_name" title="Permalink to this definition">#</a></dt>
<dd><p>usage name string</p>
<dl class="field-list simple">
<dt class="field-odd">Type</dt>
<dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p>
</dd>
</dl>
</dd></dl>
</dd></dl>
</section>
<section id="runningepochwise">
<h3>RunningEpochWise<a class="headerlink" href="#runningepochwise" title="Permalink to this heading">#</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="ignite.metrics.metric.RunningEpochWise">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">ignite.metrics.metric.</span></span><span class="sig-name descname"><span class="pre">RunningEpochWise</span></span><a class="reference internal" href="_modules/ignite/metrics/metric.html#RunningEpochWise"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ignite.metrics.metric.RunningEpochWise" title="Permalink to this definition">#</a></dt>
<dd><p>Running epoch-wise usage of Metrics. It’s the running version of the <a class="reference internal" href="#ignite.metrics.metric.EpochWise" title="ignite.metrics.metric.EpochWise"><code class="xref py py-class docutils literal notranslate"><span class="pre">EpochWise</span></code></a> metric
usage. A metric with such a usage most likely accompanies an <a class="reference internal" href="#ignite.metrics.metric.EpochWise" title="ignite.metrics.metric.EpochWise"><code class="xref py py-class docutils literal notranslate"><span class="pre">EpochWise</span></code></a> one to compute
a running measure of it e.g. running average.</p>
<p>Metric’s methods are triggered on the following engine events:</p>
<ul class="simple">
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.started" title="ignite.metrics.metric.Metric.started"><code class="xref py py-meth docutils literal notranslate"><span class="pre">started()</span></code></a> on every <code class="docutils literal notranslate"><span class="pre">STARTED</span></code>
(See <a class="reference internal" href="generated/ignite.engine.events.Events.html#ignite.engine.events.Events" title="ignite.engine.events.Events"><code class="xref py py-class docutils literal notranslate"><span class="pre">Events</span></code></a>).</p></li>
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.iteration_completed" title="ignite.metrics.metric.Metric.iteration_completed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">iteration_completed()</span></code></a> on every <code class="docutils literal notranslate"><span class="pre">EPOCH_COMPLETED</span></code>.</p></li>
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.completed" title="ignite.metrics.metric.Metric.completed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">completed()</span></code></a> on every <code class="docutils literal notranslate"><span class="pre">EPOCH_COMPLETED</span></code>.</p></li>
</ul>
<dl class="field-list simple">
</dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="ignite.metrics.metric.RunningEpochWise.usage_name">
<span class="sig-name descname"><span class="pre">usage_name</span></span><a class="headerlink" href="#ignite.metrics.metric.RunningEpochWise.usage_name" title="Permalink to this definition">#</a></dt>
<dd><p>usage name string</p>
<dl class="field-list simple">
<dt class="field-odd">Type</dt>
<dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p>
</dd>
</dl>
</dd></dl>
</dd></dl>
</section>
<section id="batchwise">
<h3>BatchWise<a class="headerlink" href="#batchwise" title="Permalink to this heading">#</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="ignite.metrics.metric.BatchWise">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">ignite.metrics.metric.</span></span><span class="sig-name descname"><span class="pre">BatchWise</span></span><a class="reference internal" href="_modules/ignite/metrics/metric.html#BatchWise"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ignite.metrics.metric.BatchWise" title="Permalink to this definition">#</a></dt>
<dd><p>Batch-wise usage of Metrics.</p>
<p>Metric’s methods are triggered on the following engine events:</p>
<ul class="simple">
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.started" title="ignite.metrics.metric.Metric.started"><code class="xref py py-meth docutils literal notranslate"><span class="pre">started()</span></code></a> on every <code class="docutils literal notranslate"><span class="pre">ITERATION_STARTED</span></code>
(See <a class="reference internal" href="generated/ignite.engine.events.Events.html#ignite.engine.events.Events" title="ignite.engine.events.Events"><code class="xref py py-class docutils literal notranslate"><span class="pre">Events</span></code></a>).</p></li>
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.iteration_completed" title="ignite.metrics.metric.Metric.iteration_completed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">iteration_completed()</span></code></a> on every <code class="docutils literal notranslate"><span class="pre">ITERATION_COMPLETED</span></code>.</p></li>
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.completed" title="ignite.metrics.metric.Metric.completed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">completed()</span></code></a> on every <code class="docutils literal notranslate"><span class="pre">ITERATION_COMPLETED</span></code>.</p></li>
</ul>
<dl class="field-list simple">
</dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="ignite.metrics.metric.BatchWise.usage_name">
<span class="sig-name descname"><span class="pre">usage_name</span></span><a class="headerlink" href="#ignite.metrics.metric.BatchWise.usage_name" title="Permalink to this definition">#</a></dt>
<dd><p>usage name string</p>
<dl class="field-list simple">
<dt class="field-odd">Type</dt>
<dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p>
</dd>
</dl>
</dd></dl>
</dd></dl>
</section>
<section id="runningbatchwise">
<h3>RunningBatchWise<a class="headerlink" href="#runningbatchwise" title="Permalink to this heading">#</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="ignite.metrics.metric.RunningBatchWise">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">ignite.metrics.metric.</span></span><span class="sig-name descname"><span class="pre">RunningBatchWise</span></span><a class="reference internal" href="_modules/ignite/metrics/metric.html#RunningBatchWise"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ignite.metrics.metric.RunningBatchWise" title="Permalink to this definition">#</a></dt>
<dd><p>Running batch-wise usage of Metrics. It’s the running version of the <a class="reference internal" href="#ignite.metrics.metric.EpochWise" title="ignite.metrics.metric.EpochWise"><code class="xref py py-class docutils literal notranslate"><span class="pre">EpochWise</span></code></a> metric
usage. A metric with such a usage could for example accompany a <a class="reference internal" href="#ignite.metrics.metric.BatchWise" title="ignite.metrics.metric.BatchWise"><code class="xref py py-class docutils literal notranslate"><span class="pre">BatchWise</span></code></a> one to compute
a running measure of it e.g. running average.</p>
<p>Metric’s methods are triggered on the following engine events:</p>
<ul class="simple">
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.started" title="ignite.metrics.metric.Metric.started"><code class="xref py py-meth docutils literal notranslate"><span class="pre">started()</span></code></a> on every <code class="docutils literal notranslate"><span class="pre">STARTED</span></code>
(See <a class="reference internal" href="generated/ignite.engine.events.Events.html#ignite.engine.events.Events" title="ignite.engine.events.Events"><code class="xref py py-class docutils literal notranslate"><span class="pre">Events</span></code></a>).</p></li>
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.iteration_completed" title="ignite.metrics.metric.Metric.iteration_completed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">iteration_completed()</span></code></a> on every <code class="docutils literal notranslate"><span class="pre">ITERATION_COMPLETED</span></code>.</p></li>
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.completed" title="ignite.metrics.metric.Metric.completed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">completed()</span></code></a> on every <code class="docutils literal notranslate"><span class="pre">ITERATION_COMPLETED</span></code>.</p></li>
</ul>
<dl class="field-list simple">
</dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="ignite.metrics.metric.RunningBatchWise.usage_name">
<span class="sig-name descname"><span class="pre">usage_name</span></span><a class="headerlink" href="#ignite.metrics.metric.RunningBatchWise.usage_name" title="Permalink to this definition">#</a></dt>
<dd><p>usage name string</p>
<dl class="field-list simple">
<dt class="field-odd">Type</dt>
<dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p>
</dd>
</dl>
</dd></dl>
</dd></dl>
</section>
<section id="singleepochrunningbatchwise">
<h3>SingleEpochRunningBatchWise<a class="headerlink" href="#singleepochrunningbatchwise" title="Permalink to this heading">#</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="ignite.metrics.metric.SingleEpochRunningBatchWise">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">ignite.metrics.metric.</span></span><span class="sig-name descname"><span class="pre">SingleEpochRunningBatchWise</span></span><a class="reference internal" href="_modules/ignite/metrics/metric.html#SingleEpochRunningBatchWise"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ignite.metrics.metric.SingleEpochRunningBatchWise" title="Permalink to this definition">#</a></dt>
<dd><p>Running batch-wise usage of Metrics in a single epoch. It’s like <a class="reference internal" href="#ignite.metrics.metric.RunningBatchWise" title="ignite.metrics.metric.RunningBatchWise"><code class="xref py py-class docutils literal notranslate"><span class="pre">RunningBatchWise</span></code></a> metric
usage with the difference that is used during a single epoch.</p>
<p>Metric’s methods are triggered on the following engine events:</p>
<ul class="simple">
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.started" title="ignite.metrics.metric.Metric.started"><code class="xref py py-meth docutils literal notranslate"><span class="pre">started()</span></code></a> on every <code class="docutils literal notranslate"><span class="pre">EPOCH_STARTED</span></code>
(See <a class="reference internal" href="generated/ignite.engine.events.Events.html#ignite.engine.events.Events" title="ignite.engine.events.Events"><code class="xref py py-class docutils literal notranslate"><span class="pre">Events</span></code></a>).</p></li>
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.iteration_completed" title="ignite.metrics.metric.Metric.iteration_completed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">iteration_completed()</span></code></a> on every <code class="docutils literal notranslate"><span class="pre">ITERATION_COMPLETED</span></code>.</p></li>
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.completed" title="ignite.metrics.metric.Metric.completed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">completed()</span></code></a> on every <code class="docutils literal notranslate"><span class="pre">ITERATION_COMPLETED</span></code>.</p></li>
</ul>
<dl class="field-list simple">
</dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="ignite.metrics.metric.SingleEpochRunningBatchWise.usage_name">
<span class="sig-name descname"><span class="pre">usage_name</span></span><a class="headerlink" href="#ignite.metrics.metric.SingleEpochRunningBatchWise.usage_name" title="Permalink to this definition">#</a></dt>
<dd><p>usage name string</p>
<dl class="field-list simple">
<dt class="field-odd">Type</dt>
<dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p>
</dd>
</dl>
</dd></dl>
</dd></dl>
</section>
<section id="batchfiltered">
<h3>BatchFiltered<a class="headerlink" href="#batchfiltered" title="Permalink to this heading">#</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="ignite.metrics.metric.BatchFiltered">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">ignite.metrics.metric.</span></span><span class="sig-name descname"><span class="pre">BatchFiltered</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/ignite/metrics/metric.html#BatchFiltered"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ignite.metrics.metric.BatchFiltered" title="Permalink to this definition">#</a></dt>
<dd><p>Batch filtered usage of Metrics. This usage is similar to epoch-wise but update event is filtered.</p>
<p>Metric’s methods are triggered on the following engine events:</p>
<ul class="simple">
<li><p><a class="reference internal" href="generated/ignite.metrics.metric.Metric.html#ignite.metrics.metric.Metric.started" title="ignite.metrics.metric.Metric.started"><code class="xref py py-meth docutils literal notranslate"><span class="pre">started()</span></code></a> on every <code class="docutils literal notranslate"><span class="pre">EPOCH_STARTED</span></code>
(See <a class="reference internal" href="generated/ignite.engine.events.Events.html#ignite.engine.events.Events" title="ignite.engine.events.Events"><code class="xref py py-class docutils literal notranslate"><span class="pre">Events</span></code></a>).</p></li>