o
    Ni                     @   sz   d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddl	m
  mZ ddlmZ dZdZG d	d
 d
ejjZdS )z;Street View House Numbers (SVHN) Dataset, cropped version.
    )absolute_import)division)print_functionN)urllibz'http://ufldl.stanford.edu/housenumbers/a,  @article{Netzer2011,
author = {Netzer, Yuval and Wang, Tao and Coates, Adam and Bissacco, Alessandro and Wu, Bo and Ng, Andrew Y},
booktitle = {Advances in Neural Information Processing Systems ({NIPS})},
title = {Reading Digits in Natural Images with Unsupervised Feature Learning},
year = {2011}
}
c                   @   sD   e Zd ZdZejddZejdgZdd Z	dd Z
d	d
 ZdS )SvhnCroppedz:Street View House Numbers (SVHN) Dataset, cropped version.3.0.0z6New split API (https://tensorflow.org/datasets/splits)z3.1.0c                 C   sV   t jjddt jjddd}| jdkrt j |d< t jj| dt j|dt	t
d	S )
N)    r      )shape
   )num_classesimagelabelr   idzThe Street View House Numbers (SVHN) Dataset is an image digit recognition dataset of over 600,000 digit images coming from real world data. Images are cropped to 32x32.)builderdescriptionfeaturessupervised_keyshomepagecitation)tfdsr   Image
ClassLabelversionTextcoreDatasetInfoFeaturesDictURL	_CITATION)selffeatures_dict r#   a/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/image_classification/svhn.py_info4   s   

zSvhnCropped._infoc                 C   s   | tjtdtjtdtjtdd}tjjtjj	t
d|d ddtjjtjjt
d	|d
 ddtjjdt
d|d ddgS )Nztrain_32x32.matztest_32x32.matzextra_32x32.mat)traintestextratrain_r&   )split_prefixfilepath)name
gen_kwargstest_r'   r(   extra_)downloadr   parseurljoinr   r   r   SplitGeneratorSplitTRAINdictTEST)r!   
dl_manageroutput_filesr#   r#   r$   _split_generatorsG   s6   zSvhnCropped._split_generatorsc           	      c   s    t jj|d}tjjjj|}W d   n1 sw   Y  t	
|d dks-J t	|d dks8J ttt	|d d|d D ]$\}\}}|d}||d d	}| jd
krfd|||d< ||fV  qGdS )zGenerate examples as dicts.

    Args:
      split_prefix: `str` prefix that identifies the split.
      filepath: `str` path of the file to process.

    Yields:
      Generator yielding the next samples
    rbNyr   r   Xr#   r   r   z{}{:06d}r   )tfiogfileGFiler   r   lazy_importsscipyloadmatnpmaxmin	enumerateziprollaxisreshaper   format)	r!   r*   r+   fdatair   r   recordr#   r#   r$   _generate_examplesd   s"   


zSvhnCropped._generate_examplesN)__name__
__module____qualname____doc__r   r   VersionVERSIONSUPPORTED_VERSIONSr%   r:   rR   r#   r#   r#   r$   r   +   s    
r   )rV   
__future__r   r   r   numpyrF   	six.movesr   tensorflow.compat.v2compatv2r?   tensorflow_datasets.public_api
public_apir   r   r    r   GeneratorBasedBuilderr   r#   r#   r#   r$   <module>   s   
