"""Check if optional packages required by some modules are available."""fromfunctoolsimportlru_cachefromimportlib.utilimportfind_specimporttorchfrompackagingimportversion
[docs]@lru_cache()defpackage_available(package_name:str)->bool:"""Check if a package is available in your environment."""try:returnfind_spec(package_name)isnotNoneexceptModuleNotFoundError:# pragma: no coverreturnFalse
# ioH5PY_AVAILABLE=package_available("h5py")# visionMMCV_AVAILABLE=package_available("mmcv")orpackage_available("mmcv-full")MMDET_AVAILABLE=package_available("mmdet")MMSEG_AVAILABLE=package_available("mmseg")DETECTRON2_AVAILABLE=package_available("detectron2")TIMM_AVAILABLE=package_available("timm")FVCORE_AVAILABLE=package_available("fvcore")# datasetsWAYMO_AVAILABLE=package_available("waymo")NUSCENES_AVAILABLE=package_available("nuscenes")SCALABEL_AVAILABLE=package_available("scalabel")BDD100K_AVAILABLE=package_available("bdd100k")# visualizationOPENCV_AVAILABLE=package_available("cv2")DASH_AVAILABLE=package_available("dash")OPEN3D_AVAILABLE=package_available("open3d")PLOTLY_AVAILABLE=package_available("plotly")# vis4d cuda opsVIS4D_CUDA_OPS_AVAILABLE=package_available("vis4d_cuda_ops")# loggingTENSORBOARD_AVAILABLE=package_available("tensorboardX")orpackage_available("tensorboard")
[docs]defis_torch_tf32_available()->bool:# pragma: no cover"""Check if torch TF32 is available. Returns: bool: True if torch TF32 is available. """returnnot(nottorch.cuda.is_available()ortorch.version.cudaisNoneorint(torch.version.cuda.split(".",maxsplit=1)[0])<11orversion.parse(torch.__version__)<version.parse("1.7"))