o
    Ni(                     @   s   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  m	Z
 ddlmZ dZdZdZd	Zd
dgZG dd dejjZG dd dejjZdS )Cifar-10.1 dataset.    )absolute_import)division)print_functionNae  @article{recht2018cifar10.1,
  author = {Benjamin Recht and Rebecca Roelofs and Ludwig Schmidt and Vaishaal Shankar},
  title = {Do CIFAR-10 Classifiers Generalize to CIFAR-10?},
  year = {2018},
  note = {\url{https://arxiv.org/abs/1806.00451}},
}

@article{torralba2008tinyimages, 
  author = {Antonio Torralba and Rob Fergus and William T. Freeman}, 
  journal = {IEEE Transactions on Pattern Analysis and Machine Intelligence}, 
  title = {80 Million Tiny Images: A Large Data Set for Nonparametric Object and Scene Recognition}, 
  year = {2008}, 
  volume = {30}, 
  number = {11}, 
  pages = {1958-1970}
}
a#  The CIFAR-10.1 dataset is a new test set for CIFAR-10. CIFAR-10.1 contains roughly 2,000 new test images 
that were sampled after multiple years of research on the original CIFAR-10 dataset. The data collection 
for CIFAR-10.1 was designed to minimize distribution shift relative to the original dataset. We describe 
the creation of CIFAR-10.1 in the paper "Do CIFAR-10 Classifiers Generalize to CIFAR-10?". 
The images in CIFAR-10.1 are a subset of the TinyImages dataset. 
There are currently two versions of the CIFAR-10.1 dataset: v4 and v6.
z^https://github.com/modestyachts/CIFAR-10.1/blob/master/datasets/cifar10.1_{}_data.npy?raw=truez`https://github.com/modestyachts/CIFAR-10.1/blob/master/datasets/cifar10.1_{}_labels.npy?raw=truev4v6c                       s*   e Zd ZdZejjd fdd	Z  ZS )Cifar10_1ConfigzBuilderConfig for Cifar-10.1.Nc                    s@   |t vr
tdt  |d| tt| jdi | || _dS )zConstructs a Cifar10_1Config.

    Args:
      data: `str`, one of `_DATA_OPTIONS`.
      **kwargs: keyword arguments forwarded to super.
    zdata must be one of %snameN )_DATA_OPTIONS
ValueError
setdefaultsuperr   __init__data)selfr   kwargs	__class__r
   f/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/image_classification/cifar10_1.pyr   B   s
   
zCifar10_1Config.__init__)N)	__name__
__module____qualname____doc__tfdscoredisallow_positional_argsr   __classcell__r
   r
   r   r   r   ?   s    r   c                   @   sT   e Zd ZdZedejdddedejdddgZdd	 Z	d
d Z
dd ZdS )	Cifar10_1r   a  It is the first version of our dataset on which we tested any classifier. As mentioned above, this makes the v4 dataset independent of the classifiers we evaluate. The numbers reported in the main sections of our paper use this version of the dataset. It was built from the top 25 TinyImages keywords for each class, which led to a slight class imbalance. The largest difference is that ships make up only 8% of the test set instead of 10%. v4 contains 2,021 images.z1.1.0r   )descriptionversionr   zIt is derived from a slightly improved keyword allocation that is exactly class balanced. This version of the dataset corresponds to the results in Appendix D of our paper. v6 contains 2,000 images.r   c              	   C   s:   t jj| tt jt jjddt jjdddddtdS )N)    r!      )shape
   )num_classesimagelabelz*https://github.com/modestyachts/CIFAR-10.1)builderr   featuressupervised_keyshomepagecitation)	r   r   DatasetInfo_DESCRIPTIONr*   FeaturesDictImage
ClassLabel	_CITATION)r   r
   r
   r   _infoj   s   zCifar10_1._infoc                 C   sJ   t | jj}t| jj}|||g\}}tjj	tj
j||ddgS )zReturns SplitGenerators.)
image_path
label_path)r	   
gen_kwargs)_DL_URL_IMAGESformatbuilder_configr   _DL_URL_LABELSr	   downloadr   r   SplitGeneratorSplitTEST)r   
dl_manager	image_url	label_urlr5   r6   r
   r
   r   _split_generatorsw   s   
zCifar10_1._split_generatorsc           
      c   s    t jj|d}t|}W d    n1 sw   Y  t jj|d}t|}W d    n1 s6w   Y  tt||D ]\}\}}||d}	||	fV  qBd S )Nrbr&   )tfiogfileGFilenpload	enumeratezip)
r   r5   r6   fimageslabelsir'   r(   recordr
   r
   r   _generate_examples   s   zCifar10_1._generate_examplesN)r   r   r   r   r   r   r   VersionBUILDER_CONFIGSr4   rC   rR   r
   r
   r
   r   r   Q   s     

r   )r   
__future__r   r   r   numpyrI   tensorflow.compat.v2compatv2rE   tensorflow_datasets.public_api
public_apir   r3   r/   r8   r;   r   r   BuilderConfigr   GeneratorBasedBuilderr   r
   r
   r
   r   <module>   s   	