o
    * i                     @   s   d Z ddlZddlZddlZddlZddlmZ g ZdZ	e	d Z
dZe	d ZdZdd
dZeddddddd Zeddddddd ZeddddddddZeddddddddZeddddddd ZdS )a,  
CIFAR dataset.

This module will download dataset from https://dataset.bj.bcebos.com/cifar/cifar-10-python.tar.gz and https://dataset.bj.bcebos.com/cifar/cifar-100-python.tar.gz, parse train/test set into
paddle reader creators.

The CIFAR-10 dataset consists of 60000 32x32 color images in 10 classes,
with 6000 images per class. There are 50000 training images and 10000 test
images.

The CIFAR-100 dataset is just like the CIFAR-10, except it has 100 classes
containing 600 images each. There are 500 training images and 100 testing
images per class.

    N)
deprecatedz$https://dataset.bj.bcebos.com/cifar/zcifar-10-python.tar.gzZ c58f30108f718f92721af3b95e74349azcifar-100-python.tar.gzZ eb9058c3a382ffc7106e4002c42a8d85Fc                    s   dd  fdd}|S )Nc                 s   s\    | d }|  d|  dd }|d usJ t||D ]\}}|d tjt|fV  qd S )Ns   datas   labelss   fine_labelsg     o@)getzipZastypenumpyZfloat32int)batchdatalabelssamplelabel r   `/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/paddle/dataset/cifar.py
read_batch0   s   z"reader_creator.<locals>.read_batchc                  3   sz    	 t jdd'} fdd| D }|D ]}tj| |dd}|E d H  qW d    n1 s3w   Y   s<d S q)NTr)modec                 3   s     | ]} |j v r|j V  qd S )N)name).0Z	each_item)sub_namer   r   	<genexpr>:   s    
z1reader_creator.<locals>.reader.<locals>.<genexpr>bytes)encoding)tarfileopenpickleloadextractfile)fnamesr   r   cyclefilenamer   r   r   r   reader7   s   
zreader_creator.<locals>.readerr   )r    r   r   r!   r   r   r   reader_creator/   s   r"   z2.0.0zpaddle.vision.datasets.Cifar100   z>Please use new dataset API which supports paddle.io.DataLoader)ZsinceZ	update_tolevelreasonc                   C      t tjjtdtdS )z
    CIFAR-100 training set creator.

    It returns a reader creator, each sample in the reader is image pixels in
    [0, 1] and label in [0, 99].

    :return: Training reader creator
    :rtype: callable
    cifartrainr"   paddledatasetcommondownloadCIFAR100_URLCIFAR100_MD5r   r   r   r   train100J      r0   c                   C   r&   )z
    CIFAR-100 test set creator.

    It returns a reader creator, each sample in the reader is image pixels in
    [0, 1] and label in [0, 99].

    :return: Test reader creator.
    :rtype: callable
    r'   testr)   r   r   r   r   test100`   r1   r3   zpaddle.vision.datasets.Cifar10c                 C      t tjjtdtd| dS )a  
    CIFAR-10 training set creator.

    It returns a reader creator, each sample in the reader is image pixels in
    [0, 1] and label in [0, 9].

    :param cycle: whether to cycle through the dataset
    :type cycle: bool
    :return: Training reader creator
    :rtype: callable
    r'   Z
data_batchr   r"   r*   r+   r,   r-   CIFAR10_URLCIFAR10_MD5r5   r   r   r   train10v   
   r9   c                 C   r4   )a  
    CIFAR-10 test set creator.

    It returns a reader creator, each sample in the reader is image pixels in
    [0, 1] and label in [0, 9].

    :param cycle: whether to cycle through the dataset
    :type cycle: bool
    :return: Test reader creator.
    :rtype: callable
    r'   Z
test_batchr5   r6   r5   r   r   r   test10   r:   r;   c                   C   s(   t jjtdt t jjtdt d S )Nr'   )r*   r+   r,   r-   r7   r8   r.   r/   r   r   r   r   fetch   s   r<   )F)__doc__r   r   r   Zpaddle.dataset.commonr*   Zpaddle.utilsr   __all__Z
URL_PREFIXr7   r8   r.   r/   r"   r0   r3   r9   r;   r<   r   r   r   r   <module>   s`   


