o
    e                     @   sf   d dl Z ddlmZ h dZh dZdhZdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )    N   )load_labelmap>   .bmp.jpg.png.jpeg>   .txt.xml.jsonz.labelsc                 C   s|   t j| std|  t| }dd |D }t| dd |D }dd |D }t| |}t|| t|| | |dS )Nzfolder does not exist. c                 S      g | ]
}|d  t v r|qS 	extension)IMAGE_EXTENSIONS.0f r   I/var/www/myenv/lib/python3.10/site-packages/roboflow/util/folderparser.py
<listcomp>       zparsefolder.<locals>.<listcomp>c                 S   r   r   )ANNOTATION_EXTENSIONSr   r   r   r   r      r   c                 S   r   r   )LABELMAPS_EXTENSIONSr   r   r   r   r      r   )locationimages)	ospathexists	Exception_list_files_decide_split_load_labelmaps_map_labelmaps_to_annotations_map_annotations_to_images)folderfilesr   annotations	labelmapsr   r   r   parsefolder
   s   


r'   c                 C   sN   g }t | D ]\}}}|D ]}t j||}|t|| d  qq|S )Nr   )r   walkr   joinappend_describe_filesplit)r#   filedescriptorsrootdirsr$   file	file_pathr   r   r   r      s   r   c                 C   sX   |  dd }tj| }tj| \}}tj|d }| ||| | | dS )N/r   )r0   dirnamenamer   keyfullkey)r,   r   r   r4   splitextlower)r   r5   r4   r7   r   r6   r   r   r   r+   $   s   r+   c                 C   s   dd | D }d}|D ]}| |d }|r||d< |d7 }q|dkr%d S dd | D }|D ]}| |d }|r=||d< q.d S )	Nc                 S      i | ]}|d  |qS )r7   r   r   ir   r   r   
<dictcomp>4       z._map_annotations_to_images.<locals>.<dictcomp>r   r7   annotationfiler   c                 S   r:   )r6   r   r;   r   r   r   r=   =   r>   r6   get)r   r%   imgmapcountmappedannimager   r   r   r"   3   s"   r"   c                 C   sl   |sd S dd |D }t |t |k r td tdd |D  | D ]}||d }|r3|d |d< q"d S )Nc                 S   r:   )r4   r   r   lmr   r   r   r=   G   r>   z1_map_labelmaps_to_annotations.<locals>.<dictcomp>z<warning: unexpectedly found multiple labelmaps per directoryc                 S   s   g | ]}|d  qS )r0   r   rF   r   r   r   r   J   s    z1_map_labelmaps_to_annotations.<locals>.<listcomp>r4   labelmap)lenprintrA   )r%   r&   labelmapmaprD   rH   r   r   r   r!   D   s   r!   c              	   C   sH   |D ]}zt |  d|d  |d< W q ty   Y qw dd |D S )Nr2   r0   rH   c                 S   s   g | ]	}| d r|qS )rH   r@   rF   r   r   r   r   X   s    z#_load_labelmaps.<locals>.<listcomp>)r   r   )r#   r&   rH   r   r   r   r    Q   s   r    c                 C   sT   | D ]%}|d }d|v rd|d< qd|v rd|d< qd|v r#d|d< qd|d< qd S )Nr7   validr,   traintestr   )r   r<   r7   r   r   r   r   [   s   



r   )r   image_utilsr   r   r   r   r'   r   r+   r"   r!   r    r   r   r   r   r   <module>   s    	
