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.45k stars 5.61k forks source link

could you please explain what are the role of crop_overlap_ratio and crop_n_points_downscale_factor parameters? #750

Open jetsonwork opened 5 months ago

jetsonwork commented 5 months ago

Hi, could you please explain what are the role of crop_overlap_ratio and crop_n_points_downscale_factor parameters? Thanks!

steinkchristensen commented 1 week ago

Here's how crops work:

  1. First the entire image has masks generated for it based on your grid size you declare (32 x 32 for example)
  2. Next, if crop_n_layers > 0, then it will divide the photo into quadrants with the amount of overlap between those quadrants being set as crop_overlap_ratio. This prevents some masks from being missed by two adjacent quadrants.
  3. For each quadrant, it will "zoom into each" for another round of automatic mask generation. crop_n_points_downscale_factor =1 means a 32x32 grid will be used for generating masks in this quadrant. If that is overkill, and you dont need that many points inside a quadrant, you can use for example crop_n_points_downscale_factor=2 which will make the grid 16x16 inside that quadrant.
  4. Crop_NMS determines which masks to keep from the quadrants but I'm not perfectly clear on how that works