
    FPhbe                     x   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
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Zd dlZd dlmZ d dlmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- ej\                  dz  dfd	Z/d+d
e0fdZ1d
e2fdZ3d,dZ4	 	 	 	 	 d-de5de5de5de2de2d
e2fdZ6d.dZ7d Z8 e!       d/d       Z9d0de5d
e2fdZ: e"       ej\                  dz  dddfd       Z;d Z<d1dZ=d2de5de2fdZ>d3d Z?d4d!Z@d5d"ZAd6d#ZBd$ ZCd% ZDefd&ZEd7d'eeF   fd(ZGd
eHfd)ZId
e2fd*ZJy)8    N)metadata)Path)Optional)font_manager)ASSETSAUTOINSTALLLINUXLOGGERONLINEROOTUSER_CONFIG_DIRSimpleNamespaceThreadingLocked	TryExcept	clean_urlcolorstr	downloadsemojisis_colab	is_docker
is_jupyter	is_kaggle	is_onlineis_pip_packageurl2filezrequirements.txt c                    |r2t        j                  |      j                  D cg c]	  }d|vs| }}n't        |       j	                         j                         }g }|D ]  }|j                         }|s|j                  d      r(|j                  d      d   j                         }t        j                  d|      }|sc|j                  t        |d   |d   r|d   j                         nd              |S c c}w )	a;  
    Parse a requirements.txt file, ignoring lines that start with '#' and any text after '#'.

    Args:
        file_path (Path): Path to the requirements.txt file.
        package (str, optional): Python package to use instead of requirements.txt file, i.e. package='ultralytics'.

    Returns:
        (List[Dict[str, str]]): List of parsed requirements as dictionaries with `name` and `specifier` keys.

    Example:
        ```python
        from ultralytics.utils.checks import parse_requirements

        parse_requirements(package='ultralytics')
        ```
    z	extra == #r   z ([a-zA-Z0-9-_]+)\s*([<>!=~]+.*)?      r   )name	specifier)r   distributionrequiresr   	read_text
