Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Heuristic:Obss Sahi Auto Slice Resolution

From Leeroopedia




Knowledge Sources
Domains Computer_Vision, Object_Detection, Optimization
Last Updated 2026-02-08 12:00 GMT

Overview

Automatic slice size and overlap calculation based on image resolution, eliminating manual parameter tuning for different image sizes.

Description

SAHI's auto-resolution system classifies images into four resolution tiers based on total pixel area, then selects appropriate slice dimensions and overlap ratios for each tier. The classification uses a resolution factor — the exponent of the power of 2 closest to the image area. This provides a logarithmic scale that naturally groups images by effective resolution.

The system also accounts for image orientation (portrait, landscape, square), applying asymmetric slice grids (e.g., more vertical slices for tall images) to optimize coverage.

Usage

Use this heuristic when `auto_slice_resolution=True` is set (the default) in `get_sliced_prediction()` and no explicit `slice_height`/`slice_width` are provided. The auto-resolution system activates automatically and replaces manual slice parameter configuration.

The Insight (Rule of Thumb)

  • Action: Set `auto_slice_resolution=True` (default) and omit `slice_height`/`slice_width` to let SAHI auto-calculate.
  • Resolution Classification:
    • factor <= 18 (e.g., 300x300, 640x640): Low resolution — no slicing (1x1 grid)
    • 18 < factor <= 21 (e.g., 1024x1024, 1336x960): Medium — moderate slicing with 0.8 overlap
    • 21 < factor <= 24 (e.g., 2048x2048, 4096x4096): High — aggressive slicing with 0.4 overlap
    • factor > 24 (e.g., 6380x6380, 4096x8192): Ultra-high — very aggressive slicing with 0.4 overlap
  • Orientation Adaptation: Vertical images get more row splits; horizontal images get more column splits.
  • Trade-off: Auto-slice may not be optimal for every use case. Manual tuning can outperform auto-slice when object sizes are known in advance.
Resolution Orientation Grid (rows x cols) Overlap
Low Any 1x1 N/A (no slicing)
Medium Vertical 1x2 0.8
Medium Horizontal 2x1 0.8
High Vertical 2x4 0.4
High Horizontal 4x2 0.4
Ultra-high Vertical 4x8 0.4
Ultra-high Horizontal 8x4 0.4

Reasoning

The resolution factor uses a logarithmic (power-of-2) scale because human perception of image "bigness" is logarithmic — a 4096x4096 image feels "twice as big" as 2048x2048 despite having 4x the pixels. The factor boundaries (18, 21, 24) correspond to practical resolution classes:

  • factor 18 ≈ 2^18 = 262,144 pixels ≈ 512x512
  • factor 21 ≈ 2^21 = 2,097,152 pixels ≈ 1448x1448
  • factor 24 ≈ 2^24 = 16,777,216 pixels ≈ 4096x4096

The high overlap (0.8) for medium-resolution images ensures good boundary coverage when there are only 2 slices. For high and ultra-high images with many more slices, 0.4 overlap is sufficient because objects are more likely to be fully contained in a single tile.

Low-resolution images skip slicing entirely because the model can handle the full image directly, and slicing would only add overhead without benefit.

Code evidence from `sahi/slicing.py:632-656`:

def get_auto_slice_params(height: int, width: int):
    resolution = height * width
    factor = calc_resolution_factor(resolution)
    if factor <= 18:
        return get_resolution_selector("low", height=height, width=width)
    elif 18 <= factor < 21:
        return get_resolution_selector("medium", height=height, width=width)
    elif 21 <= factor < 24:
        return get_resolution_selector("high", height=height, width=width)
    else:
        return get_resolution_selector("ultra-high", height=height, width=width)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment