From 748d4d8dc4fb1d737cf189d778faeb4f41b560a8 Mon Sep 17 00:00:00 2001 From: Vandana Kannan Date: Wed, 8 Aug 2018 17:24:46 -0700 Subject: [PATCH] [MXNET-696] Fix undefined variable errors (#11982) * Fix undefined error in image segmentation ctx is used undefined. Setting the default ctx to cpu and editing the comment to let the user know that it can be changed to GPU as required. * Fix undefined names in SSD example maskUtils is disabled. Remove code referencing it. Initializing start_offset. --- example/fcn-xs/image_segmentaion.py | 4 ++-- example/ssd/dataset/pycocotools/coco.py | 17 ----------------- example/ssd/symbol/common.py | 3 +++ 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/example/fcn-xs/image_segmentaion.py b/example/fcn-xs/image_segmentaion.py index 75df2d128a22..562db14d36be 100644 --- a/example/fcn-xs/image_segmentaion.py +++ b/example/fcn-xs/image_segmentaion.py @@ -93,8 +93,8 @@ def main(): model_prefix = "FCN8s_VGG16" epoch = 19 - # By default, MXNet will run on the CPU. Uncomment the line below to execute on the GPU - # ctx = mx.gpu() + # By default, MXNet will run on the CPU. Change to ctx = mx.gpu() to run on GPU. + ctx = mx.cpu() fcnxs, fcnxs_args, fcnxs_auxs = mx.model.load_checkpoint(model_prefix, epoch) fcnxs_args["data"] = mx.nd.array(get_data(args.input), ctx) diff --git a/example/ssd/dataset/pycocotools/coco.py b/example/ssd/dataset/pycocotools/coco.py index 19a7b8b7f64d..470f086f0b02 100755 --- a/example/ssd/dataset/pycocotools/coco.py +++ b/example/ssd/dataset/pycocotools/coco.py @@ -255,22 +255,7 @@ def showAnns(self, anns): color.append(c) else: # mask - t = self.imgs[ann['image_id']] - if type(ann['segmentation']['counts']) == list: - # rle = maskUtils.frPyObjects([ann['segmentation']], t['height'], t['width']) - raise NotImplementedError("maskUtils disabled!") - else: - rle = [ann['segmentation']] - # m = maskUtils.decode(rle) raise NotImplementedError("maskUtils disabled!") - img = np.ones( (m.shape[0], m.shape[1], 3) ) - if ann['iscrowd'] == 1: - color_mask = np.array([2.0,166.0,101.0])/255 - if ann['iscrowd'] == 0: - color_mask = np.random.random((1, 3)).tolist()[0] - for i in range(3): - img[:,:,i] = color_mask[i] - ax.imshow(np.dstack( (img, m*0.5) )) if 'keypoints' in ann and type(ann['keypoints']) == list: # turn skeleton into zero-based index sks = np.array(self.loadCats(ann['category_id'])[0]['skeleton'])-1 @@ -430,6 +415,4 @@ def annToMask(self, ann): :return: binary mask (numpy 2D array) """ rle = self.annToRLE(ann) - # m = maskUtils.decode(rle) raise NotImplementedError("maskUtils disabled!") - return m diff --git a/example/ssd/symbol/common.py b/example/ssd/symbol/common.py index 4a0458f87288..a2fb4e69d18c 100644 --- a/example/ssd/symbol/common.py +++ b/example/ssd/symbol/common.py @@ -206,6 +206,9 @@ def multibox_layer(from_layers, num_classes, sizes=[.2, .95], assert sizes[0] > 0 and sizes[0] < 1 assert sizes[1] > 0 and sizes[1] < 1 and sizes[1] > sizes[0] tmp = np.linspace(sizes[0], sizes[1], num=(len(from_layers)-1)) + # Ref for start_offset value: + # https://arxiv.org/abs/1512.02325 + start_offset = 0.1 min_sizes = [start_offset] + tmp.tolist() max_sizes = tmp.tolist() + [tmp[-1]+start_offset] sizes = zip(min_sizes, max_sizes)