Local pipeline for:
input/: input videos and optional evaluation filesoutput/: generated tracker, audio, eval, analysis, and UI run artifactscheckpoints/: SAM2 checkpointsconfigs/: SAM2 configssam_audio_models/: local SAM-Audio model folderssam2/: optional project-local SAM2 source checkoutsam-audio/: optional project-local SAM-Audio source checkouttools/ffmpeg/: optional repo-local ffmpeg binaries for Windows and LinuxThis folder is intended for large project assets such as SAM-Audio model folders and saved run outputs. Hugging Face authentication token
.venv between Windows and Linux..venv on that machine.cu128 wheels.cu124, cu126, cu128, and CUDA 13 wheels in the same .venv.sam_audio_models/small-tv/checkpoint.ptsam_audio_models/small-tv/config.jsonsam_audio_models/base-tv/checkpoint.ptsam_audio_models/base-tv/config.jsonsam_audio_models/large-tv/checkpoint.ptsam_audio_models/large-tv/config.jsoncheckpoints/sam2.1_hiera_tiny.ptconfigs/sam2.1/sam2.1_hiera_t.yamldataset_prep.py when needed.tracker.py.audio_pipeline.py --video-path ... --mask-path ....evaluation.py.analyze_results.py.Important alignment rule: audio_pipeline.py expects the supplied --video-path to match the tracker mask stack exactly in frame count, frame resolution, and clip segment. If tracking ran on only part of a longer video, use the matching prepared video segment instead of the full source file.
Placeholder mode is smoke-test mode only. --allow-placeholder extracts passthrough audio and does not perform source separation, so SI-SDR from placeholder runs should not be treated as a real metric.
Use PowerShell in the project root:
cd C:\path\to\Final_Project
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip setuptools wheel packaging
python -m pip install -r requirements.txt
python -m pip install -r requirements-webui.txt
Use the CUDA 12.8 wheel index so Windows and Linux use the same CUDA wheel family:
python -m pip install torch==2.11.0 torchvision==0.26.0 torchaudio==2.11.0 --index-url https://download.pytorch.org/whl/cu128
python -m pip install torchcodec==0.11.1 --index-url https://download.pytorch.org/whl/cu128
Expected versions after install:
torch 2.11.0+cu128torchvision 0.26.0+cu128torchaudio 2.11.0+cu128torchcodec 0.11.1+cu12812.8If your GPU driver cannot run CUDA 12.8 wheels, update the NVIDIA driver or install a PyTorch wheel family that matches your driver.
If you already have a local sam2/ source folder, install it in editable mode:
cd sam2
python -m pip install -e .
cd ..
If you do not have sam2/ yet, clone or download SAM2 first, then run the install command above.
Use the project-local sam-audio/ source folder first on Windows. From the project root:
cd sam-audio
python -m pip install -e .
cd ..
Validate the import:
python -c "import sam_audio; import sam_audio.model.base as b; print('sam_audio ok:', b.__file__)"
If the local sam-audio/ install works and the pipeline runs, continue to the next section.
base.py, then installUse this fallback if any of these happen:
sam-audio/ is missingimport sam_audio failsBaseModel._from_pretrained() missing 2 required keyword-only arguments: 'proxies' and 'resume_download'The important order is clone first, patch base.py in the cloned repo, then install in editable mode.
cd C:\path\to\Final_Project
if (Test-Path sam-audio) {
Rename-Item sam-audio sam-audio-broken
}
git clone https://github.com/facebookresearch/sam-audio.git sam-audio
notepad sam-audio\sam_audio\model\base.py
In sam-audio\sam_audio\model\base.py, patch _from_pretrained() using the code in SAM-Audio base.py local model patch. Save the file, then install:
cd sam-audio
python -m pip install -e .
cd ..
python -c "import sam_audio; import sam_audio.model.base as b; print('sam_audio ok:', b.__file__)"
If installing SAM-Audio changes your already-correct TorchCodec install, reinstall TorchCodec from the same PyTorch index:
python -m pip install --force-reinstall torchcodec==0.11.1 --index-url https://download.pytorch.org/whl/cu128
The project checks in this order:
--ffmpeg-bin or UI overridetools/ffmpeg/windows/ffmpeg.exetools/ffmpeg/linux/ffmpegffmpegYou can either:
ffmpeg.exe in tools/ffmpeg/windows/ffmpeg.exe, orPATHRequired for real SAM-Audio inference and for downloading model assets. Paste your Hugging Face token only when prompted; do not put it in source files or commit it.
python -m pip install -U "huggingface_hub[cli]"
hf auth login
python -c "import cv2, numpy, scipy, pandas, PIL, matplotlib; print('base deps ok')"
python -c "import torch, torchvision, torchaudio, importlib.metadata as m; print('torch', torch.__version__); print('torchvision', torchvision.__version__); print('torchaudio', torchaudio.__version__); print('torchcodec', m.version('torchcodec')); print('cuda', torch.version.cuda)"
python -c "from torchcodec.decoders import AudioDecoder, VideoDecoder; print('torchcodec ok')"
python -c "import sam2; print('sam2 ok')"
python -c "import sam_audio; print('sam_audio ok')"
python -c "from path_layout import resolve_ffmpeg_binary; print(resolve_ffmpeg_binary())"
Linux setup uses a normal Python virtual environment. On shared Rutgers iLab machines, request a Slurm GPU allocation before running GPU jobs. For the full SAM2 + SAM-Audio pipeline, use a GPU with 40 GB VRAM or more when possible. Smaller 16 GB or 24 GB GPUs may work for short or segmented runs, but they are much more likely to hit CUDA out-of-memory errors on iLab.
On Rutgers iLab machines, a typical interactive GPU allocation is shown below. This requests one GPU and 40 GB of system RAM; VRAM depends on the GPU Slurm assigns, so prefer nodes with 40 GB+ GPUs such as A100-class machines when available.
srun -G 1 --mem=40g --pty bash
Then rebuild the environment from inside the project folder. This setup redirects pip, Hugging Face, PyTorch, and temp caches away from the default home cache locations, which helps avoid quota and temp-directory issues on shared systems.
cd /common/users/$USER/Final_Project
mkdir -p /common/users/$USER/pip-tmp
mkdir -p /common/users/$USER/pip-cache
mkdir -p /common/users/$USER/.cache
mkdir -p /common/users/$USER/hf-home
mkdir -p /common/users/$USER/torch-cache
export TMPDIR=/common/users/$USER/pip-tmp
export PIP_CACHE_DIR=/common/users/$USER/pip-cache
export XDG_CACHE_HOME=/common/users/$USER/.cache
export HF_HOME=/common/users/$USER/hf-home
export TORCH_HOME=/common/users/$USER/torch-cache
rm -rf ~/.cache/pip
rm -rf .venv
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip setuptools wheel packaging
python -m pip install --no-cache-dir -r requirements.txt
python -m pip install --no-cache-dir -r requirements-webui.txt
Install the known-working Linux CUDA 12.8 stack. Keeping PyTorch, TorchVision, TorchAudio, and TorchCodec on the same cu128 wheel family avoids TorchCodec import errors such as missing AudioDecoder.
python -m pip install --no-cache-dir --force-reinstall \
torch==2.11.0 torchvision==0.26.0 torchaudio==2.11.0 \
--index-url https://download.pytorch.org/whl/cu128
python -m pip install --no-cache-dir --force-reinstall \
torchcodec==0.11.1 \
--index-url https://download.pytorch.org/whl/cu128
Expected versions after install:
torch 2.11.0+cu128torchvision 0.26.0+cu128torchaudio 2.11.0+cu128torchcodec 0.11.1+cu12812.8Use --no-build-isolation so pip does not create a separate temporary build environment.
cd /common/users/$USER/sam2
python -m pip install --no-cache-dir --no-build-isolation -e .
If the SAM2 CUDA extension causes install trouble, disable the CUDA extension and reinstall:
SAM2_BUILD_CUDA=0 python -m pip install --no-cache-dir --no-build-isolation -e .
Return to the project root:
cd /common/users/$USER/Final_Project
Use the project-local sam-audio/ source folder first on Linux. From the project root:
cd /common/users/$USER/Final_Project/sam-audio
python -m pip install --no-cache-dir -e .
cd /common/users/$USER/Final_Project
Validate the import:
python -c "import sam_audio; import sam_audio.model.base as b; print('sam_audio ok:', b.__file__)"
If the local sam-audio/ install works and the pipeline runs, continue to Hugging Face login.
base.py, then installUse this fallback if any of these happen:
sam-audio/ is missingimport sam_audio failsBaseModel._from_pretrained() missing 2 required keyword-only arguments: 'proxies' and 'resume_download'The important order is clone first, patch base.py in the cloned repo, then install in editable mode.
cd /common/users/$USER/Final_Project
if [ -d sam-audio ]; then
mv sam-audio sam-audio-broken
fi
git clone https://github.com/facebookresearch/sam-audio.git sam-audio
nano sam-audio/sam_audio/model/base.py
In sam-audio/sam_audio/model/base.py, patch _from_pretrained() using the code in SAM-Audio base.py local model patch. Save the file, then install:
cd sam-audio
python -m pip install --no-cache-dir -e .
cd ..
python -c "import sam_audio; import sam_audio.model.base as b; print('sam_audio ok:', b.__file__)"
If installing SAM-Audio changes your already-correct TorchCodec install, reinstall TorchCodec from the same PyTorch index:
python -m pip install --no-cache-dir --force-reinstall \
torchcodec==0.11.1 \
--index-url https://download.pytorch.org/whl/cu128
Log into Hugging Face before real SAM-Audio inference. Paste the token only when prompted, and do not commit tokens to the repository.
python -m pip install -U "huggingface_hub[cli]"
hf auth login
python -c "import torch, torchvision, torchaudio, importlib.metadata as m; print('torch', torch.__version__); print('torchvision', torchvision.__version__); print('torchaudio', torchaudio.__version__); print('torchcodec', m.version('torchcodec')); print('cuda', torch.version.cuda)"
python -c "from torchcodec.decoders import AudioDecoder, VideoDecoder; print('torchcodec ok')"
python -c "import sam2; print('sam2 ok')"
python -c "import sam_audio; print('sam_audio ok')"
python -c "import torch; print('cuda available:', torch.cuda.is_available())"
python -c "from path_layout import resolve_ffmpeg_binary; print(resolve_ffmpeg_binary())"
streamlit run webui.py
For a non-iLab Linux machine, use the same venv-based install flow from the project root:
cd /path/to/Final_Project
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip setuptools wheel packaging
python -m pip install -r requirements.txt
python -m pip install -r requirements-webui.txt
python -m pip install torch==2.11.0 torchvision==0.26.0 torchaudio==2.11.0 --index-url https://download.pytorch.org/whl/cu128
python -m pip install torchcodec==0.11.1 --index-url https://download.pytorch.org/whl/cu128
Then install local source checkouts:
cd sam2
python -m pip install --no-build-isolation -e .
cd ..
cd sam-audio
python -m pip install -e .
cd ..
If the local SAM-Audio checkout does not work, use the same Linux fallback flow above: clean clone sam-audio/, patch sam-audio/sam_audio/model/base.py, then install with python -m pip install -e ..
Finish with Hugging Face login and the validation commands from the Linux section above.
This README is the single setup reference for SAM-Audio. The project expects the official sam_audio package for real visual-prompted audio separation, installed from the project-local sam-audio/ source folder when possible.
Required pieces:
torch, torchaudio, torchcodec, opencv-python, numpy, and ffmpegfrom sam_audio import SAMAudio, SAMAudioProcessor worksRecommended model ids when downloading from Hugging Face:
facebook/sam-audio-small-tvfacebook/sam-audio-base-tvfacebook/sam-audio-large-tvThe -tv variants are the recommended defaults for this project because the pipeline uses visual prompting from tracker masks.
For portable local runs, keep SAM-Audio models under sam_audio_models/ in the project root:
sam_audio_models/small-tv/sam_audio_models/base-tv/sam_audio_models/large-tv/When using a local model folder, the UI and CLI should point to relative model ids like:
sam_audio_models/small-tvsam_audio_models/base-tvKeep source checkouts at:
sam2/sam-audio/This keeps local imports predictable across Windows and Linux.
If SAM-Audio fails to load local model folders or raises an error like BaseModel._from_pretrained() missing 2 required keyword-only arguments: 'proxies' and 'resume_download', patch the active SAM-Audio source file.
Patch targets:
sam-audio\sam_audio\model\base.pysam-audio/sam_audio/model/base.pypython -c "import sam_audio.model.base as b; print(b.__file__)"When using the fallback flow, patch the freshly cloned source file before running python -m pip install -e ..
Inside class BaseModel, update _from_pretrained() so it accepts the newer Hugging Face arguments and uses local model folders directly when model_id is a directory:
@classmethod
def _from_pretrained(
cls,
*,
model_id: str,
cache_dir: Optional[str] = None,
force_download: bool = False,
proxies: Optional[Dict] = None,
resume_download: bool = False,
local_files_only: bool = False,
token: Union[str, bool, None] = None,
map_location: str = "cpu",
strict: bool = True,
revision: Optional[str] = None,
**model_kwargs,
):
if os.path.isdir(model_id):
cached_model_dir = model_id
else:
cached_model_dir = snapshot_download(
repo_id=model_id,
revision=revision or getattr(cls, "revision", None),
cache_dir=cache_dir,
force_download=force_download,
token=token,
local_files_only=local_files_only,
)
Keep the rest of the function that reads config.json, loads checkpoint.pt, and calls model.load_state_dict(...).
Make sure the file already imports the names used above. If it does not, add these near the top of base.py:
import os
from typing import Dict, Optional, Union
from huggingface_hub import snapshot_download
Use spaces only for indentation. Mixing tabs and spaces can cause TabError on Linux.
After patching and installing, validate the import:
python -c "import sam_audio; import sam_audio.model.base as b; print('sam_audio ok:', b.__file__)"
Copy these if you want to avoid re-downloading large assets:
checkpoints/configs/sam_audio_models/input/tools/ffmpeg/output/sam2/sam-audio/Do not copy:
.venv/From an activated virtual environment:
streamlit run webui.py
Open the local URL that Streamlit prints in the terminal.
Interactive point selection example on Windows:
python tracker.py input\test1_TomScott.mp4 output\terminal_runs\tracker_test1\video\tracked.mp4 --checkpoint checkpoints\sam2.1_hiera_tiny.pt --config configs\sam2.1\sam2.1_hiera_t.yaml --frames-dir output\terminal_runs\tracker_test1\frames --artifacts-dir output\terminal_runs\tracker_test1\artifacts --mode point --preview
Linux equivalent:
python tracker.py input/test1_TomScott.mp4 output/terminal_runs/tracker_test1/video/tracked.mp4 --checkpoint checkpoints/sam2.1_hiera_tiny.pt --config configs/sam2.1/sam2.1_hiera_t.yaml --frames-dir output/terminal_runs/tracker_test1/frames --artifacts-dir output/terminal_runs/tracker_test1/artifacts --mode point --preview
Use tracker masks plus the matching video segment.
Windows:
python audio_pipeline.py --video-path input\test1_TomScott.mp4 --mask-path output\terminal_runs\tracker_test1\artifacts\masks\masks.npz --output-dir output\terminal_runs\audio_test1 --clip-id test1_TomScott --model-id sam_audio_models\small-tv --predict-spans --reranking-candidates 1
Linux:
python audio_pipeline.py --video-path input/test1_TomScott.mp4 --mask-path output/terminal_runs/tracker_test1/artifacts/masks/masks.npz --output-dir output/terminal_runs/audio_test1 --clip-id test1_TomScott --model-id sam_audio_models/small-tv --predict-spans --reranking-candidates 1
If you have clean reference audio and/or ground-truth masks, run evaluation.
Windows:
python evaluation.py --output-dir output\eval_test1 --clip-id test1_TomScott --model-id sam_audio_models\small-tv --predicted-mask-path output\terminal_runs\tracker_test1\artifacts\masks\masks.npz --estimated-audio-path output\terminal_runs\audio_test1\target.wav --reference-audio-path input\reference.wav --ground-truth-mask-path input\gt_masks.npz --audio-metadata-path output\terminal_runs\audio_test1\audio_run_metadata.json
Linux:
python evaluation.py --output-dir output/eval_test1 --clip-id test1_TomScott --model-id sam_audio_models/small-tv --predicted-mask-path output/terminal_runs/tracker_test1/artifacts/masks/masks.npz --estimated-audio-path output/terminal_runs/audio_test1/target.wav --reference-audio-path input/reference.wav --ground-truth-mask-path input/gt_masks.npz --audio-metadata-path output/terminal_runs/audio_test1/audio_run_metadata.json
Windows:
python analyze_results.py output\ui_runs\SOME_JOB_ID\runs --output-dir output\analysis_test1
Linux:
python analyze_results.py output/ui_runs/SOME_JOB_ID/runs --output-dir output/analysis_test1
Reference audio: used for SI-SDRGround-truth masks: used for IoUIf those are missing, evaluation still runs, but the corresponding metrics are skipped.
35 commits
Jupyter Notebook
97.2%
Python
2.8%
Local pipeline for:
input/: input videos and optional evaluation filesoutput/: generated tracker, audio, eval, analysis, and UI run artifactscheckpoints/: SAM2 checkpointsconfigs/: SAM2 configssam_audio_models/: local SAM-Audio model folderssam2/: optional project-local SAM2 source checkoutsam-audio/: optional project-local SAM-Audio source checkouttools/ffmpeg/: optional repo-local ffmpeg binaries for Windows and LinuxThis folder is intended for large project assets such as SAM-Audio model folders and saved run outputs. Hugging Face authentication token
.venv between Windows and Linux..venv on that machine.cu128 wheels.cu124, cu126, cu128, and CUDA 13 wheels in the same .venv.sam_audio_models/small-tv/checkpoint.ptsam_audio_models/small-tv/config.jsonsam_audio_models/base-tv/checkpoint.ptsam_audio_models/base-tv/config.jsonsam_audio_models/large-tv/checkpoint.ptsam_audio_models/large-tv/config.jsoncheckpoints/sam2.1_hiera_tiny.ptconfigs/sam2.1/sam2.1_hiera_t.yamldataset_prep.py when needed.tracker.py.audio_pipeline.py --video-path ... --mask-path ....evaluation.py.analyze_results.py.Important alignment rule: audio_pipeline.py expects the supplied --video-path to match the tracker mask stack exactly in frame count, frame resolution, and clip segment. If tracking ran on only part of a longer video, use the matching prepared video segment instead of the full source file.
Placeholder mode is smoke-test mode only. --allow-placeholder extracts passthrough audio and does not perform source separation, so SI-SDR from placeholder runs should not be treated as a real metric.
Use PowerShell in the project root:
cd C:\path\to\Final_Project
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip setuptools wheel packaging
python -m pip install -r requirements.txt
python -m pip install -r requirements-webui.txt
Use the CUDA 12.8 wheel index so Windows and Linux use the same CUDA wheel family:
python -m pip install torch==2.11.0 torchvision==0.26.0 torchaudio==2.11.0 --index-url https://download.pytorch.org/whl/cu128
python -m pip install torchcodec==0.11.1 --index-url https://download.pytorch.org/whl/cu128
Expected versions after install:
torch 2.11.0+cu128torchvision 0.26.0+cu128torchaudio 2.11.0+cu128torchcodec 0.11.1+cu12812.8If your GPU driver cannot run CUDA 12.8 wheels, update the NVIDIA driver or install a PyTorch wheel family that matches your driver.
If you already have a local sam2/ source folder, install it in editable mode:
cd sam2
python -m pip install -e .
cd ..
If you do not have sam2/ yet, clone or download SAM2 first, then run the install command above.
Use the project-local sam-audio/ source folder first on Windows. From the project root:
cd sam-audio
python -m pip install -e .
cd ..
Validate the import:
python -c "import sam_audio; import sam_audio.model.base as b; print('sam_audio ok:', b.__file__)"
If the local sam-audio/ install works and the pipeline runs, continue to the next section.
base.py, then installUse this fallback if any of these happen:
sam-audio/ is missingimport sam_audio failsBaseModel._from_pretrained() missing 2 required keyword-only arguments: 'proxies' and 'resume_download'The important order is clone first, patch base.py in the cloned repo, then install in editable mode.
cd C:\path\to\Final_Project
if (Test-Path sam-audio) {
Rename-Item sam-audio sam-audio-broken
}
git clone https://github.com/facebookresearch/sam-audio.git sam-audio
notepad sam-audio\sam_audio\model\base.py
In sam-audio\sam_audio\model\base.py, patch _from_pretrained() using the code in SAM-Audio base.py local model patch. Save the file, then install:
cd sam-audio
python -m pip install -e .
cd ..
python -c "import sam_audio; import sam_audio.model.base as b; print('sam_audio ok:', b.__file__)"
If installing SAM-Audio changes your already-correct TorchCodec install, reinstall TorchCodec from the same PyTorch index:
python -m pip install --force-reinstall torchcodec==0.11.1 --index-url https://download.pytorch.org/whl/cu128
The project checks in this order:
--ffmpeg-bin or UI overridetools/ffmpeg/windows/ffmpeg.exetools/ffmpeg/linux/ffmpegffmpegYou can either:
ffmpeg.exe in tools/ffmpeg/windows/ffmpeg.exe, orPATHRequired for real SAM-Audio inference and for downloading model assets. Paste your Hugging Face token only when prompted; do not put it in source files or commit it.
python -m pip install -U "huggingface_hub[cli]"
hf auth login
python -c "import cv2, numpy, scipy, pandas, PIL, matplotlib; print('base deps ok')"
python -c "import torch, torchvision, torchaudio, importlib.metadata as m; print('torch', torch.__version__); print('torchvision', torchvision.__version__); print('torchaudio', torchaudio.__version__); print('torchcodec', m.version('torchcodec')); print('cuda', torch.version.cuda)"
python -c "from torchcodec.decoders import AudioDecoder, VideoDecoder; print('torchcodec ok')"
python -c "import sam2; print('sam2 ok')"
python -c "import sam_audio; print('sam_audio ok')"
python -c "from path_layout import resolve_ffmpeg_binary; print(resolve_ffmpeg_binary())"
Linux setup uses a normal Python virtual environment. On shared Rutgers iLab machines, request a Slurm GPU allocation before running GPU jobs. For the full SAM2 + SAM-Audio pipeline, use a GPU with 40 GB VRAM or more when possible. Smaller 16 GB or 24 GB GPUs may work for short or segmented runs, but they are much more likely to hit CUDA out-of-memory errors on iLab.
On Rutgers iLab machines, a typical interactive GPU allocation is shown below. This requests one GPU and 40 GB of system RAM; VRAM depends on the GPU Slurm assigns, so prefer nodes with 40 GB+ GPUs such as A100-class machines when available.
srun -G 1 --mem=40g --pty bash
Then rebuild the environment from inside the project folder. This setup redirects pip, Hugging Face, PyTorch, and temp caches away from the default home cache locations, which helps avoid quota and temp-directory issues on shared systems.
cd /common/users/$USER/Final_Project
mkdir -p /common/users/$USER/pip-tmp
mkdir -p /common/users/$USER/pip-cache
mkdir -p /common/users/$USER/.cache
mkdir -p /common/users/$USER/hf-home
mkdir -p /common/users/$USER/torch-cache
export TMPDIR=/common/users/$USER/pip-tmp
export PIP_CACHE_DIR=/common/users/$USER/pip-cache
export XDG_CACHE_HOME=/common/users/$USER/.cache
export HF_HOME=/common/users/$USER/hf-home
export TORCH_HOME=/common/users/$USER/torch-cache
rm -rf ~/.cache/pip
rm -rf .venv
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip setuptools wheel packaging
python -m pip install --no-cache-dir -r requirements.txt
python -m pip install --no-cache-dir -r requirements-webui.txt
Install the known-working Linux CUDA 12.8 stack. Keeping PyTorch, TorchVision, TorchAudio, and TorchCodec on the same cu128 wheel family avoids TorchCodec import errors such as missing AudioDecoder.
python -m pip install --no-cache-dir --force-reinstall \
torch==2.11.0 torchvision==0.26.0 torchaudio==2.11.0 \
--index-url https://download.pytorch.org/whl/cu128
python -m pip install --no-cache-dir --force-reinstall \
torchcodec==0.11.1 \
--index-url https://download.pytorch.org/whl/cu128
Expected versions after install:
torch 2.11.0+cu128torchvision 0.26.0+cu128torchaudio 2.11.0+cu128torchcodec 0.11.1+cu12812.8Use --no-build-isolation so pip does not create a separate temporary build environment.
cd /common/users/$USER/sam2
python -m pip install --no-cache-dir --no-build-isolation -e .
If the SAM2 CUDA extension causes install trouble, disable the CUDA extension and reinstall:
SAM2_BUILD_CUDA=0 python -m pip install --no-cache-dir --no-build-isolation -e .
Return to the project root:
cd /common/users/$USER/Final_Project
Use the project-local sam-audio/ source folder first on Linux. From the project root:
cd /common/users/$USER/Final_Project/sam-audio
python -m pip install --no-cache-dir -e .
cd /common/users/$USER/Final_Project
Validate the import:
python -c "import sam_audio; import sam_audio.model.base as b; print('sam_audio ok:', b.__file__)"
If the local sam-audio/ install works and the pipeline runs, continue to Hugging Face login.
base.py, then installUse this fallback if any of these happen:
sam-audio/ is missingimport sam_audio failsBaseModel._from_pretrained() missing 2 required keyword-only arguments: 'proxies' and 'resume_download'The important order is clone first, patch base.py in the cloned repo, then install in editable mode.
cd /common/users/$USER/Final_Project
if [ -d sam-audio ]; then
mv sam-audio sam-audio-broken
fi
git clone https://github.com/facebookresearch/sam-audio.git sam-audio
nano sam-audio/sam_audio/model/base.py
In sam-audio/sam_audio/model/base.py, patch _from_pretrained() using the code in SAM-Audio base.py local model patch. Save the file, then install:
cd sam-audio
python -m pip install --no-cache-dir -e .
cd ..
python -c "import sam_audio; import sam_audio.model.base as b; print('sam_audio ok:', b.__file__)"
If installing SAM-Audio changes your already-correct TorchCodec install, reinstall TorchCodec from the same PyTorch index:
python -m pip install --no-cache-dir --force-reinstall \
torchcodec==0.11.1 \
--index-url https://download.pytorch.org/whl/cu128
Log into Hugging Face before real SAM-Audio inference. Paste the token only when prompted, and do not commit tokens to the repository.
python -m pip install -U "huggingface_hub[cli]"
hf auth login
python -c "import torch, torchvision, torchaudio, importlib.metadata as m; print('torch', torch.__version__); print('torchvision', torchvision.__version__); print('torchaudio', torchaudio.__version__); print('torchcodec', m.version('torchcodec')); print('cuda', torch.version.cuda)"
python -c "from torchcodec.decoders import AudioDecoder, VideoDecoder; print('torchcodec ok')"
python -c "import sam2; print('sam2 ok')"
python -c "import sam_audio; print('sam_audio ok')"
python -c "import torch; print('cuda available:', torch.cuda.is_available())"
python -c "from path_layout import resolve_ffmpeg_binary; print(resolve_ffmpeg_binary())"
streamlit run webui.py
For a non-iLab Linux machine, use the same venv-based install flow from the project root:
cd /path/to/Final_Project
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip setuptools wheel packaging
python -m pip install -r requirements.txt
python -m pip install -r requirements-webui.txt
python -m pip install torch==2.11.0 torchvision==0.26.0 torchaudio==2.11.0 --index-url https://download.pytorch.org/whl/cu128
python -m pip install torchcodec==0.11.1 --index-url https://download.pytorch.org/whl/cu128
Then install local source checkouts:
cd sam2
python -m pip install --no-build-isolation -e .
cd ..
cd sam-audio
python -m pip install -e .
cd ..
If the local SAM-Audio checkout does not work, use the same Linux fallback flow above: clean clone sam-audio/, patch sam-audio/sam_audio/model/base.py, then install with python -m pip install -e ..
Finish with Hugging Face login and the validation commands from the Linux section above.
This README is the single setup reference for SAM-Audio. The project expects the official sam_audio package for real visual-prompted audio separation, installed from the project-local sam-audio/ source folder when possible.
Required pieces:
torch, torchaudio, torchcodec, opencv-python, numpy, and ffmpegfrom sam_audio import SAMAudio, SAMAudioProcessor worksRecommended model ids when downloading from Hugging Face:
facebook/sam-audio-small-tvfacebook/sam-audio-base-tvfacebook/sam-audio-large-tvThe -tv variants are the recommended defaults for this project because the pipeline uses visual prompting from tracker masks.
For portable local runs, keep SAM-Audio models under sam_audio_models/ in the project root:
sam_audio_models/small-tv/sam_audio_models/base-tv/sam_audio_models/large-tv/When using a local model folder, the UI and CLI should point to relative model ids like:
sam_audio_models/small-tvsam_audio_models/base-tvKeep source checkouts at:
sam2/sam-audio/This keeps local imports predictable across Windows and Linux.
If SAM-Audio fails to load local model folders or raises an error like BaseModel._from_pretrained() missing 2 required keyword-only arguments: 'proxies' and 'resume_download', patch the active SAM-Audio source file.
Patch targets:
sam-audio\sam_audio\model\base.pysam-audio/sam_audio/model/base.pypython -c "import sam_audio.model.base as b; print(b.__file__)"When using the fallback flow, patch the freshly cloned source file before running python -m pip install -e ..
Inside class BaseModel, update _from_pretrained() so it accepts the newer Hugging Face arguments and uses local model folders directly when model_id is a directory:
@classmethod
def _from_pretrained(
cls,
*,
model_id: str,
cache_dir: Optional[str] = None,
force_download: bool = False,
proxies: Optional[Dict] = None,
resume_download: bool = False,
local_files_only: bool = False,
token: Union[str, bool, None] = None,
map_location: str = "cpu",
strict: bool = True,
revision: Optional[str] = None,
**model_kwargs,
):
if os.path.isdir(model_id):
cached_model_dir = model_id
else:
cached_model_dir = snapshot_download(
repo_id=model_id,
revision=revision or getattr(cls, "revision", None),
cache_dir=cache_dir,
force_download=force_download,
token=token,
local_files_only=local_files_only,
)
Keep the rest of the function that reads config.json, loads checkpoint.pt, and calls model.load_state_dict(...).
Make sure the file already imports the names used above. If it does not, add these near the top of base.py:
import os
from typing import Dict, Optional, Union
from huggingface_hub import snapshot_download
Use spaces only for indentation. Mixing tabs and spaces can cause TabError on Linux.
After patching and installing, validate the import:
python -c "import sam_audio; import sam_audio.model.base as b; print('sam_audio ok:', b.__file__)"
Copy these if you want to avoid re-downloading large assets:
checkpoints/configs/sam_audio_models/input/tools/ffmpeg/output/sam2/sam-audio/Do not copy:
.venv/From an activated virtual environment:
streamlit run webui.py
Open the local URL that Streamlit prints in the terminal.
Interactive point selection example on Windows:
python tracker.py input\test1_TomScott.mp4 output\terminal_runs\tracker_test1\video\tracked.mp4 --checkpoint checkpoints\sam2.1_hiera_tiny.pt --config configs\sam2.1\sam2.1_hiera_t.yaml --frames-dir output\terminal_runs\tracker_test1\frames --artifacts-dir output\terminal_runs\tracker_test1\artifacts --mode point --preview
Linux equivalent:
python tracker.py input/test1_TomScott.mp4 output/terminal_runs/tracker_test1/video/tracked.mp4 --checkpoint checkpoints/sam2.1_hiera_tiny.pt --config configs/sam2.1/sam2.1_hiera_t.yaml --frames-dir output/terminal_runs/tracker_test1/frames --artifacts-dir output/terminal_runs/tracker_test1/artifacts --mode point --preview
Use tracker masks plus the matching video segment.
Windows:
python audio_pipeline.py --video-path input\test1_TomScott.mp4 --mask-path output\terminal_runs\tracker_test1\artifacts\masks\masks.npz --output-dir output\terminal_runs\audio_test1 --clip-id test1_TomScott --model-id sam_audio_models\small-tv --predict-spans --reranking-candidates 1
Linux:
python audio_pipeline.py --video-path input/test1_TomScott.mp4 --mask-path output/terminal_runs/tracker_test1/artifacts/masks/masks.npz --output-dir output/terminal_runs/audio_test1 --clip-id test1_TomScott --model-id sam_audio_models/small-tv --predict-spans --reranking-candidates 1
If you have clean reference audio and/or ground-truth masks, run evaluation.
Windows:
python evaluation.py --output-dir output\eval_test1 --clip-id test1_TomScott --model-id sam_audio_models\small-tv --predicted-mask-path output\terminal_runs\tracker_test1\artifacts\masks\masks.npz --estimated-audio-path output\terminal_runs\audio_test1\target.wav --reference-audio-path input\reference.wav --ground-truth-mask-path input\gt_masks.npz --audio-metadata-path output\terminal_runs\audio_test1\audio_run_metadata.json
Linux:
python evaluation.py --output-dir output/eval_test1 --clip-id test1_TomScott --model-id sam_audio_models/small-tv --predicted-mask-path output/terminal_runs/tracker_test1/artifacts/masks/masks.npz --estimated-audio-path output/terminal_runs/audio_test1/target.wav --reference-audio-path input/reference.wav --ground-truth-mask-path input/gt_masks.npz --audio-metadata-path output/terminal_runs/audio_test1/audio_run_metadata.json
Windows:
python analyze_results.py output\ui_runs\SOME_JOB_ID\runs --output-dir output\analysis_test1
Linux:
python analyze_results.py output/ui_runs/SOME_JOB_ID/runs --output-dir output/analysis_test1
Reference audio: used for SI-SDRGround-truth masks: used for IoUIf those are missing, evaluation still runs, but the corresponding metrics are skipped.
35 commits
Jupyter Notebook
97.2%
Python
2.8%