o
    Ni!                     @   s   d Z ddlm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	d
 d
ejjZG dd dejjZedZdd ZdS )#Lost and Found Road Hazard Dataset.    )absolute_import)division)print_function)pathNa^  
@inproceedings{pinggera2016lost,
  title={Lost and found: detecting small road hazards for self-driving vehicles},
  author={Pinggera, Peter and Ramos, Sebastian and Gehrig, Stefan and Franke, Uwe and Rother, Carsten and Mester, Rudolf},
  booktitle={2016 IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS)},
  year={2016}
}
a9  
The LostAndFound Dataset addresses the problem of detecting unexpected small obstacles on
the road often caused by lost cargo. The dataset comprises 112 stereo video sequences
with 2104 annotated frames (picking roughly every tenth frame from the recorded data).

The dataset is designed analogous to the 'Cityscapes' dataset. The datset provides:
- stereo image pairs in either 8 or 16 bit color resolution
- precomputed disparity maps
- coarse semantic labels for objects and street

Descriptions of the labels are given here: http://www.6d-vision.com/laf_table.pdf
c                       s,   e Zd ZdZ					d fdd	Z  ZS )LostAndFoundConfigam  BuilderConfig for 'Lost and Found'.

    Args:
      right_images (bool): Enables right images for stereo image tasks.
      segmentation_labels (bool): Enables image segmentation labels.
      instance_ids (bool): Enables instance-id labels.
      disparity_maps (bool): Enables disparity maps.
      use_16bit (bool): Loads 16 bit (rgb) images instead of 8bit.
  Fc                    s   t t| jd
i | dg| _|r| jd |r| jd |r'| jd |r/| jd d|r5dnd| _d	|r?dnd| _d S )N
image_leftimage_rightsegmentation_labelinstance_iddisparity_mapzleftImg{}bit168zrightImg{}bit )superr   __init__featuresappendformatleft_image_stringright_image_string)selfright_imagessegmentation_labelsinstance_idsdisparity_maps	use_16bitkwargs	__class__r   \/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/image/lost_and_found.pyr   @   s   zLostAndFoundConfig.__init__)FFFFF)__name__
__module____qualname____doc__r   __classcell__r   r   r   r    r   5   s    r   c                   @   s   e Zd ZdZejdZedddddddddedd	ddddddded
ddddddddedddddddddgZ	dd Z
dd Zdd ZdS )LostAndFoundr   z1.0.0semantic_segmentationz-Lost and Found semantic segmentation dataset.FT)namedescriptionversionr   r   r   r   r   stereo_disparityz0Lost and Found stereo images and disparity maps.fullzFull Lost and Found dataset.
full_16bitc                    s   t jjdddt jjdddt jjdddt jjdddt jjdddd  fdd| jjD }t j |d< t j|}t jj| t|d	t	d
S )N)         png)shapeencoding_format)r.   r/      r   r	   r
   r   r   c                    s   i | ]}| | qS r   r   .0featpossible_featuresr   r    
<dictcomp>   s    
z&LostAndFound._info.<locals>.<dictcomp>image_idz,http://www.6d-vision.com/lostandfounddataset)builderr)   r   homepagecitation)
tfdsr   Imagebuilder_configTextFeaturesDictcoreDatasetInfo_DESCRIPTION	_CITATION)r   r   r   r9   r    _info   s$   
zLostAndFound._infoc                    s   d | j j| j jdddd fdd| j jD }|||tjjtj	j
fdd| j jD dtjjtj	jfd	d| j jD dgS )
zReturns SplitGenerators.z@http://www.dhbw-stuttgart.de/~sgehrig/lostAndFoundDataset/{}.zipgtCoarse	disparityr5   c                    s   i | ]
}|  | qS r   )r   r6   )base_urlzip_file_namesr   r    r;      s    z2LostAndFound._split_generators.<locals>.<dictcomp>c                    $   i | ]}|t  | | d qS )trainr   joinr6   dl_pathsrM   r   r    r;          )r(   
gen_kwargsc                    rN   )testrP   r6   rR   r   r    r;      rT   )rB   r   r   r   extractdownloadr@   rE   SplitGeneratorSplitTRAINTEST)r   
dl_managerdownload_urlsr   )rL   rS   rM   r    _split_generators   s0   zLostAndFound._split_generatorsc                 +   s    | j j| j jdddd tjj|d D ]3fdd| D d }tjj|D ]}t| fdd|D }|d	< |fV  q.qd
S )zYields examples.gtCoarse_labelIdsgtCoarse_instanceIdsrK   r5   r   c                    s   i | ]\}}|t | qS r   rP   )r7   r8   feat_dir)scene_idr   r    r;      s    z3LostAndFound._generate_examples.<locals>.<dictcomp>c                    s*   i | ]}|t | d  | qS )z	{}_{}.png)r   rQ   r   r6   )file_suffixr<   paths_city_rootr   r    r;      s    r<   N)	rB   r   r   tfiogfilelistdiritems_get_id_from_left_image)r   pathsleft_city_rootleft_imgr   r   )rd   r<   re   rc   r    _generate_examples   s*   
zLostAndFound._generate_examplesN)r!   r"   r#   r$   r@   rE   VersionVERSIONr   BUILDER_CONFIGSrI   r_   ro   r   r   r   r    r&   W   s^    


+*r&   z(.+)_leftImg(?:8|16)bit\.pngc                 C   s   t | dS )zReturns the id of an image file.

  Used to associate an image file
  with its corresponding label.
  Example:
    'bonn_000001_000019_leftImg8bit' -> 'bonn_000001_000019'

  Args:
    left_image: left image file name.

  Returns:
    id of the image.
  r4   )LEFT_IMAGE_FILE_REmatchgroup)
left_imager   r   r    rk      s   rk   )r$   
__future__r   r   r   osr   retensorflow.compat.v2compatv2rf   tensorflow_datasets.public_api
public_apir@   rH   rG   rE   BuilderConfigr   GeneratorBasedBuilderr&   compilers   rk   r   r   r   r    <module>   s   	" 
