{"library":"sam2","title":"SAM 2 (Segment Anything 2)","description":"SAM 2 is the second generation of the Segment Anything Model, supporting both image and video segmentation. Version 1.1.0 introduces new model variants (e.g., sam2.1_hiera_tiny) and improvements. Install from PyPI; requires Python >=3.10.","language":"python","status":"active","last_verified":"Mon Apr 27","install":{"commands":["pip install sam2"],"cli":null},"imports":["from sam2.build_sam import build_sam2","from sam2.predictor import SamPredictor","from sam2.sam2_image_predictor import SAM2ImagePredictor"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import torch\nfrom sam2.build_sam import build_sam2\nfrom sam2.sam2_image_predictor import SAM2ImagePredictor\n\ncheckpoint = \"sam2.1_hiera_tiny.pt\"\nmodel_cfg = \"sam2.1_hiera_t.yaml\"\n\npredictor = SAM2ImagePredictor(build_sam2(model_cfg, checkpoint))\n\nimport numpy as np\nimage = np.random.rand(1024, 1024, 3).astype(np.uint8)\npredictor.set_image(image)\n\ninput_point = np.array([[500, 375]])\ninput_label = np.array([1])\nmask, _, _ = predictor.predict(point_coords=input_point, point_labels=input_label)\nprint(mask.shape)","lang":"python","description":"Load a SAM 2 model, set an image, and predict a mask from a point prompt.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}