zoo.feature.image package

Submodules

zoo.feature.image.imagePreprocessing module

class zoo.feature.image.imagePreprocessing.ImageAspectScale(min_size, scale_multiple_of=1, max_size=1000, resize_mode=1, use_scale_factor=True, min_scale=-1.0, bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

Resize the image, keep the aspect ratio. scale according to the short edge :param min_size scale size, apply to short edge :param scale_multiple_of make the scaled size multiple of some value :param max_size max size after scale :param resize_mode if resizeMode = -1, random select a mode from (Imgproc.INTER_LINEAR, Imgproc.INTER_CUBIC, Imgproc.INTER_AREA, Imgproc.INTER_NEAREST, Imgproc.INTER_LANCZOS4) :param use_scale_factor if true, scale factor fx and fy is used, fx = fy = 0 :aram min_scale control the minimum scale up for image

class zoo.feature.image.imagePreprocessing.ImageBrightness(delta_low, delta_high, bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

adjust the image brightness :param deltaLow brightness parameter: low bound :param deltaHigh brightness parameter: high bound

class zoo.feature.image.imagePreprocessing.ImageBytesToMat(byte_key='bytes', image_codec=-1, bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

Transform byte array(original image file in byte) to OpenCVMat :param byte_key key that maps byte array :param image_codec specifying the color type of a loaded image, same as in OpenCV.imread. By default is Imgcodecs.CV_LOAD_IMAGE_UNCHANGED

class zoo.feature.image.imagePreprocessing.ImageCenterCrop(crop_width, crop_height, is_clip=True, bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

Crop a cropWidth x cropHeight patch from center of image. The patch size should be less than the image size. :param crop_width width after crop :param crop_height height after crop :param is_clip clip cropping box boundary

class zoo.feature.image.imagePreprocessing.ImageChannelNormalize(mean_r, mean_g, mean_b, std_r=1.0, std_g=1.0, std_b=1.0, bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

image channel normalize :param mean_r mean value in R channel :param mean_g mean value in G channel :param meanB_b mean value in B channel :param std_r std value in R channel :param std_g std value in G channel :param std_b std value in B channel

class zoo.feature.image.imagePreprocessing.ImageChannelOrder(bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

random change the channel of an image

class zoo.feature.image.imagePreprocessing.ImageColorJitter(brightness_prob=0.5, brightness_delta=32.0, contrast_prob=0.5, contrast_lower=0.5, contrast_upper=1.5, hue_prob=0.5, hue_delta=18.0, saturation_prob=0.5, saturation_lower=0.5, saturation_upper=1.5, random_order_prob=0.0, shuffle=False, bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

Random adjust brightness, contrast, hue, saturation :param brightness_prob probability to adjust brightness :param brightness_delta brightness parameter :param contrast_prob probability to adjust contrast :param contrast_lower contrast lower parameter :param contrast_upper contrast upper parameter :param hue_prob probability to adjust hue :param hue_delta hue parameter :param saturation_prob probability to adjust saturation :param saturation_lower saturation lower parameter :param saturation_upper saturation upper parameter :param random_order_prob random order for different operation :param shuffle shuffle the transformers

class zoo.feature.image.imagePreprocessing.ImageExpand(means_r=123, means_g=117, means_b=104, min_expand_ratio=1.0, max_expand_ratio=4.0, bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

expand image, fill the blank part with the meanR, meanG, meanB

:param means_r means in R channel :param means_g means in G channel :param means_b means in B channel :param min_expand_ratio min expand ratio :param max_expand_ratio max expand ratio

class zoo.feature.image.imagePreprocessing.ImageFeatureToSample(bigdl_type='float')[source]

Bases: zoo.feature.common.Preprocessing

A transformer that get Sample from ImageFeature.

class zoo.feature.image.imagePreprocessing.ImageFeatureToTensor(bigdl_type='float')[source]

Bases: zoo.feature.common.Preprocessing

a Transformer that convert ImageFeature to a Tensor.

class zoo.feature.image.imagePreprocessing.ImageFiller(start_x, start_y, end_x, end_y, value=255, bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

Fill part of image with certain pixel value :param start_x start x ratio :param start_y start y ratio :param end_x end x ratio :param end_y end y ratio :param value filling value

class zoo.feature.image.imagePreprocessing.ImageFixedCrop(x1, y1, x2, y2, normalized=True, is_clip=True, bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

Crop a fixed area of image

:param x1 start in width :param y1 start in height :param x2 end in width :param y2 end in height :param normalized whether args are normalized, i.e. in range [0, 1] :param is_clip whether to clip the roi to image boundaries

class zoo.feature.image.imagePreprocessing.ImageHFlip(bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

Flip the image horizontally

class zoo.feature.image.imagePreprocessing.ImageHue(delta_low, delta_high, bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

adjust the image hue :param deltaLow hue parameter: low bound :param deltaHigh hue parameter: high bound

class zoo.feature.image.imagePreprocessing.ImageMatToTensor(to_RGB=False, tensor_key='imageTensor', share_buffer=True, format='NCHW', bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

MatToTensor :param toRGB BGR to RGB (default is BGR) :param tensorKey key to store transformed tensor :param format DataFormat.NCHW or DataFormat.NHWC

class zoo.feature.image.imagePreprocessing.ImageMirror(bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

Flip the image horizontally and vertically

class zoo.feature.image.imagePreprocessing.ImagePixelBytesToMat(byte_key='bytes', bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

Transform byte array(pixels in byte) to OpenCVMat :param byte_key key that maps byte array

class zoo.feature.image.imagePreprocessing.ImagePixelNormalize(means, bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

Pixel level normalizer, data(i) = data(i) - mean(i)

:param means pixel level mean, following H * W * C order

class zoo.feature.image.imagePreprocessing.ImagePreprocessing(bigdl_type='float', *args)[source]

Bases: zoo.feature.common.Preprocessing

ImagePreprocessing is a transformer that transform ImageFeature

class zoo.feature.image.imagePreprocessing.ImageRandomAspectScale(scales, scale_multiple_of=1, max_size=1000, bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

resize the image by randomly choosing a scale :param scales array of scale options that for random choice :param scaleMultipleOf Resize test images so that its width and height are multiples of :param maxSize Max pixel size of the longest side of a scaled input image

class zoo.feature.image.imagePreprocessing.ImageRandomCrop(crop_width, crop_height, is_clip=True, bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

Random crop a cropWidth x cropHeight patch from an image. The patch size should be less than the image size.

:param crop_width width after crop :param crop_height height after crop :param is_clip whether to clip the roi to image boundaries

class zoo.feature.image.imagePreprocessing.ImageRandomPreprocessing(preprocessing, prob, bigdl_type='float')[source]

Bases: zoo.feature.common.Preprocessing

Randomly apply the preprocessing to some of the input ImageFeatures, with probability specified. E.g. if prob = 0.5, the preprocessing will apply to half of the input ImageFeatures. :param preprocessing preprocessing to apply. :param prob probability to apply the preprocessing action.

class zoo.feature.image.imagePreprocessing.ImageResize(resize_h, resize_w, resize_mode=1, use_scale_factor=True, bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

Resize image :param resize_h height after resize :param resize_w width after resize :param resize_mode if resizeMode = -1, random select a mode from (Imgproc.INTER_LINEAR, Imgproc.INTER_CUBIC, Imgproc.INTER_AREA, Imgproc.INTER_NEAREST, Imgproc.INTER_LANCZOS4) :param use_scale_factor if true, scale factor fx and fy is used, fx = fy = 0 note that the result of the following are different Imgproc.resize(mat, mat, new Size(resizeWH, resizeWH), 0, 0, Imgproc.INTER_LINEAR) Imgproc.resize(mat, mat, new Size(resizeWH, resizeWH))

class zoo.feature.image.imagePreprocessing.ImageSaturation(delta_low, delta_high, bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

adjust the image Saturation :param deltaLow brightness parameter: low bound :param deltaHigh brightness parameter: high bound

class zoo.feature.image.imagePreprocessing.ImageSetToSample(input_keys=['imageTensor'], target_keys=['label'], sample_key='sample', bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

transform imageframe to samples :param input_keys keys that maps inputs (each input should be a tensor) :param target_keys keys that maps targets (each target should be a tensor) :param sample_key key to store sample

class zoo.feature.image.imagePreprocessing.PerImageNormalize(min, max, norm_type=32, bigdl_type='float')[source]

Bases: zoo.feature.image.imagePreprocessing.ImagePreprocessing

Normalizes the norm or value range per image, similar to opencv::normalize https://docs.opencv.org/ref/master/d2/de8/group__core__array.html #ga87eef7ee3970f86906d69a92cbf064bd ImageNormalize normalizes scale and shift the input features. Various normalize methods are supported, Eg. NORM_INF, NORM_L1, NORM_L2 or NORM_MINMAX Pleas notice it’s a per image normalization. :param min lower range boundary in case of the range normalization or norm value to normalize :param max upper range boundary in case of the range normalization. It is not used for the norm normalization. :param norm_type normalization type, see opencv:NormTypes. https://docs.opencv.org/ref/master/d2/de8/group__core__array.html #gad12cefbcb5291cf958a85b4b67b6149f Default Core.NORM_MINMAX

class zoo.feature.image.imagePreprocessing.RowToImageFeature(bigdl_type='float')[source]

Bases: zoo.feature.common.Preprocessing

a Transformer that converts a Spark Row to a BigDL ImageFeature.

zoo.feature.image.imageset module

class zoo.feature.image.imageset.DistributedImageSet(image_rdd=None, label_rdd=None, jvalue=None, bigdl_type='float')[source]

Bases: zoo.feature.image.imageset.ImageSet

DistributedImageSet wraps an RDD of ImageFeature

get_image(key='floats', to_chw=True)[source]

get image rdd from ImageSet

get_label()[source]

get label rdd from ImageSet

get_predict(key='predict')[source]

get prediction rdd from ImageSet

class zoo.feature.image.imageset.ImageSet(jvalue, bigdl_type='float')[source]

Bases: bigdl.util.common.JavaValue

ImageSet wraps a set of ImageFeature

classmethod from_image_frame(image_frame, bigdl_type='float')[source]
classmethod from_rdds(image_rdd, label_rdd=None, bigdl_type='float')[source]

Create a ImageSet from rdds of ndarray.

Parameters:
  • image_rdd – a rdd of ndarray, each ndarray should has dimension of 3 or 4 (3D images)
  • label_rdd – a rdd of ndarray
Returns:

a DistributedImageSet

get_image(key='floats', to_chw=True)[source]

get image from ImageSet

get_label()[source]

get label from ImageSet

get_predict(key='predict')[source]

get prediction from ImageSet

is_distributed()[source]

whether this is a DistributedImageSet

is_local()[source]

whether this is a LocalImageSet

label_map
Returns:the labelMap of this ImageSet, None if the ImageSet does not have a labelMap
classmethod read(path, sc=None, min_partitions=1, resize_height=-1, resize_width=-1, image_codec=-1, with_label=False, one_based_label=True, bigdl_type='float')[source]

Read images as Image Set if sc is defined, Read image as DistributedImageSet from local file system or HDFS if sc is null, Read image as LocalImageSet from local file system :param path path to read images if sc is defined, path can be local or HDFS. Wildcard character are supported. if sc is null, path is local directory/image file/image file with wildcard character

if withLabel is set to true, path should be a directory that have two levels. The first level is class folders, and the second is images. All images belong to a same class should be put into the same class folder. So each image in the path is labeled by the folder it belongs.

:param sc SparkContext :param min_partitions A suggestion value of the minimal splitting number for input data. :param resize_height height after resize, by default is -1 which will not resize the image :param resize_width width after resize, by default is -1 which will not resize the image :param image_codec specifying the color type of a loaded image, same as in OpenCV.imread. By default is Imgcodecs.CV_LOAD_IMAGE_UNCHANGED(-1) :param with_label whether to treat folders in the path as image classification labels and read the labels into ImageSet. :param one_based_label whether to use one based label :return ImageSet

to_image_frame(bigdl_type='float')[source]
transform(transformer)[source]

transformImageSet

class zoo.feature.image.imageset.LocalImageSet(image_list=None, label_list=None, jvalue=None, bigdl_type='float')[source]

Bases: zoo.feature.image.imageset.ImageSet

LocalImageSet wraps a list of ImageFeature

get_image(key='floats', to_chw=True)[source]

get image list from ImageSet

get_label()[source]

get label list from ImageSet

get_predict(key='predict')[source]

get prediction list from ImageSet

Module contents