o
    MeI                     @   s   d Z ddlmZ ddlZddlZddlZddlm  m	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.

    )print_functionN)cPicklez$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   sr    | t d }| t d| t dd }|d usJ t j||D ]\}}|d tjt|fV  q%d S )NdatalabelsZfine_labelsg     o@)	sixbgetmoveszipZastypenumpyZfloat32int)batchr   r   samplelabel r   DD:\Projects\ConvertPro\env\Lib\site-packages\paddle/dataset/cifar.py
read_batch3   s   z"reader_creator.<locals>.read_batchc                  3   s    	 t jdd*} fdd| D }|D ]}tj| |dd}|D ]}|V  q%qW d    n1 s6w   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   itemcyclefilenamer   r   r   r   reader;   s   	zreader_creator.<locals>.readerr   )r%   r   r$   r&   r   r#   r   reader_creator1   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   train100L      r5   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`   r6   r8   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/   r0   r1   r2   CIFAR10_URLCIFAR10_MD5r:   r   r   r   train10t      
r>   c                 C   r9   )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_batchr:   r;   r:   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/   r0   r1   r2   r<   r=   r3   r4   r   r   r   r   fetch   s   rA   )F)__doc__
__future__r   	itertoolsr   Zpaddle.dataset.commonr/   Zpaddle.utils.deprecatedutils
deprecatedr   r   Z	six.movesr   r   __all__Z
URL_PREFIXr<   r=   r3   r4   r'   r5   r8   r>   r@   rA   r   r   r   r   <module>   sf   


