
    ڧg                     v    d dl Z d dlmZ d dlmZmZmZmZmZ d dl	Z
ddlmZmZ ddlmZ  G d de          ZdS )	    N)Path)AnyCallableOptionalTupleUnion   )download_and_extract_archiveverify_str_arg)VisionDatasetc                        e Zd ZdZdZdZ	 	 	 	 ddeeef         ded	e	e
         d
e	e
         deddf fdZdefdZdedeeef         fdZdefdZdefdZddZ xZS )Food101a  `The Food-101 Data Set <https://data.vision.ee.ethz.ch/cvl/datasets_extra/food-101/>`_.

    The Food-101 is a challenging data set of 101 food categories with 101,000 images.
    For each class, 250 manually reviewed test images are provided as well as 750 training images.
    On purpose, the training images were not cleaned, and thus still contain some amount of noise.
    This comes mostly in the form of intense colors and sometimes wrong labels. All images were
    rescaled to have a maximum side length of 512 pixels.


    Args:
        root (str or ``pathlib.Path``): Root directory of the dataset.
        split (string, optional): The dataset split, supports ``"train"`` (default) and ``"test"``.
        transform (callable, optional): A function/transform that takes in a PIL image and returns a transformed
            version. E.g, ``transforms.RandomCrop``.
        target_transform (callable, optional): A function/transform that takes in the target and transforms it.
        download (bool, optional): If True, downloads the dataset from the internet and
            puts it in root directory. If dataset is already downloaded, it is not
            downloaded again. Default is False.
    z1http://data.vision.ee.ethz.ch/cvl/food-101.tar.gz 85eeb15f3717b99a5da872d97d918f87trainNFrootsplit	transformtarget_transformdownloadreturnc           
          t                                          |||           t          |dd           _        t	           j                  dz   _         j        dz   _         j        dz   _        |r 	                                  
                                st          d          g  _        g  _        t           j        | dz            5 }t          j        |                                          }d d d            n# 1 swxY w Y   t%          |                                           _        t+          t-           j        t/          t1           j                                                 _        |                                D ]M\  }}	 xj         j        |         gt1          |	          z  z  c_         xj         fd	|	D             z  c_        Nd S )
N)r   r   r   )r   testzfood-101metaimagesz;Dataset not found. You can use download=True to download itz.jsonc                 Z    g | ]'} j         j        | d                     d           (S )z.jpg/)_images_folderjoinpathr   ).0im_rel_pathselfs     X/var/www/html/ai-engine/env/lib/python3.11/site-packages/torchvision/datasets/food101.py
<listcomp>z$Food101.__init__.<locals>.<listcomp>A   sK     " " "S^,#,.B.B.B.H.H.M.MN" " "    )super__init__r   _splitr   r   _base_folder_meta_folderr   	_download_check_existsRuntimeError_labels_image_filesopenjsonloadsreadsortedkeysclassesdictziprangelenclass_to_idxitems)r!   r   r   r   r   r   fmetadataclass_labelim_rel_paths	__class__s   `         r"   r&   zFood101.__init__#   s    	EUVVV$UG5FGG OOj8 -6"/(: 	NN!!## 	^\]]]$#ooo566 	,!z!&&((++H	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, hmmoo.. T\5T\9J9J3K3K!L!LMM)1)9)9 	 	%KLLT.{;<s<?P?PPPLL " " " "bn" " " 	 	s   'DDDc                 *    t          | j                  S N)r9   r.   r!   s    r"   __len__zFood101.__len__E   s    4$%%%r$   idxc                    | j         |         | j        |         }}t          j                            |                              d          }| j        r|                     |          }| j        r|                     |          }||fS )NRGB)r.   r-   PILImager/   convertr   r   )r!   rE   
image_filelabelimages        r"   __getitem__zFood101.__getitem__H   s~     -c2DL4EE
	z**22599> 	*NN5))E  	1))%00Ee|r$   c                     d| j          S )Nzsplit=)r'   rC   s    r"   
extra_reprzFood101.extra_reprT   s    %%%%r$   c                 L    t          d | j        | j        fD                       S )Nc              3   f   K   | ],}|                                 o|                                V  -d S rB   )existsis_dir)r   folders     r"   	<genexpr>z(Food101._check_exists.<locals>.<genexpr>X   s7      nn66==??6v}}nnnnnnr$   )allr)   r   rC   s    r"   r+   zFood101._check_existsW   s+    nndFWY]YlEmnnnnnnr$   c                 t    |                                  rd S t          | j        | j        | j                   d S )N)download_rootmd5)r+   r
   _URLr   _MD5rC   s    r"   r*   zFood101._downloadZ   s<     	F$TYdiTYWWWWWWr$   )r   NNF)r   N)__name__
__module____qualname____doc__r[   r\   r   strr   r   r   boolr&   intrD   r   r   rN   rP   r+   r*   __classcell__)r@   s   @r"   r   r      sP        ( ?D-D
 (,/3   CI    H%	 
 #8,    
           D& & & & &
s 
uS#X 
 
 
 
&C & & & &ot o o o oX X X X X X X Xr$   r   )r0   pathlibr   typingr   r   r   r   r   	PIL.ImagerH   utilsr
   r   visionr   r    r$   r"   <module>rk      s           8 8 8 8 8 8 8 8 8 8 8 8 8 8     ? ? ? ? ? ? ? ? ! ! ! ! ! !RX RX RX RX RXm RX RX RX RX RXr$   