Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dim check while calculating mIoU&pixAcc for segmentation test #991

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions gluoncv/utils/metrics/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,7 @@ def reset(self):
def batch_pix_accuracy(output, target):
"""PixAcc"""
# inputs are NDarray, output 4D, target 3D
# add new axis if missing batch dimension
# the category -1 is ignored class, typically for background / boundary
if len(output.shape) == 3:
output = output[np.newaxis, :]
if len(target.shape) == 2:
target = target[np.newaxis, :]
predict = np.argmax(output.asnumpy(), 1).astype('int64') + 1

target = target.asnumpy().astype('int64') + 1
Expand All @@ -103,12 +98,7 @@ def batch_pix_accuracy(output, target):
def batch_intersection_union(output, target, nclass):
"""mIoU"""
# inputs are NDarray, output 4D, target 3D
# add new axis if missing batch dimension
# the category -1 is ignored class, typically for background / boundary
if len(output.shape) == 3:
output = output[np.newaxis, :]
if len(target.shape) == 2:
target = target[np.newaxis, :]
mini = 1
maxi = nclass
nbins = nclass
Expand Down
2 changes: 1 addition & 1 deletion scripts/segmentation/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test(model, args, input_transform):
tbar = tqdm(test_data)
for i, (data, dsts) in enumerate(tbar):
if args.eval:
predicts = [pred[0] for pred in evaluator.parallel_forward(data)]
predicts = [pred for pred in evaluator.parallel_forward(data)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect. The output of gluoncv segmentation network is always a list

targets = [target.as_in_context(predicts[0].context) \
for target in dsts]
metric.update(targets, predicts)
Expand Down