> ## Documentation Index
> Fetch the complete documentation index at: https://felimet-hub.jmcores.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SAM2 image segmentation annotation tool

> Windows desktop annotation app built on Meta SAM2 that generates segmentation masks from clicks, with a packaged .exe and from-source PyInstaller install paths.

export const OptionPicker = ({options = [], lang = "zh", label}) => {
  const t = lang === "en" ? {
    pick: label || "Pick an option to compare",
    rec: "Recommended"
  } : {
    pick: label || "點選項目比較",
    rec: "推薦"
  };
  const opts = Array.isArray(options) ? options : [];
  const [sel, setSel] = useState(0);
  if (opts.length === 0) return null;
  const idx = Math.min(sel, opts.length - 1);
  const cur = opts[idx];
  const css = `
  .op-root{--op-bg:#FAF8F3;--op-surface:rgba(0,0,0,0.025);--op-border:rgba(0,0,0,0.09);--op-text:#2b2722;--op-dim:#6f6a62;--op-faint:#8a8378;--op-accent:#bf7551;border:1px solid var(--op-border);border-radius:14px;background:var(--op-bg);color:var(--op-text);overflow:hidden;}
  .dark .op-root{--op-bg:#1b1a18;--op-surface:rgba(255,255,255,0.03);--op-border:rgba(255,255,255,0.08);--op-text:#e7e3da;--op-dim:#a8a299;--op-faint:#8a8378;--op-accent:#cf8a68;}
  .op-head{padding:12px 16px 11px;border-bottom:1px solid var(--op-border);font-size:12.5px;color:var(--op-dim);display:flex;align-items:center;gap:8px;}
  .op-head-ic{color:var(--op-accent);flex-shrink:0;}
  .op-tabs{display:flex;gap:8px;padding:14px 16px 4px;flex-wrap:wrap;}
  .op-tab{position:relative;flex:1 1 130px;min-width:120px;text-align:left;background:transparent;border:1px solid var(--op-border);border-radius:11px;padding:11px 13px;cursor:pointer;color:inherit;font:inherit;transition:border-color .15s,background .15s,box-shadow .15s;}
  .op-tab:hover{background:var(--op-surface);}
  .op-tab-on{border-color:rgba(191,117,81,.5);background:rgba(191,117,81,.07);box-shadow:0 0 0 3px rgba(191,117,81,.1);}
  .op-tab-name{font-size:14.5px;font-weight:600;line-height:1.3;}
  .op-tab-on .op-tab-name{color:var(--op-accent);}
  .op-badge{display:inline-block;margin-top:6px;font-size:10.5px;font-weight:700;letter-spacing:.4px;text-transform:uppercase;padding:2px 7px;border-radius:20px;background:rgba(191,117,81,.14);color:var(--op-accent);}
  .op-rec{position:absolute;top:10px;right:11px;font-size:10px;font-weight:700;letter-spacing:.3px;text-transform:uppercase;color:var(--op-accent);}
  .op-body{padding:6px 16px 16px;}
  .op-specs{border:1px solid var(--op-border);border-radius:10px;overflow:hidden;margin-bottom:11px;}
  .op-row{display:flex;border-top:1px solid var(--op-border);font-size:13px;}
  .op-row:first-child{border-top:none;}
  .op-k{width:42%;flex-shrink:0;padding:8px 12px;color:var(--op-dim);background:var(--op-surface);}
  .op-v{flex:1 1 0;min-width:0;padding:8px 12px;font-weight:500;}
  .op-note{font-size:13px;line-height:1.6;color:var(--op-dim);padding:0 2px;}
  `;
  return <div className="op-root">
      <style>{css}</style>
      <div className="op-head"><svg className="op-head-ic" xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z" /><path d="m22 17.65-9.17 4.16a2 2 0 0 1-1.66 0L2 17.65" /><path d="m22 12.65-9.17 4.16a2 2 0 0 1-1.66 0L2 12.65" /></svg>{t.pick}</div>
      <div className="op-tabs">
        {opts.map((o, i) => <button key={i} type="button" className={"op-tab" + (i === idx ? " op-tab-on" : "")} onClick={() => setSel(i)}>
            {o.recommend && <span className="op-rec">★ {t.rec}</span>}
            <div className="op-tab-name">{o.name}</div>
            {o.badge && <span className="op-badge">{o.badge}</span>}
          </button>)}
      </div>
      <div className="op-body">
        <div className="op-specs">
          {(cur.specs || []).map((row, i) => <div className="op-row" key={i}>
              <div className="op-k">{row[0]}</div>
              <div className="op-v">{row[1]}</div>
            </div>)}
        </div>
        {cur.note && <div className="op-note">{cur.note}</div>}
      </div>
    </div>;
};

