o
    Nia                     @   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Zddlm  m	Z
 ddlmZ dZdZg dZd	Zd
ZG dd deZG dd dejjZdS )+Healthy and unhealthy plant leaves dataset.    )absolute_import)division)print_functionNz
@misc{,
  author={Siddharth Singh Chouhan, Ajay Kaul, Uday Pratap Singh, Sanjeev
Jain},
  title={A Database of Leaf Images: Practice towards Plant Conservation with
Plant Pathology},
  howpublished={Mendeley Data},
  year={2019}
}
at  
This dataset consists of 4502 images of healthy and unhealthy plant leaves
divided into 22 categories by species and state of health. The images are in
high resolution JPG format.

There are no files with label prefix 0000, therefore label encoding is shifted
by one (e.g. file with label prefix 0001 gets encoded label 0).

Note: Each image is a separate download. Some might rarely fail, therefore make
sure to restart if that happens. An exception will be raised in case one of the
downloads repeatedly fails.

Dataset URL: https://data.mendeley.com/datasets/hb74ynkjcn/1
License: http://creativecommons.org/licenses/by/4.0
))0001zMango (P0) healthy)0002zArjun (P1) healthy)0003zAlstonia Scholaris (P2) healthy)0004zGauva (P3) healthy)0005zJamun (P5) healthy)0006zJatropha (P6) healthy)0007zPongamia Pinnata (P7) healthy)0008zBasil (P8) healthy)0009zPomegranate (P9) healthy)0010zLemon (P10) healthy)0011zChinar (P11) healthy)0012zMango (P0) diseased)0013zArjun (P1) diseased)0014z Alstonia Scholaris (P2) diseased)0015zGauva (P3) diseased)0016zBael (P4) diseased)0017zJamun (P5) diseased)0018zJatropha (P6) diseased)0019zPongamia Pinnata (P7) diseased)0020zPomegranate (P9) diseased)0021zLemon (P10) diseased)0022zChinar (P11) diseasedz*image_classification/plant_leaves_urls.txt
   c                   @   s   e Zd ZdS )DownloadRetryLimitReachedErrorN)__name__
__module____qualname__ r!   r!   i/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/image_classification/plant_leaves.pyr   U   s    r   c                   @   s4   e Zd ZdZejdZdd Zdd Z	dd Z
d	S )
PlantLeavesr   z0.1.0c              
   C   sN   t tt d }tjj| ttjtj	 tj
 tjj|ddddtdS )N   )namesimagezimage/filenamelabel)r'   r(   z/https://data.mendeley.com/datasets/hb74ynkjcn/1)builderdescriptionfeaturessupervised_keyshomepagecitation)listzip_LABEL_MAPPINGtfdscoreDatasetInfo_DESCRIPTIONr+   FeaturesDictImageText
ClassLabel	_CITATION)selflabelsr!   r!   r"   _info^   s   zPlantLeaves._infoc              	   C   s   t jjtjtC}dd | D }d}i }	 z|	|}W n tj	j
y8   |d7 }|tkr6tdY nw qtjjtjjd|idgW  d	   S 1 sQw   Y  d	S )
zReturns SplitGenerators.c                 S   s"   i | ]}t j| | qS r!   )ospathbasenamestrip).0lr!   r!   r"   
<dictcomp>r   s    z1PlantLeaves._split_generators.<locals>.<dictcomp>r   Tr$   z7Retry limit reached. Try downloading the dataset again.image_files)name
gen_kwargsN)tfiogfileGFiler2   r3   get_tfds_path_URLS_FNAME	readlinesdownloadDownloadError_MAX_DOWNLOAD_RETRYr   SplitGeneratorSplitTRAIN)r;   
dl_managerfname_to_url_mapretry_countrE   r!   r!   r"   _split_generatorsm   s2   

$zPlantLeaves._split_generatorsc           	      c   sp    dd t D }td}| D ]$\}}||}|r5|d|v r5||d }|||d}||fV  qdS )zYields examples.c                 S   s   i | ]\}}||qS r!   r!   )rB   patternr(   r!   r!   r"   rD      s    z2PlantLeaves._generate_examples.<locals>.<dictcomp>z^(\d\d\d\d)_.*\.JPG$r$   r&   N)r1   recompileitemsmatchgroup)	r;   rE   	label_mapregexporiginal_fnamefpathr^   r(   recordr!   r!   r"   _generate_examples   s   


zPlantLeaves._generate_examplesN)r   r   r    __doc__r2   r3   VersionVERSIONr=   rY   re   r!   r!   r!   r"   r#   Y   s    r#   )rf   
__future__r   r   r   r>   r[   tensorflow.compat.v2compatv2rH   tensorflow_datasets.public_api
public_apir2   r:   r5   r1   rM   rQ   	Exceptionr   r3   GeneratorBasedBuilderr#   r!   r!   r!   r"   <module>   s   