def test_transform_shape(self): input1 = mx.nd.random.uniform(0, 255, shape=(32, 32, 3)) output1 = image.transform_shape(input1) assert output1.shape == (1, 3, 32, 32), "transform_shape method fail. Got %s shape." % (str(output1.shape)) input2 = mx.nd.random.uniform(0, 255, shape=(28, 28, 3)) output2 = image.transform_shape(input2, dim_order='NHWC') assert output2.shape == (1, 28, 28, 3), "transform_shape method fail. Got %s shape." % (str(output2.shape))
def _preprocess(self, data): input_shape = self.signature['inputs'][0]['data_shape'] height, width = input_shape[2:] img_arr = image.read(data[0]) img_arr = image.resize(img_arr, width, height) img_arr = image.color_normalize(img_arr, nd.array([127.5]), nd.array([127.5])) img_arr = image.transform_shape(img_arr) return [img_arr]
def _preprocess(self, data): img_list = [] for idx, img in enumerate(data): input_shape = self.signature['inputs'][idx]['data_shape'] # We are assuming input shape is NCHW [h, w] = input_shape[2:] img_arr = image.read(img) img_arr = image.resize(img_arr, w, h) img_arr = image.transform_shape(img_arr) img_list.append(img_arr) return img_list
def _preprocess(self, data): img_list = [] for idx, img in enumerate(data): input_shape = self.signature['inputs'][idx][ 'data_shape'] # Input shape is NCHW [h, w] = input_shape[2:] img_arr = image.read( img, 0) #Set flag to 0 for reading grayscale images img_arr = image.resize(img_arr, w, h) img_arr = image.transform_shape(img_arr) img_list.append(img_arr) return img_list
def _preprocess(self, data): img_list = [] for idx, img in enumerate(data): input_shape = self.signature['inputs'][idx]['data_shape'] # We are assuming input shape is NCHW img_arr = image.read(img) img_arr, im_scale = rcnn_resize(img_arr, SHORTER_SIZE, MAX_SIZE, stride=IMAGE_STRIDE) rgb_mean = mx.nd.array([[[0, 0, 0]]]) img_arr = img_arr.astype('float32') img_arr = img_arr - rgb_mean img_arr = image.transform_shape(img_arr) img_list.append(img_arr) im_info = [[img_arr.shape[2], img_arr.shape[3], im_scale]] self.scale = im_scale img_list.append(mx.nd.array(im_info)) return img_list
def _preprocess(self, data): img_list = [] for idx, img in enumerate(data): input_shape = self.signature['inputs'][idx]['data_shape'] # We are assuming input shape is NCHW [h, w] = input_shape[2:] if input_shape[1] == 1: img_arr = image.read(img, 0) else: img_arr = image.read(img) img_arr = image.resize(img_arr, w, h) rgb_mean = mx.nd.array([123.68, 116.779, 103.939]) rgb_std = mx.nd.array([58.395, 57.12, 57.375]) img_arr = img_arr.astype('float32') img_arr = mx.image.color_normalize(img_arr, mean=rgb_mean, std=rgb_std) img_arr = mx.nd.reshape(img_arr, (w, h, input_shape[1])) img_arr = image.transform_shape(img_arr) img_list.append(img_arr) return img_list