
    ΑiY                     l   S r SSKrSSKrSSKJr  SSKJrJr  SSKJ	r	J
r
  SSKJrJr  SSKJr  / rS	rS
rSrSrSrSrSrSrSrS r\R6                  " \S5      r\R6                  " \S5      r   SS jr\" SSSSS9\SSS4S j5       r\" SSSSS9\SSS4S j5       r \" SSSSS9\SS4S j5       r!S r"g) 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                     Uu  p#[        U5      n[        USSU / SQS9nUR                  5       R                  S5      U4$ )z:
map image bytes data to type needed by model input layer
      )g\(Y@gR1]@gQ^@)meanfloat32)r   r   flattenastype)is_trainsampleimglabels       V/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/dataset/flowers.pydefault_mapperr   :   sI     JC
3
C
S#x&>C ;;=	*E11    TF   c           	      ~   ^ ^^^ U UUU4S jnU(       a  [        XH[        S[        5       5      U5      $ [        XH5      $ )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     >#    [        S5      n U R                  T5      S   S   nU R                  T5      T   S   n0 nU H  nSUS S3nXS-
     X5'   M     [        R                  " T5      nUR	                  5       nSnU HT  n	U	R
                  U;   d  M  UR                  U	5      R                  5       n
X9R
                     nU
[        U5      S-
  4v   MV     g 7f)Nzscipy.iolabelsr   z
jpg/image_05z.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   readerreader_creator.<locals>.readerm   s     *%j)(3A6,,z*<8;	AqfD)C#E]IN  \\)$}}Cxx9$s+002!((+SZ!^++	 s   BCAC   )r   minr   r   )	r6   r8   r9   r7   mapperbuffered_sizeuse_xmapcycler:   s	   ````     r   reader_creatorrB   J   s6    F, ,( FC9;,?OO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                     [        [        [        S[        5      [        [        S[
        5      [        [        S[        5      [        U UUUS9$ )a  
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rA   )	rB   r   DATA_URLDATA_MD5	LABEL_URL	LABEL_MD5	SETID_URL	SETID_MD5
TRAIN_FLAGr>   r?   r@   rA   s       r   trainrR      sD    0 9h/Iy1Iy1	 	r   c                     [        [        [        S[        5      [        [        S[
        5      [        [        S[        5      [        U UUUS9$ )a  
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
rH   rI   )	rB   r   rJ   rK   rL   rM   rN   rO   	TEST_FLAGrQ   s       r   testrU      sD    0 9h/Iy1Iy1	 	r   c           	          [        [        [        S[        5      [        [        S[
        5      [        [        S[        5      [        U UU5      $ )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
rH   )	rB   r   rJ   rK   rL   rM   rN   rO   
VALID_FLAG)r>   r?   r@   s      r   r   r      sA    , 9h/Iy1Iy1 r   c                      [        [        S[        5        [        [        S[        5        [        [
        S[        5        g )NrH   )r   rJ   rK   rL   rM   rN   rO    r   r   fetchrZ      s&    Xy(+Y	9-Y	9-r   )r    TF)#__doc__	functoolsr&   multiprocessingr   paddle.dataset.imager   r   paddle.readerr   r   paddle.utilsr   r	   commonr   __all__rJ   rL   rN   rK   rM   rO   rP   rT   rW   r   partialtrain_mappertest_mapperrB   rR   rU   r   rZ   rY   r   r   <module>rf      s$  $   % C 3 / 
EG	A	-.	.	 
	
	2   66 
:+z 
.
K	 TD < 
.
K	 4$e < 
.
K	 D4 6.r   