o
    Me,                     @   s   d Z ddlmZ ddlZddlm  m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ed
 ZdZed ZdZ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 ZdS )z
MNIST dataset.

This module will download dataset from http://yann.lecun.com/exdb/mnist/ and
parse training set and test set into paddle reader creators.
    )print_functionN)rangez$https://dataset.bj.bcebos.com/mnist/zt10k-images-idx3-ubyte.gzZ 9fb629c4189551a2d022fa330f9573f3zt10k-labels-idx1-ubyte.gzZ ec29112dd5afa0611ce80d1b7f02629cztrain-images-idx3-ubyte.gzZ f68b3c2dcbeaaa9fbdd348bbdeb94873ztrain-labels-idx1-ubyte.gzZ d53e105ee54ea40749a09fcbcd1e9432c                    s    fdd}|S )Nc               	   3   s   t d} |  }t d}| }d}d}d}t|||\}}}	}
|t|7 }d}d}t|||\}}|t|7 }	 ||krInddt  d }t|||}|t|7 }| 7 }dt |	 |
  d }t|||}t| |	|
 f	d}|t|7 }|d	 }|d
 }|d }t
 D ]}||d d f t|| fV  qqDW d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nrbr   z>IIIIz>IIT>BZfloat32g     o@g       @g      ?)gzipGzipFilereadstructunpack_fromcalcsizestrnumpyZreshapeZastyper   int)Z
image_fileZimg_bufZ
label_fileZlab_bufZ
step_labelZ
offset_imgZmagic_byte_imgZ	magic_imgZ	image_numrowscolsZ
offset_labZmagic_byte_labZ	magic_labZ	label_numZ	fmt_labellabelsZ
fmt_imagesZimages_tempZimagesibuffer_sizeimage_filenamelabel_filename DD:\Projects\ConvertPro\env\Lib\site-packages\paddle/dataset/mnist.pyreader-   s^   
 "zreader_creator.<locals>.readerr   )r   r   r   r   r   r   r   reader_creator+   s   /r   z2.0.0zpaddle.vision.datasets.MNIST   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tjjtdtdS )z
    MNIST training set creator.

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

    :return: Training reader creator
    :rtype: callable
    mnistd   )	r   paddledatasetcommondownloadTRAIN_IMAGE_URLTRAIN_IMAGE_MD5TRAIN_LABEL_URLTRAIN_LABEL_MD5r   r   r   r   train_   s   r*   c                   C   r   )z
    MNIST test set creator.

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

    :return: Test reader creator.
    :rtype: callable
    r    r!   )	r   r"   r#   r$   r%   TEST_IMAGE_URLTEST_IMAGE_MD5TEST_LABEL_URLTEST_LABEL_MD5r   r   r   r   testu   s
   r/   c                   C   sL   t jjtdt t jjtdt t jjtdt	 t jjt
dt d S )Nr    )r"   r#   r$   r%   r&   r'   r(   r)   r+   r,   r-   r.   r   r   r   r   fetch   s   r0   )__doc__
__future__r   Zpaddle.dataset.commonr"   Zpaddle.utils.deprecatedutils
deprecatedr   r   r
   Z	six.movesr   __all__Z
URL_PREFIXr+   r,   r-   r.   r&   r'   r(   r)   r   r*   r/   r0   r   r   r   r   <module>   sP   4

