facebookresearch / segment-anything

The repository provides code for running inference with the SegmentAnything Model (SAM), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.
Apache License 2.0
47.83k stars 5.66k forks source link

About SamAutomaticMaskGenerator, how to get maps less than 4**2 ? #417

Open xyjin01 opened 1 year ago

xyjin01 commented 1 year ago

In SamAutomaticMaskGenerator, I set points Per Set to 4, I thought the segmentation maps I obtain should not exceed 4 * 4, which is 16, but I obtained 22 feature maps. Why? My setting is:

mask_generator = SamAutomaticMaskGenerator( model=sam, points_per_side=4, #32 points_per_batch = 64, pred_iou_thresh=0.88, stability_score_thresh=0.95, stability_score_offset=1.0, box_nms_thresh=0.7, crop_n_layers=0, crop_nms_thresh = 0.7, crop_overlap_ratio = 512 / 1500, crop_n_points_downscale_factor=0,

point_grids: Optional[List[np.ndarray]] = None,

min_mask_region_area=0, # Requires open-cv to run post-processing output_mode = "binary_mask", )

Could anyone tell me why? And what is the correct settings to get maps whose number is not larger than 16? Thanks very much!

Yuhan-Shen commented 1 year ago

For each point, SAM will output three masks by default, so the number of raw segmentation maps should be 3 4 4 = 48 in your case. If you only want one segmentation mask per point, you can set multimask_output as False in this line.

xyjin01 commented 1 year ago

For each point, SAM will output three masks by default, so the number of raw segmentation maps should be 3 4 4 = 48 in your case. If you only want one segmentation mask per point, you can set multimask_output as False in this line.

Oh, it really works!! Thank you very much, you really did me a big favor!