From 9d46a4b56823f4a02905e3e3978a198e8d67f088 Mon Sep 17 00:00:00 2001 From: wkcn Date: Mon, 29 Jul 2019 18:57:28 +0800 Subject: [PATCH 1/3] fix segmentation testing and support CPU --- scripts/segmentation/test.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/segmentation/test.py b/scripts/segmentation/test.py index 3cb5a6396f..4b16bdb18a 100644 --- a/scripts/segmentation/test.py +++ b/scripts/segmentation/test.py @@ -68,7 +68,7 @@ def test(args): im_paths = dsts predicts = evaluator.parallel_forward(data) for predict, impath in zip(predicts, im_paths): - predict = mx.nd.squeeze(mx.nd.argmax(predict[0], 1)).asnumpy() + \ + predict = mx.nd.squeeze(mx.nd.argmax(predict[0], 0)).asnumpy() + \ testset.pred_offset mask = get_color_pallete(predict, args.dataset) outname = os.path.splitext(impath)[0] + '.png' @@ -76,6 +76,8 @@ def test(args): if __name__ == "__main__": args = parse_args() - args.test_batch_size = args.ngpus + args.test_batch_size = max(1, args.ngpus) + if args.ngpus == 0: + args.ctx = [mx.cpu()] print('Testing model: ', args.resume) test(args) From d86aaada5afcce42bcc0b5cb206488735cb1c6b1 Mon Sep 17 00:00:00 2001 From: wkcn Date: Mon, 29 Jul 2019 19:11:53 +0800 Subject: [PATCH 2/3] update no cuda config --- scripts/segmentation/test.py | 2 -- scripts/segmentation/train.py | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/segmentation/test.py b/scripts/segmentation/test.py index 4b16bdb18a..efe8f3ecf3 100644 --- a/scripts/segmentation/test.py +++ b/scripts/segmentation/test.py @@ -77,7 +77,5 @@ def test(args): if __name__ == "__main__": args = parse_args() args.test_batch_size = max(1, args.ngpus) - if args.ngpus == 0: - args.ctx = [mx.cpu()] print('Testing model: ', args.resume) test(args) diff --git a/scripts/segmentation/train.py b/scripts/segmentation/train.py index aada216d17..a51a00f031 100644 --- a/scripts/segmentation/train.py +++ b/scripts/segmentation/train.py @@ -88,6 +88,8 @@ def parse_args(): # the parser args = parser.parse_args() # handle contexts + if args.ngpus == 0: + args.no_cuda = True if args.no_cuda: print('Using CPU') args.kvstore = 'local' From f02a7446d5ed253a14ce08e25b8500e7f2191b47 Mon Sep 17 00:00:00 2001 From: wkcn Date: Tue, 30 Jul 2019 09:18:23 +0800 Subject: [PATCH 3/3] change the axis of argmax --- scripts/segmentation/test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/segmentation/test.py b/scripts/segmentation/test.py index efe8f3ecf3..3f1e30d5f3 100644 --- a/scripts/segmentation/test.py +++ b/scripts/segmentation/test.py @@ -68,8 +68,8 @@ def test(args): im_paths = dsts predicts = evaluator.parallel_forward(data) for predict, impath in zip(predicts, im_paths): - predict = mx.nd.squeeze(mx.nd.argmax(predict[0], 0)).asnumpy() + \ - testset.pred_offset + predict = mx.nd.squeeze(mx.nd.argmax(predict, 1), axis=0).\ + asnumpy() + testset.pred_offset mask = get_color_pallete(predict, args.dataset) outname = os.path.splitext(impath)[0] + '.png' mask.save(os.path.join(outdir, outname))