ó ùµÈ[c@s dZddlmZmZddlmZmZddlmZddl m Z defd„ƒYZ d efd „ƒYZ d efd „ƒYZ d efd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd „ƒYZd!efd"„ƒYZd#efd$„ƒYZd%S(&sImage transforms.i(tBlockt HybridBlock(t SequentialtHybridSequentiali(timage(t numeric_typestComposecBseZdZd„ZRS(sÜSequentially composes multiple transforms. Parameters ---------- transforms : list of transform Blocks. The list of transforms to be composed. Inputs: - **data**: input tensor with shape of the first transform Block requires. Outputs: - **out**: output tensor with shape of the last transform Block produces. Examples -------- >>> transformer = transforms.Compose([transforms.Resize(300), ... transforms.CenterCrop(256), ... transforms.ToTensor()]) >>> image = mx.nd.random.uniform(0, 255, (224, 224, 3)).astype(dtype=np.uint8) >>> transformer(image) cCsþtt|ƒjƒ|jdƒg}xÑ|D]É}t|tƒrU|j|ƒq-n…t|ƒdkr|j|dƒg}nYt|ƒdkrÚt ƒ}x|D]}|j|ƒq£W|j ƒ|j|ƒg}n|dk r-|j|ƒq-q-WdS(Nii( tsuperRt__init__tappendtNonet isinstanceRtlentaddRt hybridize(tselft transformsthybridtithblocktj((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR4s&          (t__name__t __module__t__doc__R(((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRstCastcBs#eZdZdd„Zd„ZRS(s6Cast input to a specific data type Parameters ---------- dtype : str, default 'float32' The target data type, in string or `numpy.dtype`. Inputs: - **data**: input tensor with arbitrary shape. Outputs: - **out**: output tensor with the same shape as `data`. tfloat32cCs tt|ƒjƒ||_dS(N(RRRt_dtype(Rtdtype((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRZscCs|j||jƒS(N(tcastR(RtFtx((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pythybrid_forward^s(RRRRR(((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRKs tToTensorcBs eZdZd„Zd„ZRS(sÐConverts an image NDArray to a tensor NDArray. Converts an image NDArray of shape (H x W x C) in the range [0, 255] to a float32 tensor NDArray of shape (C x H x W) in the range [0, 1). Inputs: - **data**: input tensor with (H x W x C) shape and uint8 type. Outputs: - **out**: output tensor with (C x H x W) shape and float32 type. Examples -------- >>> transformer = vision.transforms.ToTensor() >>> image = mx.nd.random.uniform(0, 255, (4, 2, 3)).astype(dtype=np.uint8) >>> transformer(image) [[[ 0.85490197 0.72156864] [ 0.09019608 0.74117649] [ 0.61960787 0.92941177] [ 0.96470588 0.1882353 ]] [[ 0.6156863 0.73725492] [ 0.46666667 0.98039216] [ 0.44705883 0.45490196] [ 0.01960784 0.8509804 ]] [[ 0.39607844 0.03137255] [ 0.72156864 0.52941179] [ 0.16470589 0.7647059 ] [ 0.05490196 0.70588237]]] cCstt|ƒjƒdS(N(RR R(R((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR‚scCs|jj|ƒS(N(Rt to_tensor(RRR((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR…s(RRRRR(((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR bs t NormalizecBs eZdZd„Zd„ZRS(s’Normalize an tensor of shape (C x H x W) with mean and standard deviation. Given mean `(m1, ..., mn)` and std `(s1, ..., sn)` for `n` channels, this transform normalizes each channel of the input tensor with:: output[i] = (input[i] - mi) / si If mean or std is scalar, the same value will be applied to all channels. Parameters ---------- mean : float or tuple of floats The mean values. std : float or tuple of floats The standard deviation values. Inputs: - **data**: input tensor with (C x H x W) shape. Outputs: - **out**: output tensor with the shape as `data`. cCs)tt|ƒjƒ||_||_dS(N(RR"Rt_meant_std(Rtmeantstd((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR¢s cCs|jj||j|jƒS(N(Rt normalizeR#R$(RRR((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR§s(RRRRR(((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR"‰s tRandomResizedCropcBs7eZdZdddddfdd„Zd„ZRS( s²Crop the input image with random scale and aspect ratio. Makes a crop of the original image with random size (default: 0.08 to 1.0 of the original image size) and random aspect ratio (default: 3/4 to 4/3), then resize it to the specified size. Parameters ---------- size : int or tuple of (W, H) Size of the final output. scale : tuple of two floats If scale is `(min_area, max_area)`, the cropped image's area will range from min_area to max_area of the original image's area ratio : tuple of two floats Range of aspect ratio of the cropped image before resizing. interpolation : int Interpolation method for resizing. By default uses bilinear interpolation. See OpenCV's resize function for available choices. Inputs: - **data**: input tensor with (Hi x Wi x C) shape. Outputs: - **out**: output tensor with (H x W x C) shape. g{®Gáz´?gð?g@g@icCsJtt|ƒjƒt|tƒr1||f}n||||f|_dS(N(RR(RR Rt_args(Rtsizetscaletratiot interpolation((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRÆscCstj||jŒdS(Ni(Rtrandom_size_cropR)(RR((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pytforwardÍs(g{®Gáz´?gð?(RRRRR/(((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR(«s t CenterCropcBs#eZdZdd„Zd„ZRS(s.Crops the image `src` to the given `size` by trimming on all four sides and preserving the center of the image. Upsamples if `src` is smaller than `size`. Parameters ---------- size : int or tuple of (W, H) Size of output image. interpolation : int Interpolation method for resizing. By default uses bilinear interpolation. See OpenCV's resize function for available choices. Inputs: - **data**: input tensor with (Hi x Wi x C) shape. Outputs: - **out**: output tensor with (H x W x C) shape. Examples -------- >>> transformer = vision.transforms.CenterCrop(size=(1000, 500)) >>> image = mx.nd.random.uniform(0, 255, (2321, 3482, 3)).astype(dtype=np.uint8) >>> transformer(image) icCsDtt|ƒjƒt|tƒr1||f}n||f|_dS(N(RR0RR RR)(RR*R-((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRìscCstj||jŒdS(Ni(Rt center_cropR)(RR((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR/òs(RRRRR/(((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR0Ñs tResizecBs&eZdZedd„Zd„ZRS(ssResize an image to the given size. Should be applied before `mxnet.gluon.data.vision.transforms.ToTensor`. Parameters ---------- size : int or tuple of (W, H) Size of output image. keep_ratio : bool Whether to resize the short edge or both edges to `size`, if size is give as an integer. interpolation : int Interpolation method for resizing. By default uses bilinear interpolation. See OpenCV's resize function for available choices. Inputs: - **data**: input tensor with (Hi x Wi x C) shape. Outputs: - **out**: output tensor with (H x W x C) shape. Examples -------- >>> transformer = vision.transforms.Resize(size=(1000, 500)) >>> image = mx.nd.random.uniform(0, 255, (224, 224, 3)).astype(dtype=np.uint8) >>> transformer(image) icCs2tt|ƒjƒ||_||_||_dS(N(RR2Rt_keept_sizet_interpolation(RR*t keep_ratioR-((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRs  cCs¶t|jtƒrŽ|js0|j}|j}q|j\}}}||krn|j}t|||ƒ}q|j}t|||ƒ}n|j\}}tj||||jƒS(N( R R4RR3tshapetintRtimresizeR5(RRtwsizethsizethtwt_((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR/s      (RRRtFalseRR/(((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR2östRandomFlipLeftRightcBs eZdZd„Zd„ZRS(sßRandomly flip the input image left to right with a probability of 0.5. Inputs: - **data**: input tensor with (H x W x C) shape. Outputs: - **out**: output tensor with same shape as `data`. cCstt|ƒjƒdS(N(RR@R(R((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR5scCs|jj|ƒS(N(Rtrandom_flip_left_right(RRR((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR8s(RRRRR(((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR@+s  tRandomFlipTopBottomcBs eZdZd„Zd„ZRS(sßRandomly flip the input image top to bottom with a probability of 0.5. Inputs: - **data**: input tensor with (H x W x C) shape. Outputs: - **out**: output tensor with same shape as `data`. cCstt|ƒjƒdS(N(RRBR(R((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRFscCs|jj|ƒS(N(Rtrandom_flip_top_bottom(RRR((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRIs(RRRRR(((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRB<s  tRandomBrightnesscBs eZdZd„Zd„ZRS(s»Randomly jitters image brightness with a factor chosen from `[max(0, 1 - brightness), 1 + brightness]`. Parameters ---------- brightness: float How much to jitter brightness. brightness factor is randomly chosen from `[max(0, 1 - brightness), 1 + brightness]`. Inputs: - **data**: input tensor with (H x W x C) shape. Outputs: - **out**: output tensor with same shape as `data`. cCs7tt|ƒjƒtdd|ƒd|f|_dS(Nii(RRDRtmaxR)(Rt brightness((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR^scCs|jj||jŒS(N(Rtrandom_brightnessR)(RRR((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRbs(RRRRR(((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRDMs tRandomContrastcBs eZdZd„Zd„ZRS(s«Randomly jitters image contrast with a factor chosen from `[max(0, 1 - contrast), 1 + contrast]`. Parameters ---------- contrast: float How much to jitter contrast. contrast factor is randomly chosen from `[max(0, 1 - contrast), 1 + contrast]`. Inputs: - **data**: input tensor with (H x W x C) shape. Outputs: - **out**: output tensor with same shape as `data`. cCs7tt|ƒjƒtdd|ƒd|f|_dS(Nii(RRHRRER)(Rtcontrast((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRwscCs|jj||jŒS(N(Rtrandom_contrastR)(RRR((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR{s(RRRRR(((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRHfs tRandomSaturationcBs eZdZd„Zd„ZRS(s»Randomly jitters image saturation with a factor chosen from `[max(0, 1 - saturation), 1 + saturation]`. Parameters ---------- saturation: float How much to jitter saturation. saturation factor is randomly chosen from `[max(0, 1 - saturation), 1 + saturation]`. Inputs: - **data**: input tensor with (H x W x C) shape. Outputs: - **out**: output tensor with same shape as `data`. cCs7tt|ƒjƒtdd|ƒd|f|_dS(Nii(RRKRRER)(Rt saturation((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRscCs|jj||jŒS(N(Rtrandom_saturationR)(RRR((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR”s(RRRRR(((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRKs t RandomHuecBs eZdZd„Zd„ZRS(sƒRandomly jitters image hue with a factor chosen from `[max(0, 1 - hue), 1 + hue]`. Parameters ---------- hue: float How much to jitter hue. hue factor is randomly chosen from `[max(0, 1 - hue), 1 + hue]`. Inputs: - **data**: input tensor with (H x W x C) shape. Outputs: - **out**: output tensor with same shape as `data`. cCs7tt|ƒjƒtdd|ƒd|f|_dS(Nii(RRNRRER)(Rthue((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR©scCs|jj||jŒS(N(Rt random_hueR)(RRR((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyR­s(RRRRR(((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRN˜s tRandomColorJittercBs,eZdZddddd„Zd„ZRS(sGRandomly jitters the brightness, contrast, saturation, and hue of an image. Parameters ---------- brightness : float How much to jitter brightness. brightness factor is randomly chosen from `[max(0, 1 - brightness), 1 + brightness]`. contrast : float How much to jitter contrast. contrast factor is randomly chosen from `[max(0, 1 - contrast), 1 + contrast]`. saturation : float How much to jitter saturation. saturation factor is randomly chosen from `[max(0, 1 - saturation), 1 + saturation]`. hue : float How much to jitter hue. hue factor is randomly chosen from `[max(0, 1 - hue), 1 + hue]`. Inputs: - **data**: input tensor with (H x W x C) shape. Outputs: - **out**: output tensor with same shape as `data`. icCs,tt|ƒjƒ||||f|_dS(N(RRQRR)(RRFRIRLRO((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRËscCs|jj||jŒS(N(Rtrandom_color_jitterR)(RRR((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRÏs(RRRRR(((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRQ±stRandomLightingcBs eZdZd„Zd„ZRS(sAdd AlexNet-style PCA-based noise to an image. Parameters ---------- alpha : float Intensity of the image. Inputs: - **data**: input tensor with (H x W x C) shape. Outputs: - **out**: output tensor with same shape as `data`. cCs tt|ƒjƒ||_dS(N(RRSRt_alpha(Rtalpha((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRâscCs|jj||jƒS(N(Rtrandom_lightingRT(RRR((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRæs(RRRRR(((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyRSÓs N(RtblockRRtnnRRtRtbaseRRRR R"R(R0R2R@RBRDRHRKRNRQRS(((sb/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/data/vision/transforms.pyts&/'"&%5"