Ë
    †\;jM  ã                   óv  — d Z ddlZddlZddlmZ ddlmZmZ ddlm	Z	m
Z
 ddlmZmZ ddlmZ g Zd	Zd
ZdZdZdZdZdZdZdZd„ Z ej6                  ed«      Z ej6                  ed«      Z	 	 	 dd„Z edddd¬«      edddfd„«       Z edddd¬«      edddfd„«       Z  edddd¬«      eddfd„«       Z!d„ Z"y) a‰  
This module will download dataset from
http://www.robots.ox.ac.uk/~vgg/data/flowers/102/index.html
and parse train/test dataset into paddle reader creators.

This set contains images of flowers belonging to 102 different categories.
The images were acquired by searching the web and taking pictures. There are a
minimum of 40 images for each category.

The database was used in:

Nilsback, M-E. and Zisserman, A. Automated flower classification over a large
 number of classes.Proceedings of the Indian Conference on Computer Vision,
Graphics and Image Processing (2008)
http://www.robots.ox.ac.uk/~vgg/publications/papers/nilsback08.{pdf,ps.gz}.

é    N)Ú	cpu_count)Úload_image_bytesÚsimple_transform)Úmap_readersÚxmap_readers)Ú
deprecatedÚ
try_importé   )Údownloadz8http://paddlemodels.bj.bcebos.com/flowers/102flowers.tgzz9http://paddlemodels.bj.bcebos.com/flowers/imagelabels.matz3http://paddlemodels.bj.bcebos.com/flowers/setid.matÚ 52808999861908f626f3c1f4e79d11faÚ e0620be6f572b9609742df49c70aed4dÚ a5357ecc9cb78c4bef273ce3793fc85cÚtstidÚtrnidÚvalidc                 óˆ   — |\  }}t        |«      }t        |dd| g d¢¬«      }|j                  «       j                  d«      |fS )zB
    map image bytes data to type needed by model input layer
    é   éà   )g\�Âõ(üY@gR¸…ë1]@gìQ¸…ë^@)ÚmeanÚfloat32)r   r   ÚflattenÚastype)Úis_trainÚsampleÚimgÚlabels       ú_G:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\paddle/dataset/flowers.pyÚdefault_mapperr   :   sK   € ð �J€CˆÜ
˜3Ó
€CÜ
ØˆS�#�xÒ&>ô€Cð �;‰;‹=×Ñ 	Ó*¨EÐ1Ð1ó    TFé   c           	      óv   ‡ ‡‡‡— ˆ ˆˆˆfd„}|r t        ||t        dt        «       «      |«      S t        ||«      S )a�  
    1. read images from tar file and
        merge images into batch files in 102flowers.tgz_batch/
    2. get a reader to read sample from batch file

    :param data_file: downloaded data file
    :type data_file: string
    :param label_file: downloaded label file
    :type label_file: string
    :param setid_file: downloaded setid file containing information
                        about how to split dataset
    :type setid_file: string
    :param dataset_name: data set name (tstid|trnid|valid)
    :type dataset_name: string
    :param mapper: a function to map image bytes data to type
                    needed by model input layer
    :type mapper: callable
    :param buffered_size: the size of buffer used to process images
    :type buffered_size: int
    :param cycle: whether to cycle through the dataset
    :type cycle: bool
    :return: data reader
    :rtype: callable
    c               3   ó¬  •K  — t        d«      } | j                  ‰«      d   d   }| j                  ‰«      ‰   d   }i }|D ]  }d|z  }||dz
     ||<   Œ t        j                  ‰«      }|j	                  «       }d}|D ]Q  }	|	j
                  |v sŒ|j                  |	«      j                  «       }
||	j
                     }|
t        |«      dz
  f–— ŒS y ­w)Nzscipy.ioÚlabelsr   zjpg/image_%05d.jpgr
   )	r	   ÚloadmatÚtarfileÚopenÚ
