π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
Update rst(docs) files to support MPS (#2430)
Nripesh Niketand821ccf7a2e5
diff --git a/docs/source/models/segment_anything.rst b/docs/source/models/segment_anything.rstindex fa4748174..9ba72bf8f 100644--- a/docs/source/models/segment_anything.rst+++ b/docs/source/models/segment_anything.rst@@ -96,11 +96,11 @@ to query the image masks from the SAM model.from kornia.io import load_image, ImageLoadTypefrom kornia.geometry.keypoints import Keypointsfrom kornia.geometry.boxes import Boxes- from kornia.utils import get_cuda_device_if_available+ from kornia.utils import get_cuda_or_mps_device_if_availablemodel_type = 'vit_h'checkpoint = './https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth'- device = get_cuda_device_if_available()+ device = get_cuda_or_mps_device_if_available# Load imageimage = load_image('./example.jpg', ImageLoadType.RGB32, device)@@ -180,7 +180,7 @@ parameters. If a checkpoint URL or path for a file is seted, the method will aut.. code-block:: pythonfrom kornia.contrib.models.sam import Sam, SamConfig- from kornia.utils import get_cuda_device_if_available+ from kornia.utils import get_cuda_or_mps_device_if_available# model_type can be:# 0, 'vit_h' or `kornia.contrib.models.sam.SamModelType.vit_h`@@ -190,7 +190,7 @@ parameters. If a checkpoint URL or path for a file is seted, the method will aut# The checkpoint can be a filepath or a urlcheckpoint = './path_for_the_model_checkpoint.pth'- device = get_cuda_device_if_available()+ device = get_cuda_or_mps_device_if_available()# Load configconfig = SamConfig(model_type, checkpoint)@@ -216,13 +216,13 @@ If a URL is passed the model will automatically download and cache the weights u.. code-block:: pythonfrom kornia.contrib.models.sam import Sam, SamConfig- from kornia.utils import get_cuda_device_if_available+ from kornia.utils import get_cuda_or_mps_device_if_availablemodel_type = 'vit_b'# The checkpoint can be a filepath or a urlcheckpoint = './path_for_the_model_checkpoint.pth'- device = get_cuda_device_if_available()+ device = get_cuda_or_mps_device_if_available()# Load/build the modelsam_model = Sam.from_config(SamConfig(model_type))@@ -245,13 +245,13 @@ This is a simple example, of how to directly use the SAM model loaded. We recommfrom kornia.contrib.models.sam import Samfrom kornia.contrib.models import SegmentationResultsfrom kornia.io import load_image, ImageLoadType- from kornia.utils import get_cuda_device_if_available+ from kornia.utils import get_cuda_or_mps_device_if_availablefrom kornia.geometry import resizefrom kornia.enhance import normalizemodel_type = 'vit_b' # or can be a number `2` or the enum sam.SamModelType.vit_bcheckpoint_path = './path_for_the_model_checkpoint.pth'- device = get_cuda_device_if_available()+ device = get_cuda_or_mps_device_if_available()# Load the modelsam_model = Sam.from_pretrained(model_type, checkpoint_path, device)diff --git a/docs/source/utils.rst b/docs/source/utils.rstindex 8e81a3386..b7229c422 100644--- a/docs/source/utils.rst+++ b/docs/source/utils.rst@@ -39,6 +39,8 @@ Device-------.. autofunction:: get_cuda_device_if_available+.. autofunction:: get_mps_device_if_available+.. autofunction:: get_cuda_or_mps_device_if_available.. autofunction:: map_location_to_cpu