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Zddlm  m	Z
 ddlmZ dZdZdZd	Zd
ZG dd dejjZdS )z$Dataset class for DeepWeeds dataset.    )absolute_import)division)print_functionNzGhttps://nextcloud.qriscloud.org.au/index.php/s/a3KxPawpqkiorST/downloadzNhttps://raw.githubusercontent.com/AlexOlsen/DeepWeeds/master/labels/labels.csva  The DeepWeeds dataset consists of 17,509 images capturing eight different weed species native to Australia in situ with neighbouring flora.The selected weed species are local to pastoral grasslands across the state of Queensland.The images were collected from weed infestations at the following sites across Queensland: "Black River", "Charters Towers",  "Cluden", "Douglas", "Hervey Range", "Kelso", "McKinlay" and "Paluma".)   r      as   @article{DeepWeeds2019,
  author = {Alex Olsen and
    Dmitry A. Konovalov and
    Bronson Philippa and
    Peter Ridd and
    Jake C. Wood and
    Jamie Johns and
    Wesley Banks and
    Benjamin Girgenti and
    Owen Kenny and
    James Whinney and
    Brendan Calvert and
    Mostafa {Rahimi Azghadi} and
    Ronald D. White},
  title = {{DeepWeeds: A Multiclass Weed Species Image Dataset for Deep Learning}},
  journal = {Scientific Reports},
  year = 2019,
  number = 2058,
  month = 2,
  volume = 9,
  issue = 1,
  day = 14,
  url = "https://doi.org/10.1038/s41598-018-38343-3",
  doi = "10.1038/s41598-018-38343-3"
}
c                   @   sH   e Zd ZdZejddZejjdddgZdd Z	d	d
 Z
dd ZdS )	DeepWeedszDeepWeeds Image Dataset Class.z2.0.0zFixes wrong labels in V1.z1.0.0(c28a63fa9d9fb9ba3cced7052ea243e8884f9bf1)tfds_version_to_preparec              	   C   s:   t jj| tt jt jjtdt jjdddddt	dS )zDefine Dataset Info.)shape	   )num_classesimagelabelz&https://github.com/AlexOlsen/DeepWeeds)builderdescriptionfeaturessupervised_keyshomepagecitation)
tfdscoreDatasetInfo_DESCRIPTIONr   FeaturesDictImage_IMAGE_SHAPE
ClassLabel	_CITATION)self r    g/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/image_classification/deep_weeds.py_infoP   s   zDeepWeeds._infoc                 C   sB   | tjjttjjjdtd}tjj	d|d |d ddgS )zDefine Splits.)urlextract_methodr   trainr   r   )data_dir_path
label_path)name
gen_kwargs)
download_and_extractr   downloadResource_URLExtractMethodZIP_URL_LABELSr   SplitGenerator)r   
dl_managerpathsr    r    r!   _split_generators_   s   zDeepWeeds._split_generatorsc                 c   s    t jj|}tt|}W d   n1 sw   Y  dd |D }dd t| D | j	j
d _dd |D }t jj|D ]}|tj|||| dfV  qDdS )	z&Generate images and labels for splits.Nc                 S   s   i | ]}t |d  |d qS )LabelSpecies)int.0rowr    r    r!   
<dictcomp>{   s    z0DeepWeeds._generate_examples.<locals>.<dictcomp>c                 S   s   g | ]\}}|qS r    r    )r9   _vr    r    r!   
<listcomp>|   s    z0DeepWeeds._generate_examples.<locals>.<listcomp>r   c                 S   s   i | ]	}|d  |d qS )Filenamer6   r    r8   r    r    r!   r;      s    r   )tfiogfileGFilelistcsv
DictReadersorteditemsinfor   nameslistdirospathjoin)r   r&   r'   freaderlabel_id_to_namefilename_to_label	file_namer    r    r!   _generate_examplesr   s   
zDeepWeeds._generate_examplesN)__name__
__module____qualname____doc__r   r   VersionVERSIONSUPPORTED_VERSIONSr"   r4   rT   r    r    r    r!   r   F   s    r   )rX   
__future__r   r   r   rE   rL   tensorflow.compat.v2compatv2r@   tensorflow_datasets.public_api
public_apir   r-   r0   r   r   r   r   GeneratorBasedBuilderr   r    r    r    r!   <module>   s   