Spaces:
Runtime error
Runtime error
Update sam2_mask.py
Browse files110 unmodified lines1111121131141151166 unmodified lines12312412512612712812922 unmodified lines152153154155156157158159110 unmodified linesmask = feather_mask(mask, feather_size)return maskdef sam_process(input_image, checkpoint, tracking_points, trackings_input_label, expand_contract_px, expand, feathering_enabled, feather_size):image = Image.open(input_image)image = np.array(image.convert("RGB"))6 unmodified lines# sam2_checkpoint, model_cfg = checkpoint_map[checkpoint]# Use CPU for both model and computations# sam2_model = build_sam2(model_cfg, sam2_checkpoint, device="cpu")predictor = SAM2ImagePredictor.from_pretrained(sam21_hfmap[checkpoint], device="cpu")# predictor = SAM2ImagePredictor(sam2_model)predictor.set_image(image)22 unmodified linestracking_points = gr.State([])trackings_input_label = gr.State([])with gr.Column():gr.Markdown("# SAM2 Image Predictor (CPU Version)")gr.Markdown("This version runs entirely on CPU")with gr.Row():with gr.Column():input_image = gr.Image(label="input image", interactive=False, type="filepath", visible=False)110 unmodified lines1111121131141151161176 unmodified lines12412512612712812913022 unmodified lines153154155156157158159110 unmodified linesmask = feather_mask(mask, feather_size)return mask@spaces.GPU()def sam_process(input_image, checkpoint, tracking_points, trackings_input_label, expand_contract_px, expand, feathering_enabled, feather_size):image = Image.open(input_image)image = np.array(image.convert("RGB"))6 unmodified lines# sam2_checkpoint, model_cfg = checkpoint_map[checkpoint]# Use CPU for both model and computations# sam2_model = build_sam2(model_cfg, sam2_checkpoint, device="cpu")predictor = SAM2ImagePredictor.from_pretrained(sam21_hfmap[checkpoint], device="cuda")# predictor = SAM2ImagePredictor(sam2_model)predictor.set_image(image)22 unmodified linestracking_points = gr.State([])trackings_input_label = gr.State([])with gr.Column():gr.Markdown("# SAM2 Image Predictor / Masking Assistant")with gr.Row():with gr.Column():input_image = gr.Image(label="input image", interactive=False, type="filepath", visible=False)
sam2_mask.py+3-3