`SAM2` · `Python` · `Computer Vision` · `Annotation` · `Windows` · `CUDA`

## Overview

A Windows desktop annotation application built on Meta's Segment Anything Model 2 (SAM2). Users click on a target in an image to generate a segmentation mask without manual tracing. It ships as a packaged `.exe` for direct use, and can also be built from source with PyInstaller, producing a `dist/SAM2_Annotation_Tool` executable directory. The primary use case is building labelled datasets for computer vision research.

## Core features

* Click-driven SAM2 zero-shot segmentation to generate masks quickly
* Annotate multiple target regions in a single image in sequence
* Export annotation results for use in downstream training pipelines
* Packaged executable means no Python environment setup for end users
* Supports multiple SAM2 model sizes (tiny / small / base\_plus / large) to trade off speed and accuracy

## Quick start

Two install paths; compare them first, then follow the detailed steps:

<OptionPicker
  lang="en"
  label="Compare install paths"
  options={[
{
name: "Packaged executable", badge: "general use", recommend: true,
specs: [["Python env", "Not needed"], ["Build step", "No"], ["GPU", "NVIDIA 6 GB+ recommended"], ["How to get", "Download Release zip"], ["Best for", "General users, annotators"]],
note: "Unzip and run, no Python environment. Lowest barrier to start annotating."
},
{
name: "Build from source", badge: "developers",
specs: [["Python env", "3.9+ with CUDA PyTorch"], ["Build step", "PyInstaller (setup.py)"], ["GPU", "NVIDIA + CUDA required"], ["How to get", "git clone + pip install -e"], ["Best for", "Editing the code, custom flows"]],
note: "Modify the source and repackage yourself. Fits developers integrating it into an existing pipeline."
}
]}
/>

### Option A: packaged executable (recommended for general use)

<Steps>
  <Step title="Download the packaged release">
    Download the latest `SAM2_Annotation_Tool.zip` from the Releases page and extract it to any directory.
  </Step>

  <Step title="Run the application">
    Launch `SAM2_Annotation_Tool.exe` from the extracted folder. The annotation interface opens immediately; no Python installation required.
  </Step>
</Steps>

### Option B: build from source (for developers)

<Steps>
  <Step title="Install Python and PyTorch (CUDA wheel)">
    Install Python 3.9 or later, then install PyTorch with the CUDA wheel:

    ```bash theme={null}
    pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118
    ```
  </Step>

  <Step title="Install remaining dependencies">
    ```bash theme={null}
    pip install matplotlib numpy pillow pyinstaller tqdm
    ```
  </Step>

  <Step title="Clone the SAM2 repo and install">
    ```bash theme={null}
    git clone https://github.com/facebookresearch/sam2.git
    cd sam2
    pip install -e .
    ```
  </Step>

  <Step title="Download model checkpoints">
    ```bash theme={null}
    cd checkpoints
    ./download_ckpts.sh
    ```

    Alternatively, download the `.pt` weights manually from the [SAM2 repository](https://github.com/facebookresearch/sam2).
  </Step>

  <Step title="Run the packaging script">
    ```bash theme={null}
    python setup.py
    ```

    The executable is placed in `dist/SAM2_Annotation_Tool` when the script finishes.
  </Step>
</Steps>

## Notes

<Warning>
  A Windows 10/11 (64-bit) machine with an NVIDIA GPU (6 GB VRAM or more) and CUDA support is recommended. The tool can run in CPU mode without a GPU, but inference will be noticeably slower. If you hit out-of-memory errors, switch to a smaller model (e.g. `sam2.1_hiera_tiny.pt`) or reduce the input image size. Verify that PyTorch can see CUDA:

  ```python theme={null}
  import torch
  print(torch.cuda.is_available())
  ```
</Warning>

## In practice

Useful for building custom image segmentation datasets: livestock body contour labelling, agricultural object region marking, or any task that needs pixel-level masks generated quickly. The packaged executable lowers the barrier for non-Python annotators to participate in data collection directly.

## Links

* GitHub: [felimet/SAM2\_Annotation\_Tool](https://github.com/felimet/SAM2_Annotation_Tool)
* SAM2 repository: [facebookresearch/sam2](https://github.com/facebookresearch/sam2)
