
    x-jY                        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j        ed          Z ej        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"dS ) 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          }|                                                    d          |fS )zB
    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.11/site-packages/paddle/dataset/flowers.pydefault_mapperr   :   sc     JC
3

C
S#x&>&>&>  C ;;==	**E11    TF   c           	            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          } |                               d         d         }|                                        d         }i }|D ]}d|dd}||dz
           ||<   t          j                  }|                                }d}|D ]U}	|	j        |v rJ|                    |	                                          }
||	j                 }|
t          |          dz
  fV  Vd S )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   readerzreader_creator.<locals>.readerm   s     *%%j))(3A6,,z**<8;	 	+ 	+A)q))))C#AE]IcNN\)$$}} 	, 	,Cx9$$s++0022!#(+SZZ!^++++		, 	,r      )r   minr   r   )	r6   r8   r9   r7   mapperbuffered_sizeuse_xmapcycler:   s	   ````     r   reader_creatorrA   J   sk    F, , , , , , , ,(  +FFC9;;,?,?OOO66***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@   )	rA   r   DATA_URLDATA_MD5	LABEL_URL	LABEL_MD5	SETID_URL	SETID_MD5
TRAIN_FLAGr=   r>   r?   r@   s       r   trainrQ      sW    0 9h//Iy11Iy1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
    rG   rH   )	rA   r   rI   rJ   rK   rL   rM   rN   	TEST_FLAGrP   s       r   testrT      sW    0 9h//Iy11Iy1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
    rG   )	rA   r   rI   rJ   rK   rL   rM   rN   
VALID_FLAG)r=   r>   r?   s      r   r   r      sO    , 9h//Iy11Iy11  r   c                      t          t          dt                     t          t          dt                     t          t
          dt                     d S )NrG   )r   rI   rJ   rK   rL   rM   rN    r   r   fetchrY      s>    Xy(+++Y	9---Y	9-----r   )r    TF)#__doc__	functoolsr&   multiprocessingr   paddle.dataset.imager   r   paddle.readerr   r   paddle.utilsr   r	   commonr   __all__rI   rK   rM   rJ   rL   rN   rO   rS   rV   r   partialtrain_mappertest_mapperrA   rQ   rT   r   rY   rX   r   r   <module>re      s   $      % % % % % % C C C C C C C C 3 3 3 3 3 3 3 3 / / / / / / / /      
EG	A	-.	.	 
	
	2 	2 	2 !y 66i66 
:+ :+ :+ :+z 
.
K	   TD    < 
.
K	   4$e    < 
.
K	   D4    6. . . . .r   