splitlinesstrip
startswithsplitrematchappendr   )	file_pathpackagexr$   requirementsliner+   s          cC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\ultralytics/utils/checks.pyparse_requirementsr3      s    & '44W=FF_F!+]^J^AF_	?,,.99;Lzz|,::c?1%++-DHH@$GE##OqafghaiUSTX^^M]oq$rs   `s
   	C>C>returnc           	          	 t        t        t        t        j                  d|       dd             S # t
        $ r%}t        j                  d|  d|        Y d}~yd}~ww xY w)a  
    Convert a version string to a tuple of integers, ignoring any extra non-numeric string attached to the version. This
    function replaces deprecated 'pkg_resources.parse_version(v)'.

    Args:
        version (str): Version string, i.e. '2.0.1+cpu'

    Returns:
        (tuple): Tuple of integers representing the numeric part of the version and the extra string, i.e. (2, 0, 1)
    z\d+N   u)   WARNING ⚠️ failure for parse_version(z), returning (0, 0, 0): )r   r   r   )tuplemapintr*   findall	Exceptionr
   warning)versiones     r2   parse_versionr?   A   s[    Sbjj9"1=>?? B7)Kcdecfghs   /2 	A AA c                 <    t        |       } t        d | D              S )z
    Check if a string is composed of only ASCII characters.

    Args:
        s (str): String to be checked.

    Returns:
        bool: True if the string is composed only of ASCII characters, False otherwise.
    c              3   8   K   | ]  }t        |      d k    yw)   N)ord).0cs     r2   	<genexpr>zis_ascii.<locals>.<genexpr>a   s     'Qs1v|Qs   )strall)ss    r2   is_asciirJ   S   s      	AA 'Q'''    c           	         t        t        |t        j                        r|j	                         n|      }t        | t               r| g} nGt        | t
        t        f      rt        |       } n%t        d|  dt        |       j                   d      t        |       |kD  rHd}|dk7  rt        d|  d|       t        j                  dt	        |        d	|        t	        |       g} | D cg c]'  }t	        t        j                  ||z        |z  |      ) }}|| k7  rt        j                  d
|  d| d|        |dk(  rt        |      dk(  r|d   |d   g}|S |dk(  rt        |      dk(  r|d   }|S |}|S c c}w )a(  
    Verify image size is a multiple of the given stride in each dimension. If the image size is not a multiple of the
    stride, update it to the nearest multiple of the stride that is greater than or equal to the given floor value.

    Args:
        imgsz (int | cList[int]): Image size.
        stride (int): Stride value.
        min_dim (int): Minimum number of dimensions.
        max_dim (int): Maximum number of dimensions.
        floor (int): Minimum allowed value for image size.

    Returns:
        (List[int]): Updated image size.
    z'imgsz=z' is of invalid type zK. Valid imgsz types are int i.e. 'imgsz=640' or list i.e. 'imgsz=[640,640]'z'train' and 'val' imgsz must be an integer, while 'predict' and 'export' imgsz may be a [h, w] list or an integer, i.e. 'yolo export imgsz=640,480' or 'yolo export imgsz=640'r   zimgsz=z is not a valid image size. u"   WARNING ⚠️ updating to 'imgsz=z'. u   WARNING ⚠️ imgsz=z  must be multiple of max stride z, updating to r    r   )r9   
isinstancetorchTensormaxlistr7   	TypeErrortype__name__len
ValueErrorr
   r<   mathceil)imgszstridemin_dimmax_dimfloormsgr/   szs           r2   check_imgszr`   d   s     FELL!AvNF %	ED%=	)U'%(=d5k>R>R=S Td e f 	f 5zG[a<veW,HNOO;CJ<s3%PQU>C	De#diiF
#f,e
4eB	D 
U{.ug5UV\U]]klnkopq #a<CGqL"Q%ABI HORS|X[\^X_cdXdbeBI kmBI 
Es   +,E9currentrequiredr!   hardverbosec           	         | st        j                  d|  d| d       y| d   j                         s	 | }t        j                  |       } |syd}t        |       }|j                  d	      j                  d	      D ]  }t        j                  d
|      j                         \  }}	t        |	      }	|dk(  r||	k7  rd}B|dk(  r||	k(  rd}O|dv r||	k\  sd}[|dk(  r||	k  sd}h|dk(  r||	kD  sd}u|dk(  s{||	k  rd} |s=d|  | d| d|  d	}
|rt        t        |
            |rt        j                  |
       |S # t        j
                  $ r |rt        t        d|  d            Y yw xY w)a  
    Check current version against the required version or range.

    Args:
        current (str): Current version or package name to get version from.
        required (str): Required version or range (in pip-style format).
        name (str, optional): Name to be used in warning message.
        hard (bool, optional): If True, raise an AssertionError if the requirement is not met.
        verbose (bool, optional): If True, print warning message if requirement is not met.

    Returns:
        (bool): True if requirement is met, False otherwise.

    Example:
        ```python
        # Check if current version is exactly 22.04
        check_version(current='22.04', required='==22.04')

        # Check if current version is greater than or equal to 22.04
        check_version(current='22.10', required='22.04')  # assumes '>=' inequality if none passed

        # Check if current version is less than or equal to 22.04
        check_version(current='22.04', required='<=22.04')

        # Check if current version is between 20.04 (inclusive) and 22.04 (exclusive)
        check_version(current='21.10', required='>20.04,<22.04')
        ```
    u%   WARNING ⚠️ invalid check_version(, z!) requested, please check values.Tr   u   WARNING ⚠️ z& package is required but not installedF,z([^0-9]*)([\d.]+)z==z!=)z>=r   z<=><z is required, but z is currently installed)r
   r<   isdigitr   r=   PackageNotFoundErrorModuleNotFoundErrorr   r?   r'   r)   r*   r+   groups)ra   rb   r!   rc   rd   resultrE   ropvwarning_messages              r2   check_versionrs      s   B >wir(StuvQZ!	D&&w/G FgA^^C &&s+-q188:A!:!q&F4ZAFF:qAvF4ZaF3YAF3YAF , +D6"hZ?QRVQWWYZaYbbyz%f_&=>>NN?+MA ,, 	)&?7)Kq1r*stt		s   E -E10E1c                 D   t        j                  t              5  t        j                  j
                  j                          t        j                  d|  dd      }|j                  dk(  r|j                         d   d   cddd       S 	 ddd       y# 1 sw Y   yxY w)	a  
    Returns the latest version of a PyPI package without downloading or installing it.

    Parameters:
        package_name (str): The name of the package to find the latest version for.

    Returns:
        (str): The latest version of the package.
    zhttps://pypi.org/pypi/z/jsonr6   )timeout   infor=   N)

contextlibsuppressr;   requestspackagesurllib3disable_warningsgetstatus_codejson)package_nameresponses     r2   check_latest_pypi_versionr      s     
		Y	'!!224<<"8e LVWX3&==?6*95	 
(	' ' 
(	'	's   A(BBc                     t         rpt               rft        j                  t              5  ddlm}  t               }t        | d|       r#t        j                  d| d       	 ddd       y	 ddd       yy# 1 sw Y   yxY w)	z
    Checks if a new version of the ultralytics package is available on PyPI.

    Returns:
        (bool): True if an update is available, False otherwise.
    r   )__version__ri   z)New https://pypi.org/project/ultralytics/u8    available 😃 Update with 'pip install -U ultralytics'NTF)r   r   rx   ry   r;   ultralyticsr   r   rs   r
   rw   )r   latests     r2   check_pip_update_availabler      s{     ."  +/.0F[AfX,7Gx PG H I ,+ 8 ,  , s   :A88Bc                 @   t        |       j                  }t        |z  }|j                         r|S t	        j
                         D cg c]	  }| |v s| }}t        |      r|d   S d| }t        j                  |      rt        j                  ||       |S yc c}w )z
    Find font locally or download to user's configuration directory if it does not already exist.

    Args:
        font (str): Path or name of font.

    Returns:
        file (Path): Resolved font file path.
    r   zhttps://ultralytics.com/assets/)urlfileN)
r   r!   r   existsr   findSystemFontsanyr   is_urlsafe_download)fontr!   r   rI   matchesr   s         r2   
check_fontr     s     :??D T!D{{} '668F8QDAIq8GF
7|qz ,D6
2CCd3  Gs   	BBminimumc                 D    t        t        j                         | dd      S )z
    Check current python version against the required minimum version.

    Args:
        minimum (str): Required minimum version of python.

    Returns:
        None
    zPython T)r!   rc   )rs   platformpython_version)r   s    r2   check_pythonr      s     002G)RVWWrK    Tc                 L   t        ddd      }t                t                t        | t              rm| j                         }|j                         sJ | d| d       t        |      D cg c]+  }|j                  |vs|j                   |j                   - } }nt        | t              r| g} g }| D ]}  }|j                  d      d   j                  dd	      }	t        j                  d
|	      }
|
d   |
d   r|
d   j                         nd	}}	 t!        t#        j$                  |      |      sJ  dj-                  d |D              }|r|rt.        rt1        |      }t3        j4                  | dd|dkD  z   d| d       	 t7        j6                         }t9               sJ d       t3        j4                  t;        j<                  d| d| d      j?                                t7        j6                         |z
  }t3        j4                  | d|dd| dd|dkD  z   d| d| dt        dd       d       yyyc c}w # t&        t"        j(                  f$ r |j+                  |       Y w xY w# t@        $ r$}t3        jB                  | d|        Y d}~yd}~ww xY w) a  
    Check if installed dependencies meet YOLOv8 requirements and attempt to auto-update if needed.

    Args:
        requirements (Union[Path, str, List[str]]): Path to a requirements.txt file, a single package requirement as a
            string, or a list of package requirements as strings.
        exclude (Tuple[str]): Tuple of package names to exclude from checking.
        install (bool): If True, attempt to auto-update packages that don't meet requirements.
        cmds (str): Additional commands to pass to the pip install command when auto-updating.

    Example:
        ```python
        from ultralytics.utils.checks import check_requirements

        # Check a requirements.txt file
        check_requirements('path/to/requirements.txt')

        # Check a single package
        check_requirements('ultralytics>=8.0.0')

        # Check multiple packages
        check_requirements(['numpy', 'ultralytics>=8.0.0'])
        ```
    redboldzrequirements: z not found, check failed./z.gitr   z([a-zA-Z0-9-_]+)([<>!=~]+.*)?r   r    c              3   (   K   | ]
  }d | d   yw)"Nr   )rD   r/   s     r2   rF   z%check_requirements.<locals>.<genexpr>\  s     (4a1QCq4s   z Ultralytics requirementrI   z$ not found, attempting AutoUpdate...zAutoUpdate skipped (offline)zpip install --no-cache Tshellu    AutoUpdate success ✅ .1fzs, installed z package: 
u    ⚠️ z;Restart runtime or rerun command for updates to take effectu    ❌ NF)"r   r   check_torchvisionrM   r   resolver   r3   r!   r"   rG   r)   replacer*   r+   r'   rs   r   r=   AssertionErrorrk   r,   joinr   rU   r
   rw   timer   
subprocesscheck_outputdecoder;   r<   )r0   excludeinstallcmdsprefixr   r/   pkgsro   
r_strippedr+   r!   rb   rI   ntdtr>   s                     r2   check_requirementsr   -  s   6 eV_5FN,%##%{{}I$/HII}:LT:Rl:RQVWV\V\dkVk166(1;;-0:Rl	L#	&$~DWWS\"%--fb9
9:FquQx58>>#3Rh	 !1!1$!7BBB  	(4((A{D	AKK6(":3!a%=/4&Ptuv
IIK {B$BB{J336MaSPQRVQW4X`dellnoYY[1_h6r#hmA3hWZ^_bc^cWdVeeghlgmmohhx8u'v&wwy{|  C m  = => 	KKN	   &qc23s7   ,I  I !IB5I6 *I32I36	J#?JJ#c            	         ddl } dgdgdgd}dj                  t        j                  j	                  d      d   j	                  d      dd	       }dj                  | j                  j	                  d      d   j	                  d      dd	       ||v r3||   }t        fd
|D              rt        d d| d|d    d       yyy)a  
    Checks the installed versions of PyTorch and Torchvision to ensure they're compatible.

    This function checks the installed versions of PyTorch and Torchvision, and warns if they're incompatible according
    to the provided compatibility table based on:
    https://github.com/pytorch/vision#installation.

    The compatibility table is a dictionary where the keys are PyTorch versions and the values are lists of compatible
    Torchvision versions.
    r   Nz0.15z0.14z0.13)z2.0z1.13z1.12.+r    c              3   (   K   | ]	  }|k7    y w)Nr   )rD   rq   v_torchvisions     r2   rF   z$check_torchvision.<locals>.<genexpr>  s     ?+>a}!+>s   u   WARNING ⚠️ torchvision==z is incompatible with torch==z .
Run 'pip install torchvision==z' to fix torchvision or 'pip install -U torch torchvision' to update both.
For a full compatibility table see https://github.com/pytorch/vision#installation)torchvisionr   rN   r   r)   rH   print)r   compatibility_tablev_torchcompatible_versionsr   s       @r2   r   r   r  s      $*(VHvhO hhu((..s3A6<<SA"1EFGHH[44::3?BHHMbqQRM%%1':?+>??0?\]d\e f33Fq3I2J Kff g @ &rK   c                    | r|rt        |t              r|f}t        | t        t        f      r| n| gD ]T  }t	        |      j
                  j                         j                         }t        |      s@||v rEJ | | d| d|         yyy)z$Check file(s) for acceptable suffix.z acceptable suffix is z, not N)	rM   rG   rQ   r7   r   suffixlowerr'   rU   )r   r   r^   frI   s        r2   check_suffixr     s    fc"ZF#D4-8tfDAQ$$&,,.A1vF{VseA3.DVHFSTRU$VV{ E trK   r   c                 *   d| v sd| v rd| v r| j                  dd      } | S d| v rnd| vrj| }t        j                  dd|       } t        j                  d	d|       } t        j                  d
d|       } | |k7  r|rt        j                  d| d|  d       | S )z?Replace legacy YOLOv5 filenames with updated YOLOv5u filenames.yolov3yolov5zu.yaml.yaml.ptuz(.*yolov5([nsmlx]))\.ptz\1u.ptz(.*yolov5([nsmlx])6)\.ptz(.*yolov3(|-tiny|-spp))\.ptu   PRO TIP 💡 Replace 'model=z' with new 'model=z'.
YOLOv5 'u' models are trained with https://github.com/ultralytics/ultralytics and feature improved performance vs standard YOLOv5 models trained with https://github.com/ultralytics/yolov5.
)r   r*   subr
   rw   )r   rd   original_files      r2   check_yolov5u_filenamer     s    48t+t<<'2D K d]s$ M664iFD665y$GD668)TJD}$2=/ASTXSY Zc de KrK   c                    t        | |       t        |       j                         } t        |       } | rd| vrt	        |       j                         r| S |r| j                         j                  d      rf| }t        |       } t	        |       j                         r&t        j                  dt        |       d|         | S t        j                  || d       | S t        j                  t        t        dz  dz  | z        d	
      }|s|rt!        d|  d      t#        |      dkD  r|rt!        d|  d|       t#        |      r|d   S g S )z4Search/download file (if necessary) and return path.z://)zhttps://zhttp://zrtsp://zrtmp://ztcp://zFound z locally at F)r   r   unzipcfgz**T)	recursive'z' does not existr   zMultiple files match 'z', specify exact path: r   )r   rG   r'   r   r   r   r   r(   r   r
   rw   r   r   r   globr   FileNotFoundErrorrU   )r   r   downloadrc   r   filess         r2   
check_filer     s2   vt9??D!$'DE%$t**;*;*=	djjl--.ef~:KK&3 0TFCD  ##$eD		#dUlT1D89TJ#av-=$>??Z!^#&<TFBYZ_Y`$abbu:uQx-2-rK   c                     t        | ||      S )zJSearch/download YAML file (if necessary) and return path, checking suffix.rc   )r   )r   r   rc   s      r2   
check_yamlr     s    dF..rK   c                    	 t         r2dt        j                  v rt               st	               s
t               rJ t        j                  dt        j                  dt        j                               t        j                  d       t        j                          t        j                  d       y# t        $ r$}| rt        j                  d|        Y d}~y	d}~ww xY w)
z-Check if environment supports image displays.DISPLAYtest)   r   r6   )dtyper   TuM   WARNING ⚠️ Environment does not support cv2.imshow() or PIL Image.show()
NF)r	   osenvironr   r   r   cv2imshownpzerosuint8waitKeydestroyAllWindowsr;   r
   r<   )warnr>   s     r2   check_imshowr     s    

*9;xzZcZeee

6288IRXX>?AA NNklmknops   B/B2 2	C;CCc           	      R   ddl }ddlm} t               rCt	        dd      rt        j                  d       t               rt        j                  dd	
       | rd}|j                         j                  }t        j                  d      \  }}}dt        j                          d||z  dd||z
  |z  dd||z  dd	}	t        j                  t               5  ddlm}
 |
j'                          ddd       nd}	 ||d       t)        j*                  d|	        y# 1 sw Y   ,xY w)z;Return a human-readable YOLO software and hardware summary.r   N)select_devicewandbF)r   zpip uninstall -y wandbsample_dataT)ignore_errors   @r   (z CPUs, r   z	 GB RAM, z	 GB disk))displayr   )devicenewlineu   Setup complete ✅ )psutilultralytics.utils.torch_utilsr   r   r   r   systemr   shutilrmtreevirtual_memorytotal
disk_usage	cpu_countrx   ry   r;   IPythonr   clear_outputr
   rw   )rd   r   r   r   gibramr   usedfreerI   r   s              r2   
check_yolor    s   ;|gu5II./:MM-t<##%++"--c2tTwsSyoYPS?STW>XXYZ_beZefiYjjst  +'  " ,+ /
KK%aS)* ,+s   DD&c                  T   ddl } ddlm}m} ddlm} | j                         j                  dz  }t                t        j                  dddt        j                          dd	d| dd
dt        j                  j                         d    ddd |       rdnt               rdnd ddd|dddd |        dddt         r8t         j"                  j%                         rt         j                  j"                  nd d       t'        d      D ]y  }	 t)        j                  |j*                        }t-        |t/        |j0                        d      rdnd}t        j                  |j*                  d| | |j0                          { y# t(        j2                  $ r d}d}Y Nw xY w)zWCollect and print relevant system information including OS, Python, RAM, CPU, and CUDA.r   N)ENVIRONMENT
is_git_dir)get_cpu_infor   r   OSz<20EnvironmentPythonInstallgitpipotherRAMz.2fz GB
CPUCUDAr   )r.   Tr   u   ✅ u   ❌ z(not installed))r   ultralytics.utilsr
  r  r   r  r   r   r  r
   rw   r   sysr=   r)   r   rN   cudais_availabler3   r   r!   rs   rG   r"   rk   )r   r
  r  r  ram_inforo   ra   is_mets           r2   collect_system_infor    s}    9:$$&,,	:HL
KK"T#Jx00232 %k]"C.!2!2!4Q!7 8S/:<%nFVU\c!ddf+hs^5+ln-R#,Uuzz?V?V?Xu}}11^bcceg h  6	&&qvv.G,Wc!++6FTRVX^F 	qvvcl6(7)AKK=AB 7 ,, 	'GF	s   AFF'&F'c                    t        | j                               j                  j                  dv ryfd}t        dz  }t        d      }t        j                  | d       d}	 dd	lm	}  | |d
      |      sJ t        j                  | d       y# t        $ r t        j                  | d|        Y yt        t        f$ r t        j                  | d|        Y yt        $ r t        j                  | d       Y yw xY w)a  
    This function checks the PyTorch Automatic Mixed Precision (AMP) functionality of a YOLOv8 model. If the checks
    fail, it means there are anomalies with AMP on the system that may cause NaN losses or zero-mAP results, so AMP will
    be disabled during training.

    Args:
        model (nn.Module): A YOLOv8 model instance.

    Example:
        ```python
        from ultralytics import YOLO
        from ultralytics.utils.checks import check_amp

        model = YOLO('yolov8n.pt').model.cuda()
        check_amp(model)
        ```

    Returns:
        (bool): Returns True if the AMP functionality works correctly with YOLOv8 model, else False.
    )cpumpsFc                     | |d      d   j                   j                  }t        j                  j                  j                  d      5   | |d      d   j                   j                  }ddd       ~ |j                  j                  k(  xr& t        j                  ||j                         d      S # 1 sw Y   KxY w)zAll close FP32 vs AMP results.F)r   rd   r   TNg      ?)atol)	boxesdatarN   r  ampautocastshapeallclosefloat)mimabr   s       r2   amp_allclosezcheck_amp.<locals>.amp_allclose+  s    b/288==ZZ^^$$T*"VU3A6<<AAA +ww!''!LennQ	&LL +*s   #B::Czbus.jpgzAMP: z>running Automatic Mixed Precision (AMP) checks with YOLOv8n...z`Setting 'amp=True'. If you experience zero-mAP or NaN losses you can disable AMP with amp=False.r   )YOLO
yolov8n.ptu   checks passed ✅u?   checks skipped ⚠️, offline and unable to download YOLOv8n. ua   checks skipped ⚠️. Unable to load YOLOv8n due to possible Ultralytics package modifications. u   checks failed ❌. Anomalies were detected with AMP on your system that may lead to NaN losses or zero-mAP results, so AMP will be disabled during training.T)next
parametersr   rS   r   r   r
   rw   r   r/  ConnectionErrorr<   AttributeErrorrl   r   )modelr.  r+  r   warning_msgr/  r   s         @r2   	check_ampr7    s,   * %""$%,,F{{n$M 
)	BgF
KK6(XYZtK$D.333vh/01   p&!`al`mno  /0 s& "ddocpr 	s 	  & "b c 	ds   (/B #D
=(D
' D
	D
c                     t        j                  t              5  t        j                  d|  dd      j                         dd cddd       S # 1 sw Y   yxY w)zbReturn human-readable git description, i.e. v5.0-5-g3e25f1e https://git-scm.com/docs/git-describe.zgit -C z  describe --tags --long --alwaysTr   Nr   r   )rx   ry   r;   r   r   r   )paths    r2   git_describer:  G  sL    			Y	'&&6V'W_cdkkmnqoqr 
(	'	's   ,AAargsc                    d t        j                         j                  }t        j                  |      \  }}}}}| Bt        j                  |      \  } }}}|j                         D 	ci c]  \  }}	|| v s||	 } }}		 t        |      j                         j                  t              j                  d      }|r| dnd|r| dndz   }
t        j                  t        |
      dj!                  fd| j                         D              z          yc c}	}w # t        $ r t        |      j                  }Y w xY w)z.Print function arguments (optional args dict).c                 z    t        | t              r*| j                  d      rt        |       dkD  rt	        |       S | S )zTClean longer Ultralytics HUB URLs by stripping potential authentication information.httpd   )rM   rG   r(   rU   r   )rq   s    r2   
strip_authzprint_args.<locals>.strip_authQ  s5     *1c 2q||F7KPSTUPVY\P\y|dcddrK   Nr   r   rf   c              3   >   K   | ]  \  }}| d  |         yw)=Nr   )rD   krq   r@  s      r2   rF   zprint_args.<locals>.<genexpr>_  s%     'X<41a1#Qz!}o(><s   )inspectcurrentframef_backgetframeinfogetargvaluesitemsr   r   relative_tor   with_suffixrV   stemr
   rw   r   r   )r;  	show_file	show_funcr/   r   _funcfrmrC  rq   rI   r@  s              @r2   
print_argsrR  N  s   e 	%%A!..q1D!T1a|!..q1aC!$:AT	1:Dz!!#//5AA"E "D6rYbkBOA
KKdii'X4::<'XXXY ;  Dzs   -D:D;D E ?E c                      	 t        j                  g dd      } | j                         j                  d      d   }t	        |      S # t         j
                  t        t        f$ r Y yw xY w)z
    Get the number of NVIDIA GPUs available in the environment.

    Returns:
        (int): The number of NVIDIA GPUs available.
    )z
nvidia-smiz--query-gpu=countz--format=csv,noheader,nounitszutf-8)encodingr   r   )r   r   r'   r)   r9   CalledProcessErrorr   rV   )output
first_lines     r2   cuda_device_countrX  b  sd    (()m29; \\^))$/2
:))+<jI s   AA A)(A)c                      t               dkD  S )z
    Check if CUDA is available in the environment.

    Returns:
        (bool): True if one or more NVIDIA GPUs are available, False otherwise.
    r   )rX  r   rK   r2   cuda_is_availablerZ  w  s     ""rK   )0.0.0)    r   r    r   )r[  r[  r=   FF)r   )z	Arial.ttf)z3.8.0)r0  r   r   )T)r   TT))r   z.ymlT)F)Tr   )NTF)Krx   r   rD  rW   r   r   r*   r   r   r  r   	importlibr   pathlibr   typingr   r   numpyr   rz   rN   
matplotlibr   r  r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   parentr3   r7   r?   boolrJ   r`   rG   rs   r   r   r   r   r   r   r   r   r   r   r   r  r  r7  r:  dictrR  r9   rX  rZ  r   rK   r2   <module>re     s       	  	   
     
    #[ [ [ [ [ [
 "&/A!A2 !He $(4 ("-` ")")'$"'	H3 HHH H  	H -1	HV6"$  :
X# 
XD 
X $(KK2D$DbZ^eg A AHg<W t $.0/
 +8C82j  ZXd^ Z(3 *#4 #rK   