getmembersÚnameÚextractfileÚreadÚint)Úscior#   ÚindexesÚ	img2labelÚir   ÚtfÚmemsÚfile_idÚmemÚimager   Ú	data_fileÚdataset_nameÚ
label_fileÚ
setid_files               €€€€r   Úreaderzreader_creator.<locals>.readerm   sÙ   øè ø€ Ü˜*Ó%ˆà—‘˜jÓ)¨(Ñ3°AÑ6ˆØ—,‘,˜zÓ*¨<Ñ8¸Ñ;ˆàˆ	ÛˆAØ&¨Ñ*ˆCØ# A¨¡E™]ˆI�cŠNð ô �\‰\˜)Ó$ˆØ�}‰}‹ˆØˆÛˆCØ�x‰x˜9Ò$ØŸ™ sÓ+×0Ñ0Ó2�Ø! #§(¡(Ñ+�ØœS ›Z¨!™^Ð+Ó+ñ	 ùs   ƒBCÂACé   )r   Úminr   r   )	r5   r7   r8   r6   ÚmapperÚbuffered_sizeÚuse_xmapÚcycler9   s	   ````     r   Úreader_creatorr@   J   s5   û€ ÷F,ñ( Ü˜F F¬C°´9³;Ó,?ÀÓOÐOä˜6 6Ó*Ð*r   z2.0.0zpaddle.vision.datasets.Flowersz>Please use new dataset API which supports paddle.io.DataLoader)ÚsinceÚ	update_toÚlevelÚreasonc           
      ó¢   — t        t        t        dt        «      t        t        dt
        «      t        t        dt        «      t        | |||¬«      S )a8  
    Create flowers training set reader.
    It returns a reader, each sample in the reader is
    image pixels in [0, 1] and label in [1, 102]
    translated from original color image by steps:
    1. resize to 256*256
    2. random crop to 224*224
    3. flatten
    :param mapper:  a function to map sample.
    :type mapper: callable
    :param buffered_size: the size of buffer used to process images
    :type buffered_size: int
    :param cycle: whether to cycle through the dataset
    :type cycle: bool
    :return: train data reader
    :rtype: callable
    Úflowers©r?   )	r@   r   ÚDATA_URLÚDATA_MD5Ú	LABEL_URLÚ	LABEL_MD5Ú	SETID_URLÚ	SETID_MD5Ú
TRAIN_FLAG©r<   r=   r>   r?   s       r   ÚtrainrP   ‡   sD   € ô0 Ü”˜9¤hÓ/Ü”˜I¤yÓ1Ü”˜I¤yÓ1ÜØØØØô	ð 	r   c           
      ó¢   — t        t        t        dt        «      t        t        dt
        «      t        t        dt        «      t        | |||¬«      S )a3  
    Create flowers test set reader.
    It returns a reader, each sample in the reader is
    image pixels in [0, 1] and label in [1, 102]
    translated from original color image by steps:
    1. resize to 256*256
    2. random crop to 224*224
    3. flatten
    :param mapper:  a function to map sample.
    :type mapper: callable
    :param buffered_size: the size of buffer used to process images
    :type buffered_size: int
    :param cycle: whether to cycle through the dataset
    :type cycle: bool
    :return: test data reader
    :rtype: callable
    rF   rG   )	r@   r   rH   rI   rJ   rK   rL   rM   Ú	TEST_FLAGrO   s       r   ÚtestrS   «   sD   € ô0 Ü”˜9¤hÓ/Ü”˜I¤yÓ1Ü”˜I¤yÓ1ÜØØØØô	ð 	r   c           	      óž   — t        t        t        dt        «      t        t        dt
        «      t        t        dt        «      t        | ||«      S )aì  
    Create flowers validation set reader.
    It returns a reader, each sample in the reader is
    image pixels in [0, 1] and label in [1, 102]
    translated from original color image by steps:
    1. resize to 256*256
    2. random crop to 224*224
    3. flatten
    :param mapper:  a function to map sample.
    :type mapper: callable
    :param buffered_size: the size of buffer used to process images
    :type buffered_size: int
    :return: test data reader
    :rtype: callable
    rF   )	r@   r   rH   rI   rJ   rK   rL   rM   Ú
VALID_FLAG)r<   r=   r>   s      r   r   r   Ï   sA   € ô, Ü”˜9¤hÓ/Ü”˜I¤yÓ1Ü”˜I¤yÓ1ÜØØØóð r   c                  ó‚   — t        t        dt        «       t        t        dt        «       t        t
        dt        «       y )NrF   )r   rH   rI   rJ   rK   rL   rM   © r   r   ÚfetchrX   ð   s&   € ÜŒX�y¤(Ô+ÜŒY˜	¤9Ô-ÜŒY˜	¤9Õ-r   )r    TF)#Ú__doc__Ú	functoolsr%   Úmultiprocessingr   Úpaddle.dataset.imager   r   Úpaddle.readerr   r   Úpaddle.utilsr   r	   Úcommonr   Ú__all__rH   rJ   rL   rI   rK   rM   rN   rR   rU   r   ÚpartialÚtrain_mapperÚtest_mapperr@   rP   rS   r   rX   rW   r   r   Ú<module>rd      s(  ðñó$ Û Ý %ç Cß 3ß /å à
€àE€ØG€	ØA€	Ø-€Ø.€	Ø.€	ð €
Ø€	Ø€
ò	2ð !ˆy× Ñ  °Ó6€Øˆi×Ñ °Ó6€ð ØØ
ó:+ñz Ø
Ø.Ø
ØKô	ð ¨T¸DÈò óðñ< Ø
Ø.Ø
ØKô	ð ¨4¸$Àeò óðñ< Ø
Ø.Ø
ØKô	ð ¨D¸4ò óðó6.r   