# Use SAM2 with images import torch from sam2.sam2_image_predictor import SAM2ImagePredictor predictor = SAM2ImagePredictor.from_pretrained(facebook/sam2.1-hiera-large) with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): predictor.set_image() masks, _, _ = predictor.predict()