def preprocess(self, inp): """ Default preprocessing method for is to convert the picture to black and white and resize to be 48x48 """ im = preprocessing_utils.decode_base64_to_image(inp) im = im.convert('RGB') im = preprocessing_utils.resize_and_crop(im, (self.image_width, self.image_height)) return np.array(im)
def preprocess(self, inp): """ Default preprocessing method for is to convert the picture to black and white and resize to be 48x48 """ im = preprocessing_utils.decode_base64_to_image(inp) with warnings.catch_warnings(): warnings.simplefilter("ignore") im = im.convert(self.image_mode) im = preprocessing_utils.resize_and_crop(im, (self.image_width, self.image_height)) return np.array(im)
def preprocess(self, inp): """ Default preprocessing method for the SketchPad is to convert the sketch to black and white and resize 28x28 """ im = preprocessing_utils.decode_base64_to_image(inp) im = im.convert('L') if self.invert_colors: im = ImageOps.invert(im) im = preprocessing_utils.resize_and_crop(im, (self.image_width, self.image_height)) if self.flatten: array = np.array(im).flatten().reshape(1, self.image_width * self.image_height) else: array = np.array(im).flatten().reshape(1, self.image_width, self.image_height) array = array * self.scale + self.shift array = array.astype(self.dtype) return array
def preprocess(self, inp): """ Default preprocessing method for is to convert the picture to black and white and resize to be 48x48 """ im = preprocessing_utils.decode_base64_to_image(inp) with warnings.catch_warnings(): warnings.simplefilter("ignore") im = im.convert(self.image_mode) im = preprocessing_utils.resize_and_crop(im, (self.image_width, self.image_height)) im = np.array(im).flatten() im = im * self.scale + self.shift if self.num_channels is None: array = im.reshape(1, self.image_width, self.image_height) else: array = im.reshape(1, self.image_width, self.image_height, self.num_channels) return array