ó šÄïYc@@s'dZddlmZmZddlZddlZddlZddlZddlZ yddl Z Wne k r�dZ nXddl mZddlmZddlmZddlmZdd lmZdd lmZdd lmZd „Zd „Zd„Zd;d„Zdd„Zddd„Zdd„Z dd„Z!dd„Z"dd„Z#de$fd„ƒYZ%de%fd„ƒYZ&de%fd„ƒYZ'de%fd„ƒYZ(de%fd„ƒYZ)d e%fd!„ƒYZ*d"e%fd#„ƒYZ+d$e%fd%„ƒYZ,d&e%fd'„ƒYZ-d(e%fd)„ƒYZ.d*e%fd+„ƒYZ/d,e+fd-„ƒYZ0d.e%fd/„ƒYZ1d0e%fd1„ƒYZ2d2e%fd3„ƒYZ3d4e%fd5„ƒYZ4d6e%fd7„ƒYZ5de6e6e6dddddddddd8„ Z7d9ej8fd:„ƒYZ9dS(<s6Read individual image files and perform augmentations.i(tabsolute_importtprint_functionNi(t numeric_types(tndarray(t_ndarray_internal(t _cvimresize(t_cvcopyMakeBorder(tio(trecordiocO@stj|||ŽS(s Read and decode an image to an NDArray. Note: `imread` uses OpenCV (not the CV2 Python library). MXNet must have been built with USE_OPENCV=1 for `imdecode` to work. Parameters ---------- filename : str Name of the image file to be loaded. flag : {0, 1}, default 1 1 for three channel color output. 0 for grayscale output. to_rgb : bool, default True True for RGB formatted output (MXNet default). False for BGR formatted output (OpenCV default). out : NDArray, optional Output buffer. Use `None` for automatic allocation. Returns ------- NDArray An `NDArray` containing the image. Example ------- >>> mx.img.imread("flower.jpg") Set `flag` parameter to 0 to get grayscale output >>> mx.img.imdecode("flower.jpg", flag=0) Set `to_rgb` parameter to 0 to get output in OpenCV format (BGR) >>> mx.img.imdecode(str_image, to_rgb=0) (t _internalt _cvimread(tfilenametargstkwargs((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pytimread,s&cO@sRt|tjƒs?tjtj|dtjƒdtjƒ}ntj|||ŽS(suDecode an image to an NDArray. Note: `imdecode` uses OpenCV (not the CV2 Python library). MXNet must have been built with USE_OPENCV=1 for `imdecode` to work. Parameters ---------- buf : str/bytes or numpy.ndarray Binary image data as string or numpy ndarray. flag : int, optional, default=1 1 for three channel color output. 0 for grayscale output. to_rgb : int, optional, default=1 1 for RGB formatted output (MXNet default). 0 for BGR formatted output (OpenCV default). out : NDArray, optional Output buffer. Use `None` for automatic allocation. Returns ------- NDArray An `NDArray` containing the image. Example ------- >>> with open("flower.jpg", 'rb') as fp: ... str_image = fp.read() ... >>> image = mx.img.imdecode(str_image) >>> image Set `flag` parameter to 0 to get grayscale output >>> with open("flower.jpg", 'rb') as fp: ... str_image = fp.read() ... >>> image = mx.img.imdecode(str_image, flag=0) >>> image Set `to_rgb` parameter to 0 to get output in OpenCV format (BGR) >>> with open("flower.jpg", 'rb') as fp: ... str_image = fp.read() ... >>> image = mx.img.imdecode(str_image, to_rgb=0) >>> image tdtype( t isinstancetndtNDArraytarraytnpt frombuffertuint8R t _cvimdecode(tbufR R ((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pytimdecodeUs1-cC@s‚|\}}|\}}||krBt||ƒ||}}n||krl|t||ƒ|}}nt|ƒt|ƒfS(sšScales down crop size if it's larger than image size. If width/height of the crop is larger than the width/height of the image, sets the width/height to the width/height of the image. Parameters ---------- src_size : tuple of int Size of the image in (width, height) format. size : tuple of int Size of the crop in (width, height) format. Returns ------- tuple of int A tuple containing the scaled crop size in (width, height) format. Example -------- >>> src_size = (640,480) >>> size = (720,120) >>> new_size = mx.img.scale_down(src_size, size) >>> new_size (640,106) (tfloattint(tsrc_sizetsizetwthtswtsh((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyt scale_down‹s    cC@sÁ|dkr‚|r{t|ƒdks*t‚|\}}}}||krX||krXdS||krt||krtdSdSq‚dSn|dkržtjddƒS|d kr½td|ƒ‚n|S( sðGet the interpolation method for resize functions. The major purpose of this function is to wrap a random interp method selection and a auto-estimation method. Parameters ---------- interp : int interpolation method for all resizing operations Possible values: 0: Nearest Neighbors Interpolation. 1: Bilinear interpolation. 2: Area-based (resampling using pixel area relation). It may be a preferred method for image decimation, as it gives moire-free results. But when the image is zoomed, it is similar to the Nearest Neighbors method. (used by default). 3: Bicubic interpolation over 4x4 pixel neighborhood. 4: Lanczos interpolation over 8x8 pixel neighborhood. 9: Cubic for enlarge, area for shrink, bilinear for others 10: Random select from interpolation method metioned above. Note: When shrinking an image, it will generally look best with AREA-based interpolation, whereas, when enlarging an image, it will generally look best with Bicubic (slow) or Bilinear (faster but still looks OK). More details can be found in the documentation of OpenCV, please refer to http://docs.opencv.org/master/da/d54/group__imgproc__transform.html. sizes : tuple of int (old_height, old_width, new_height, new_width), if None provided, auto(9) will return Area(2) anyway. Returns ------- int interp method from 0 to 4 i iiiii isUnknown interp method %d(iiiii(tlentAssertionErrortrandomtrandintt ValueError(tinterptsizestohtowtnhtnw((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyt_get_interp_method®s$   c C@sv|j\}}}||kr6||||}}n||||}}t|||dt|||||fƒƒS(sâResizes shorter edge to size. Note: `resize_short` uses OpenCV (not the CV2 Python library). MXNet must have been built with OpenCV for `resize_short` to work. Resizes the original image by setting the shorter edge to size and setting the longer edge accordingly. Resizing function is called from OpenCV. Parameters ---------- src : NDArray The original image. size : int The length to be set for the shorter edge. interp : int, optional, default=2 Interpolation method used for resizing the image. Possible values: 0: Nearest Neighbors Interpolation. 1: Bilinear interpolation. 2: Area-based (resampling using pixel area relation). It may be a preferred method for image decimation, as it gives moire-free results. But when the image is zoomed, it is similar to the Nearest Neighbors method. (used by default). 3: Bicubic interpolation over 4x4 pixel neighborhood. 4: Lanczos interpolation over 8x8 pixel neighborhood. 9: Cubic for enlarge, area for shrink, bilinear for others 10: Random select from interpolation method metioned above. Note: When shrinking an image, it will generally look best with AREA-based interpolation, whereas, when enlarging an image, it will generally look best with Bicubic (slow) or Bilinear (faster but still looks OK). More details can be found in the documentation of OpenCV, please refer to http://docs.opencv.org/master/da/d54/group__imgproc__transform.html. Returns ------- NDArray An 'NDArray' containing the resized image. Example ------- >>> with open("flower.jpeg", 'rb') as fp: ... str_image = fp.read() ... >>> image = mx.img.imdecode(str_image) >>> image >>> size = 640 >>> new_image = mx.img.resize_short(image, size) >>> new_image R((tshapetimresizeR.(tsrcRR(RRt_tnew_htnew_w((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyt resize_shortås 6 c C@sŸtj|d||dfd||||t|jdƒfƒ}|dk r›||f|kr›|||d|df}t|dt||ƒ|Œ}n|S(s`Crop src at fixed location, and (optionally) resize it to size. Parameters ---------- src : NDArray Input image x0 : int Left boundary of the cropping area y0 : int Top boundary of the cropping area w : int Width of the cropping area h : int Height of the cropping area size : tuple of (w, h) Optional, resize to new size after cropping interp : int, optional, default=2 Interpolation method. See resize_short for details. Returns ------- NDArray An `NDArray` containing the cropped image. tbeginitendiiR(N(RtcropRR/tNoneR0R.( R1tx0ty0RRRR(toutR)((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyt fixed_crop#s B!c C@s�|j\}}}t||f|ƒ\}}tjd||ƒ}tjd||ƒ} t||| ||||ƒ} | || ||ffS(s±Randomly crop `src` with `size` (width, height). Upsample result if `src` is smaller than `size`. Parameters ---------- src: Source image `NDArray` size: Size of the crop formatted as (width, height). If the `size` is larger than the image, then the source image is upsampled to `size` and returned. interp: int, optional, default=2 Interpolation method. See resize_short for details. Returns ------- NDArray An `NDArray` containing the cropped image. Tuple A tuple (x, y, width, height) where (x, y) is top-left position of the crop in the original image and (width, height) are the dimensions of the cropped image. Example ------- >>> im = mx.nd.array(cv2.imread("flower.jpg")) >>> cropped_im, rect = mx.image.random_crop(im, (100, 100)) >>> print cropped_im >>> print rect (20, 21, 100, 100) i(R/R"R%R&R=( R1RR(RRR2R4R3R:R;R<((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyt random_cropCs c C@s‰|j\}}}t||f|ƒ\}}t||dƒ}t||dƒ} t||| ||||ƒ} | || ||ffS(sVCrops 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`. .. note:: This requires MXNet to be compiled with USE_OPENCV. Parameters ---------- src : NDArray Binary source image data. size : list or tuple of int The desired output image size. interp : int, optional, default=2 Interpolation method. See resize_short for details. Returns ------- NDArray The cropped image. Tuple (x, y, width, height) where x, y are the positions of the crop in the original image and width, height the dimensions of the crop. Example ------- >>> with open("flower.jpg", 'rb') as fp: ... str_image = fp.read() ... >>> image = mx.image.imdecode(str_image) >>> image >>> cropped_image, (x, y, width, height) = mx.image.center_crop(image, (1000, 500)) >>> cropped_image >>> x, y, width, height (1241, 910, 1000, 500) i(R/R"RR=( R1RR(RRR2R4R3R:R;R<((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyt center_cropjs 'cC@s6|dk r||8}n|dk r2||:}n|S(s9Normalize src with mean and std. Parameters ---------- src : NDArray Input image mean : NDArray RGB mean to be subtracted std : NDArray RGB standard deviation to be divided Returns ------- NDArray An `NDArray` containing the normalized image. N(R9(R1tmeantstd((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pytcolor_normalize›s     c C@s@|j\}}}||}xtdƒD]}tj|dƒ|} tj|Œ} tttj| | ƒƒƒ} tttj| | ƒƒƒ} tjƒdkr´| | } } n| |kr)| |kr)tjd|| ƒ} tjd|| ƒ}t || || | ||ƒ}|| || | ffSq)Wt |||ƒS(sþRandomly crop src with size. Randomize area and aspect ratio. Parameters ---------- src : NDArray Input image size : tuple of (int, int) Size of the crop formatted as (width, height). min_area : int Minimum area to be maintained after cropping ratio : tuple of (float, float) Aspect ratio range as (min_aspect_ratio, max_aspect_ratio) interp: int, optional, default=2 Interpolation method. See resize_short for details. Returns ------- NDArray An `NDArray` containing the cropped image. Tuple A tuple (x, y, width, height) where (x, y) is top-left position of the crop in the original image and (width, height) are the dimensions of the cropped image. i gð?gà?i( R/trangeR%tuniformRtroundRtsqrtR&R=R?(R1Rtmin_areatratioR(RRR2tareat target_areat new_ratioR4R3R:R;R<((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pytrandom_size_crop³s t AugmentercB@s)eZdZd„Zd„Zd„ZRS(sImage Augmenter base classcK@s|||_xl|jjƒD][\}}t|tjƒrF|jƒ}nt|tjƒr|jƒ}||j|RR((RRR1((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR\4s(RYR]R^RUR\(((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRb%s  tRandomSizedCropAugcB@s#eZdZdd„Zd„ZRS(sÙMake random crop with random resizing and random aspect ratio jitter augmenter. Parameters ---------- size : tuple of (int, int) Size of the crop formatted as (width, height). min_area : int Minimum area to be maintained after cropping ratio : tuple of (float, float) Aspect ratio range as (min_aspect_ratio, max_aspect_ratio) interp: int, optional, default=2 Interpolation method. See resize_short for details. ic C@sStt|ƒjd|d|d|d|ƒ||_||_||_||_dS(NRRGRHR((R`RcRURRGRHR((RRRRGRHR(((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRUGs     cC@s&t||j|j|j|jƒdS(sAugmenter bodyi(RLRRGRHR((RRR1((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR\Os(RYR]R^RUR\(((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRc9s  t CenterCropAugcB@s#eZdZdd„Zd„ZRS(sèMake center crop augmenter. Parameters ---------- size : list or tuple of int The desired output image size. interp : int, optional, default=2 Interpolation method. See resize_short for details. icC@s5tt|ƒjd|d|ƒ||_||_dS(NRR((R`RdRURR((RRRR(((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRU^s cC@st||j|jƒdS(sAugmenter bodyi(R?RR((RRR1((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR\cs(RYR]R^RUR\(((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRdTs  tRandomOrderAugcB@s)eZdZd„Zd„Zd„ZRS(s¥Apply list of augmenters in random order Parameters ---------- ts : list of augmenters A series of augmenters to be applied in random order cC@s tt|ƒjƒ||_dS(N(R`ReRUtts(RRRf((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRUpscC@s2|jjjƒg|jD]}|jƒ^qgS(s-Override the default to avoid duplicate dump.(RXRYRZRfRW(RRtx((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRWtscC@s4tj|jƒx|jD]}||ƒ}qW|S(sAugmenter body(R%tshuffleRf(RRR1tt((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR\xs(RYR]R^RURWR\(((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRehs  tBrightnessJitterAugcB@s eZdZd„Zd„ZRS(s“Random brightness jitter augmentation. Parameters ---------- brightness : float The brightness jitter ratio range, [0, 1] cC@s&tt|ƒjd|ƒ||_dS(Nt brightness(R`RjRURk(RRRk((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRUˆscC@s+dtj|j |jƒ}||9}|S(sAugmenter bodygð?(R%RDRk(RRR1talpha((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR\Œs (RYR]R^RUR\(((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRj€s tContrastJitterAugcB@s eZdZd„Zd„ZRS(s�Random contrast jitter augmentation. Parameters ---------- contrast : float The contrast jitter ratio range, [0, 1] cC@sGtt|ƒjd|ƒ||_tjdddgggƒ|_dS(Ntcontrastg‰A`åÐ"Ó?gbX9´Èâ?gÉv¾Ÿ/½?(R`RmRURnRRtcoef(RRRn((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRU›s cC@sddtj|j |jƒ}||j}dd||jtj|ƒ}||9}||7}|S(sAugmenter bodygð?g@(R%RDRnRoRRtsum(RRR1Rltgray((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR\ s  "  (RYR]R^RUR\(((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRm“s tSaturationJitterAugcB@s eZdZd„Zd„ZRS(s“Random saturation jitter augmentation. Parameters ---------- saturation : float The saturation jitter ratio range, [0, 1] cC@sGtt|ƒjd|ƒ||_tjdddgggƒ|_dS(Nt saturationg‰A`åÐ"Ó?gbX9´Èâ?gÉv¾Ÿ/½?(R`RrRURsRRRo(RRRs((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRU²s cC@skdtj|j |jƒ}||j}tj|dddtƒ}|d|9}||9}||7}|S(sAugmenter bodygð?taxisitkeepdims(R%RDRsRoRRptTrue(RRR1RlRq((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR\·s   (RYR]R^RUR\(((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRrªs t HueJitterAugcB@s eZdZd„Zd„ZRS(s~Random hue jitter augmentation. Parameters ---------- hue : float The hue jitter ratio range, [0, 1] cC@s’tt|ƒjd|ƒ||_tjdddgdddgdd d ggƒ|_tjd d d gd ddgd ddggƒ|_dS(Nthueg‰A`åÐ"Ó?gbX9´Èâ?gÉv¾Ÿ/½?gßO�—nã?gð§ÆK7‰Ñ¿g%�•C‹Ô¿g5^ºI Ë?g#Ûù~j¼à¿g�•C‹lçÓ?gð?gd;ßO�—î?g¬Zd;ßã?gœÄ °rhÑ¿gNbX9´ä¿gƒÀÊ¡E¶ñ¿gHáz®Gû?(R`RwRURxRRttyiqtityiq(RRRx((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRUÊs   cC@s¿tj|j |jƒ}tj|tjƒ}tj|tjƒ}tjdddgd|| gd||ggƒ}tjtj|j |ƒ|j ƒj }t j|t j|ƒƒ}|S(s�Augmenter body. Using approximate linear transfomation described in: https://beesbuzz.biz/code/hsv_color_transforms.php gð?g( R%RDRxRtcostpitsinRtdotRyRztTR(RRR1RltvsutvswtbtRi((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR\Ôs '(RYR]R^RUR\(((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRwÂs tColorJitterAugcB@seZdZd„ZRS(sCApply random brightness, contrast and saturation jitter in random order. Parameters ---------- brightness : float The brightness jitter ratio range, [0, 1] contrast : float The contrast jitter ratio range, [0, 1] saturation : float The saturation jitter ratio range, [0, 1] cC@s†g}|dkr(|jt|ƒƒn|dkrJ|jt|ƒƒn|dkrl|jt|ƒƒntt|ƒj|ƒdS(Ni(tappendRjRmRrR`RƒRU(RRRkRnRsRf((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRUðs   (RYR]R^RU(((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRƒäs t LightingAugcB@s eZdZd„Zd„ZRS(sÀAdd PCA based noise. Parameters ---------- alphastd : float Noise level eigval : 3x1 np.array Eigen values eigvec : 3x3 np.array Eigen vectors cC@sDtt|ƒjd|d|d|ƒ||_||_||_dS(Ntalphastdteigvalteigvec(R`R…RUR†R‡Rˆ(RRR†R‡Rˆ((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRUs%  cC@sQtjjd|jddƒ}tj|j||jƒ}|tj|ƒ7}|S(sAugmenter bodyiRi(i( RR%tnormalR†R~RˆR‡RR(RRR1Rltrgb((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR\ s(RYR]R^RUR\(((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR…ûs  tColorNormalizeAugcB@s eZdZd„Zd„ZRS(s³Mean and std normalization. Parameters ---------- mean : NDArray RGB mean to be subtracted std : NDArray RGB standard deviation to be divided cC@sktt|ƒjd|d|ƒ|dk r:tj|ƒnd|_|dk r^tj|ƒnd|_dS(NR@RA(R`R‹RUR9RRR@RA(RRR@RA((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRUs$cC@st||j|jƒS(sAugmenter body(RBR@RA(RRR1((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR\$s(RYR]R^RUR\(((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR‹s  t RandomGrayAugcB@s eZdZd„Zd„ZRS(s}Randomly convert to gray image. Parameters ---------- p : float Probability to convert to grayscale cC@s\tt|ƒjd|ƒ||_tjdddgdddgdddggƒ|_dS(Ntpgáz®GáÊ?g ×£p= ç?gìQ¸…ë±?(R`RŒRUR�RRtmat(RRR�((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRU1s   cC@s1tjƒ|jkr-tj||jƒ}n|S(sAugmenter body(R%R�RR~RŽ(RRR1((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR\8s(RYR]R^RUR\(((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRŒ)s tHorizontalFlipAugcB@s eZdZd„Zd„ZRS(sxRandom horizontal flip. Parameters ---------- p : float Probability to flip image horizontally cC@s&tt|ƒjd|ƒ||_dS(NR�(R`R�RUR�(RRR�((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRUGscC@s1tjƒ|jkr-tj|ddƒ}n|S(sAugmenter bodyRti(R%R�Rtflip(RRR1((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR\Ks(RYR]R^RUR\(((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR�?s tCastAugcB@s eZdZd„Zd„ZRS(sCast to float32cC@stt|ƒjddƒdS(Nttypetfloat32(R`R‘RU(RR((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRUTscC@s|jtjƒ}|S(sAugmenter body(tastypeRR“(RRR1((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR\Ws(RYR]R^RUR\(((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR‘Rs cC@sµg}|dkr+|jt|| ƒƒn|d|df}|r~|sQt‚|jt|dddddf| ƒƒn5|r�|jt|| ƒƒn|jt|| ƒƒ|rÏ|jtdƒƒn|jtƒƒ|sñ|sñ| r |jt||| ƒƒn| r)|jt | ƒƒn| dkrœt j dd d gƒ}t j d d d gdddgdddggƒ}|jt | ||ƒƒn| dkr¾|jt | ƒƒn|tkråt j dddgƒ}n:|dk rt|t jƒr|jddkst‚n|tkrFt j dddgƒ}n:|dk r€t|t jƒrw|jddks€t‚n|dk s˜|dk r±|jt||ƒƒn|S(s� Creates an augmenter list. Parameters ---------- data_shape : tuple of int Shape for output data resize : int Resize shorter edge if larger than 0 at the begining rand_crop : bool Whether to enable random cropping other than center crop rand_resize : bool Whether to enable random sized cropping, require rand_crop to be enabled rand_gray : float [0, 1], probability to convert to grayscale for all channels, the number of channels will not be reduced to 1 rand_mirror : bool Whether to apply horizontal flip to image with probability 0.5 mean : np.ndarray or None Mean pixel values for [r, g, b] std : np.ndarray or None Standard deviations for [r, g, b] brightness : float Brightness jittering range (percent) contrast : float Contrast jittering range (percent) saturation : float Saturation jittering range (percent) hue : float Hue jittering range (percent) pca_noise : float Pca noise level (percent) inter_method : int, default=2(Area-based) Interpolation method for all resizing operations Possible values: 0: Nearest Neighbors Interpolation. 1: Bilinear interpolation. 2: Area-based (resampling using pixel area relation). It may be a preferred method for image decimation, as it gives moire-free results. But when the image is zoomed, it is similar to the Nearest Neighbors method. (used by default). 3: Bicubic interpolation over 4x4 pixel neighborhood. 4: Lanczos interpolation over 8x8 pixel neighborhood. 9: Cubic for enlarge, area for shrink, bilinear for others 10: Random select from interpolation method metioned above. Note: When shrinking an image, it will generally look best with AREA-based interpolation, whereas, when enlarging an image, it will generally look best with Bicubic (slow) or Bilinear (faster but still looks OK). Examples -------- >>> # An example of creating multiple augmenters >>> augs = mx.image.CreateAugmenter(data_shape=(3, 300, 300), rand_mirror=True, ... mean=True, brightness=0.125, contrast=0.125, rand_gray=0.05, ... saturation=0.125, pca_noise=0.05, inter_method=10) >>> # dump the details >>> for aug in augs: ... aug.dumps() iiig{®Gáz´?g@g@gà?g{®GáºK@g“V-@g‘í|?5^ò?g)\�Âõ(â¿gùé·¯ç?gÙ=yX¨Ù?g ‰°áé•â¿g;ßO�—nr¿g?5^ºI ê¿g[B>èÙ¬â¿gyX¨5Í;æ¿g.� ø1æÚ?gìQ¸…ë^@gR¸…ë]@gR¸…ëáY@igÃõ(\�2M@g�Âõ(\�L@g°L@N(ii(ii(R„R_R$RcRbRdR�R‘RƒRwRRR…RŒRvR9RRR/R‹(t data_shapetresizet rand_cropt rand_resizet rand_mirrorR@RARkRnRsRxt pca_noiset rand_grayt inter_methodtauglistt crop_sizeR‡Rˆ((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pytCreateAugmenter]sH?  -     .  .t ImageIterc B@sŒeZdZdddddeddddddd„ Zd„Zd„Zd„Zd „Z d „Z d „Z d „Z d „Z d„ZRS(sImage data iterator with a large number of augmentation choices. This iterator supports reading from both .rec files and raw image files. To load input images from .rec files, use `path_imgrec` parameter and to load from raw image files, use `path_imglist` and `path_root` parameters. To use data partition (for distributed training) or shuffling, specify `path_imgidx` parameter. Parameters ---------- batch_size : int Number of examples per batch. data_shape : tuple Data shape in (channels, height, width) format. For now, only RGB image with 3 channels is supported. label_width : int, optional Number of labels per example. The default label width is 1. path_imgrec : str Path to image record file (.rec). Created with tools/im2rec.py or bin/im2rec. path_imglist : str Path to image list (.lst). Created with tools/im2rec.py or with custom script. Format: Tab separated record of index, one or more labels and relative_path_from_root. imglist: list A list of images with the label(s). Each item is a list [imagelabel: float or list of float, imgpath]. path_root : str Root folder of image files. path_imgidx : str Path to image index file. Needed for partition and shuffling when using .rec source. shuffle : bool Whether to shuffle all images at the start of each iteration or not. Can be slow for HDD. part_index : int Partition index. num_parts : int Total number of partitions. data_name : str Data name for provided symbols. label_name : str Label name for provided symbols. kwargs : ... More arguments for creating augmenter. See mx.image.CreateAugmenter. iitdatat softmax_labelc K@sGtt|ƒjƒ|s4|s4t| tƒs4t‚tjjddƒ}t j dt |ƒƒt j dƒ|j j }|rèt j d||ƒ|rÇtj||dƒ|_t|jjƒ|_qñtj|dƒ|_d|_n d|_|rÉt j d||ƒt|ƒ�®}i} g}x�t|jdƒD]{}|jƒjd ƒ}tjg|dd !D]}t|ƒ^qgƒ}t|d ƒ}||d f| |<|j|ƒq8W| |_WdQXnût| tƒr»t j d |ƒi}g}d}x²| D]ª}t |ƒ}|d7}t |ƒd krEtj|d ƒ}n?t|d t!ƒrqtj|d gƒ}ntj|d ƒ}||d f||<|jt |ƒƒqW||_n d|_||_"|j#|ƒ| |f|fg|_$|dkr|||ffg|_%n||ffg|_%||_&||_'||_(||_)|jdkrn||_*n?|s€| dkr¤|jdk s•t‚|j|_*n d|_*| dkr| | ksËt‚t |j*ƒ}|| }|j*| || d|!|_*n| dkr't+||�|_,n | |_,d |_-|j.ƒdS(NtMXNET_CPU_WORKER_NTHREADSis Using %s threads for decoding...sYSet enviroment variable MXNET_CPU_WORKER_NTHREADS to a larger number to use more threads.s%s: loading recordio %s...trs%s: loading image list %s...ts iÿÿÿÿis%s: loading image list...i(/R`R RURtlistR$tostenvirontgettloggingtinfotstrRXRYRtMXIndexedRecordIOtimgrectkeystimgidxt MXRecordIOR9topentitertreadlinetstriptsplitRRRRR„timglistR#Rt path_roottcheck_data_shapet provide_datat provide_labelt batch_sizeR•t label_widthRhtseqRŸR�tcurtreset(RRR¼R•R½t path_imgrect path_imglistR¸t path_imgidxRht part_indext num_partstaug_listR·t data_namet label_nameR t num_threadst class_nametfintimgkeystlinetitlabeltkeytresulttindextimgtNtC((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRUþsŒ!      /                "   cC@sH|jrtj|jƒn|jdk r;|jjƒnd|_dS(s1Resets the iterator to the beginning of the data.iN(RhR%R¾R®R9RÀR¿(RR((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRÀUs  cC@s,|jdk râ|jt|jƒkr0t‚n|j|j}|jd7_|jdk r¹|jj|ƒ}tj|ƒ\}}|j dkr¡|j |fS|j |d|fSq(|j |\}}||j |ƒfSnF|jj ƒ}|dkrt‚ntj|ƒ\}}|j |fSdS(s+Helper function for reading in next sample.iiN( R¾R9R¿R#t StopIterationR®tread_idxRtunpackR·RÏt read_imagetread(RRtidxtstheaderRÓRÏtfname((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyt next_sample]s$    c C@s\|j}|j\}}}tj||||fƒ}tj|jddƒ}d}yÆx¿||kr|jƒ\}} |j| ƒ} y|j| ƒWn,tk rÈ} t j dt | ƒƒq\nX|j | ƒ} ||ksðt dƒ‚|j| ƒ||<|||<|d7}q\WWn tk r>|s?t‚q?nXtj|g|g||ƒS(sReturns the next batch of data.iisInvalid image, skipping: %ss7Batch size must be multiples of augmenter output length(R¼R•RtemptyR»RßRtcheck_valid_imaget RuntimeErrorRªtdebugR¬taugmentation_transformR$tpostprocess_dataRÖRt DataBatch( RRR¼tcRRt batch_datat batch_labelRÎRÏRÜR¡te((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pytnextus.    cC@sDt|ƒdks!tdƒ‚n|ddks@tdƒ‚ndS(s'Checks if the input data shape is validis6data_shape should have length 3, with dimensions CxHxWis0This iterator expects inputs to have 3 channels.N(R#R'(RRR•((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR¹�scC@s,t|djƒdkr(tdƒ‚ndS(s!Checks if the input data is validisData shape is wrongN(R#R/Râ(RRR¡((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRá—scC@s t|ƒS(s\Decodes a string or byte string to an NDArray. See mx.img.imdecode for more details.(R(RRRÜ((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRœscC@s:ttjj|j|ƒdƒ�}|jƒ}WdQX|S(s¼Reads an input image `fname` and returns the decoded raw bytes. Example usage: ---------- >>> dataIter.read_image('Face.jpg') # returns decoded raw bytes. trbN(R²R§tpathtjoinR¸RÚ(RRRÞRËRÓ((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRÙ¡s$cC@s$x|jD]}||ƒ}q W|S(s2Transforms input data with specified augmentation.(R�(RRR¡taug((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRä¬scC@stj|ddƒS(s@Final postprocessing step before image is loaded into the batch.taxesiii(iii(Rt transpose(RRtdatum((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyRå²sN(RYR]R^R9tFalseRURÀRßRëR¹RáRRÙRäRå(((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyR Ïs- T       ((:R^t __future__RRR§R%RªRVtnumpyRtcv2t ImportErrorR9tbaseRR¥RRRR RR0RtcopyMakeBorderRRRRR"R.R5R=R>R?RBRLtobjectRMR_RaRbRcRdReRjRmRrRwRƒR…R‹RŒR�R‘RóRŸtDataIterR (((s1build/bdist.linux-armv7l/egg/mxnet/image/image.pyts`        ) 6 # 7 > ' 1  /" p