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g dZg d	Zd
d eD Zedd eD  g dZdgZg dZdZG dd dejjZdS )zPetFinder Dataset.    )absolute_import)division)print_functionNa  
@ONLINE {kaggle-petfinder-adoption-prediction,
    author = "Kaggle and PetFinder.my",
    title  = "PetFinder.my Adoption Prediction",
    month  = "april",
    year   = "2019",
    url    = "https://www.kaggle.com/c/petfinder-adoption-prediction/data/"
}
z1https://storage.googleapis.com/petfinder_dataset/)test_metadatatest_imagestest_sentimenttrain_metadatatrain_imagestrain_sentiment)testtrainbreed_labelsstate_labelscolor_labelsc                 C      i | ]	}|t | d  qS )z.zip_URL.0name r   g/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/image_classification/pet_finder.py
<dictcomp>/       r   c                 C   r   )z.csvr   )r   labelr   r   r   r   0   r   )TypeAgeBreed1Breed2GenderColor1Color2Color3MaturitySize	FurLength
VaccinatedDewormed
SterilizedHealthQuantityFeeStateVideoAmtPhotoAmt)r   r   PetIDRescurIDzgA large set of images of cats and dogs.Together with the metadata information of sentiment information.c                   @   s4   e Zd ZdZejdZdd Zdd Z	dd Z
d	S )
	PetFinderzPet Finder.z1.0.0c                 C   sR   t jj| dt jt j t j t j dd tD t jjdddddt	d	S )
NzZDataset with images from 5 classes (see config name for information on the specific class)c                 S   s   i | ]}|t jqS r   )tfint64r   r   r   r   r   K   s    z#PetFinder._info.<locals>.<dictcomp>   )num_classesimagezimage/filenamer.   
attributesr   )r7   r   z;https://www.kaggle.com/c/petfinder-adoption-prediction/data)builderdescriptionfeaturessupervised_keyshomepagecitation)
tfdscoreDatasetInfor:   FeaturesDictImageText
_INT_FEATS
ClassLabel	_CITATION)selfr   r   r   _infoB   s   zPetFinder._infoc                 C   sR   | t}tjjtjjd|d |d ddtjjtjjd|d |d ddgS )	zReturns SplitGenerators.z	train.csvr   r	   )csv_name	csv_paths	img_paths)r   
gen_kwargstest.csvr   r   )download_and_extract_DL_URLSr>   r?   SplitGeneratorSplitTRAINTEST)rG   
dl_managerdl_pathsr   r   r   _split_generatorsS   s    
zPetFinder._split_generatorsc                 c   s    t jjj}tjj|std	|tjj
|}||}W d   n1 s+w   Y  |dkr8d|d< tjj|}|D ]2}|dd }	tj||}
|j|d |	k }|
||	|t d	d |d jd d
}||fV  qAdS )zYields examples.

    Args:
      csv_name: file name for the csv file used in the split
      csv_paths: Path to csv files containing the label and attributes
        information.
      img_paths: Path to images.
    z{} not existNrM   AdoptionSpeed-r   r.   recordsr5   )r>   r?   lazy_importspandasr1   iogfileexistsAssertionErrorformatGFileread_csvlistdirsplitospathjoinlocrD   to_dictvalues)rG   rI   rJ   rK   pdcsv_file	dataframeimagesr6   pet_id
image_path	attr_dictrecordr   r   r   _generate_examplesn   s,   
	zPetFinder._generate_examplesN)__name__
__module____qualname____doc__r>   r?   VersionVERSIONrH   rV   rt   r   r   r   r   r0   >   s    r0   )rx   
__future__r   r   r   rf   tensorflow.compat.v2compatv2r1   tensorflow_datasets.public_api
public_apir>   rF   r   _DATA_OPTIONS_LABEL_OPTIONSrO   updaterD   _FLOAT_FEATS
_OBJ_FEATS_DESCRIPTIONr?   GeneratorBasedBuilderr0   r   r   r   r   <module>   s&   
