Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
M
metrics
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Eigo Mori
metrics
Commits
e566d76b
Commit
e566d76b
authored
May 06, 2018
by
Eigo Mori
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pixel accuracy and IoU for semantic segmentation
parents
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
0 deletions
+80
-0
ss_metrics.py
ss_metrics.py
+80
-0
No files found.
ss_metrics.py
0 → 100644
View file @
e566d76b
# -*- coding: utf-8 -*-
import
sys
import
numpy
as
np
from
PIL
import
Image
# CLASS = 14
CLASS
=
2
def
main
():
img
=
Image
.
open
(
sys
.
argv
[
1
])
w
,
h
=
img
.
size
target
=
np
.
asarray
(
img
,
dtype
=
np
.
int64
)
# print(target.shape)
img
=
Image
.
open
(
sys
.
argv
[
2
])
pred
=
np
.
asarray
(
img
,
dtype
=
np
.
int64
)[:,:,
0
]
# print(pred.shape)
acc
=
np
.
zeros
(
CLASS
,
dtype
=
np
.
int64
)
# iをiと判定した数 acc[i]
nacc
=
np
.
zeros
(
CLASS
,
dtype
=
np
.
int64
)
# iをi以外と判定した数 nacc[i]
occ
=
np
.
zeros
(
CLASS
,
dtype
=
np
.
int64
)
# iに本来所属する画素数 occ[i]
pcc
=
np
.
zeros
(
CLASS
,
dtype
=
np
.
int64
)
# iに所属するとされた画素数 pcc[i]
accuracy
=
np
.
zeros
(
CLASS
,
dtype
=
np
.
float64
)
iou
=
np
.
zeros
(
CLASS
,
dtype
=
np
.
float64
)
print
(
sys
.
argv
[
1
])
for
y
in
range
(
0
,
h
):
for
x
in
range
(
0
,
w
):
occ
[
target
[
y
][
x
]]
+=
1
pcc
[
pred
[
y
][
x
]]
+=
1
if
target
[
y
][
x
]
==
pred
[
y
][
x
]:
acc
[
target
[
y
][
x
]]
+=
1
else
:
nacc
[
target
[
y
][
x
]]
+=
1
for
i
in
range
(
0
,
CLASS
):
if
acc
[
i
]
+
nacc
[
i
]
>
0
:
print
(
"Class {0:2d}: correct {1:6d}, incorrect {2:6d}, accuracy {3:.3}"
.
format
(
i
,
acc
[
i
],
nacc
[
i
],
float
(
acc
[
i
])
/
float
(
acc
[
i
]
+
nacc
[
i
])))
accuracy
[
i
]
=
float
(
acc
[
i
])
/
float
(
acc
[
i
]
+
nacc
[
i
])
else
:
print
(
"Class {0:2d}: correct 0, incorrect 0, accuracy -"
.
format
(
i
))
accuracy
[
i
]
=
-
1
print
(
"Total : correct {0:6d}, incorrect {1:6d}, accuracy {2:.3}"
.
format
(
np
.
sum
(
acc
),
np
.
sum
(
nacc
),
float
(
np
.
sum
(
acc
))
/
float
(
np
.
sum
(
acc
)
+
np
.
sum
(
nacc
))))
cc
=
0
s
=
0
for
a
in
accuracy
:
if
a
!=
-
1
:
cc
+=
1
s
+=
a
print
(
"Mean Accuracy : {0:.3}"
.
format
(
s
/
float
(
cc
)))
print
()
for
i
in
range
(
0
,
CLASS
):
if
occ
[
i
]
+
pcc
[
i
]
-
acc
[
i
]
>
0
:
iou
[
i
]
=
acc
[
i
]
/
(
occ
[
i
]
+
pcc
[
i
]
-
acc
[
i
])
print
(
"Class {0:2d}: IoU {1:.3}"
.
format
(
i
,
acc
[
i
]
/
(
occ
[
i
]
+
pcc
[
i
]
-
acc
[
i
])))
else
:
iou
[
i
]
=
-
1
print
(
"Class {0:2d}: IoU -"
.
format
(
i
))
print
(
"Total IoU : {0:.3}"
.
format
(
np
.
sum
(
acc
)
/
float
(
np
.
sum
(
occ
)
+
np
.
sum
(
pcc
)
-
np
.
sum
(
acc
))))
cc
=
0
s
=
0
for
a
in
iou
:
if
a
!=
-
1
:
cc
+=
1
s
+=
a
print
(
"Mean IoU : {0:.3}"
.
format
(
s
/
float
(
cc
)))
print
()
if
__name__
==
"__main__"
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment