File tree Expand file tree Collapse file tree 1 file changed +2
-10
lines changed Expand file tree Collapse file tree 1 file changed +2
-10
lines changed Original file line number Diff line number Diff line change 2
2
# https://github.com/wkentaro/pytorch-fcn/blob/master/torchfcn/utils.py
3
3
4
4
import numpy as np
5
-
5
+ from sklearn . metrics import confusion_matrix
6
6
7
7
class runningScore (object ):
8
8
def __init__ (self , n_classes ):
9
9
self .n_classes = n_classes
10
10
self .confusion_matrix = np .zeros ((n_classes , n_classes ))
11
11
12
- def _fast_hist (self , label_true , label_pred , n_class ):
13
- mask = (label_true >= 0 ) & (label_true < n_class )
14
- hist = np .bincount (
15
- n_class * label_true [mask ].astype (int ) + label_pred [mask ], minlength = n_class ** 2
16
- ).reshape (n_class , n_class )
17
- return hist
18
-
19
12
def update (self , label_trues , label_preds ):
20
- for lt , lp in zip (label_trues , label_preds ):
21
- self .confusion_matrix += self ._fast_hist (lt .flatten (), lp .flatten (), self .n_classes )
13
+ self .confusion_matrix += confusion_matrix (label_trues .flatten (), label_preds .flatten (), list (range (self .n_classes )))
22
14
23
15
def get_scores (self ):
24
16
"""Returns accuracy score evaluation result.
You can’t perform that action at this time.
0 commit comments