Search

260314_1943_배경제거라이브러리 설치부터 활용방법 까지 (rembg)

rembg
danielgatis

removebg (rembg)

이미지 배경 제거 도구 rembg 로컬 빌드/설치 가이드.

요구사항

Python 3.11 이상 (3.13 권장)
pip

설치 (빌드 및 개발 모드)

CLI(rembg i ... 등)를 쓰려면 반드시 [cli] 포함해서 설치해야 합니다.
.[cpu]만 쓰면 filetype 등이 없어 rembg 명령 실행 시 에러가 납니다.
cd rembg pip install -e ".[cpu]" # 라이브러리만 (CPU) — CLI 사용 불가 pip install -e ".[cpu,cli]" # 라이브러리 + CLI (CPU) ← CLI 쓸 때 권장
Bash
복사
GPU 사용 시:
pip install -e ".[gpu]" # NVIDIA CUDA pip install -e ".[gpu,cli]"
Bash
복사
GPU를 쓰려면 CPU용 onnxruntime을 제거해야 합니다.
두 패키지가 같이 있으면 import onnxruntime 시 CPU용이 먼저 로드되어 GPU가 안 씁니다.
pip uninstall onnxruntime -y # CPU용 제거 pip install onnxruntime-gpu # GPU용만 유지 (이미 설치됐으면 생략)
Bash
복사
GPU 인식 확인:
python -c "import onnxruntime as ort; print('providers:', ort.get_available_providers()); print('device:', ort.get_device())" # CUDA 쓸 때: providers에 CUDAExecutionProvider, device: GPU 나와야 함
Bash
복사
libcublasLt.so.12: cannot open shared object file 에러가 나는 경우
pip의 onnxruntime-gpuCUDA 12용으로 빌드되어 있습니다. 시스템에 CUDA 13만 있으면 이 에러가 납니다.
당장 쓰려면 CPU로 돌리기: pip uninstall onnxruntime-gpu -ypip install onnxruntime 하면 rembg는 CPU로 동작합니다.
→ GPU를 쓰려면 CUDA 12를 별도 설치하거나, CUDA 13 지원 onnxruntime 빌드가 나올 때까지 CPU를 쓰면 됩니다.

설치 확인

rembg --help python -c "from rembg import remove; print('OK')"
Bash
복사

사용 예

rembg i input.png output.png
Bash
복사
from rembg import remove from PIL import Image im = Image.open('input.png') out = remove(im) out.save('output.png')
Python
복사

참고

NumPy: pymatting(→ numba)이 NumPy 2.3 이하만 지원합니다. numpy>=2.4Numba needs NumPy 2.3 or less 에러가 나므로 pip install "numpy>=2.3,<2.4" 로 맞추면 됩니다.
버전은 Git 태그 기준으로 poetry-dynamic-versioning이 자동 부여합니다.
빌드만 하려면: pip install build && python -m build (wheel/sdist 생성).

안녕하세요

관련 기술 문의와 R&D 공동 연구 사업 관련 문의는 “glory@keti.re.kr”로 연락 부탁드립니다.

Hello

For technical and business inquiries, please contact me at “glory@keti.re.kr”