CivArchive
    ← All articles
    Published March 6, 2025by huggy

    RMBG 1.4 and RMBG 2.0: Installation Guide

    303 views0 reactions0 comments on CivitAI0 collected
    data prep

    Shared Requirements (Both Models):

    Python: Both models work with Python 3.9.21 (MacOS)

    • ImageMagick: Required for pre-processing (resizing and canvas extension) in the Bash script. Install via Homebrew: brew install imagemagick.

    • macOS Quick Actions with Full Disk Access to Finder: Crucial for the scripts to function correctly. Go to System Settings > Privacy & Security > Full Disk Access and add Finder.

    I. Dependencies for RMBG-1.4:

    These are the only dependencies needed for RMBG-1.4.

    • torch: 2.2.2

    • torchvision: 0.17.2

    • Pillow: 11.1.0 (or later, Pillow is quite backward-compatible)

    • numpy: 1.23.5

    • typing_extensions: 4.12.2 (or latest)

    • transformers: >=4.39.1 (newer versions are generally recommended)

    • huggingface_hub: (install the latest version)

    • scikit-image: (install the latest version)

    II. Dependencies for RMBG-2.0:

    These include all the dependencies from RMBG-1.4, plus two additional packages.

    • torch: 2.2.2

    • torchvision: 0.17.2

    • Pillow: 11.1.0 (or later)

    • numpy: 1.23.5

    • typing_extensions: 4.12.2 (or latest)

    • transformers: >=4.39.1 (newer versions are generally recommended)

    • huggingface_hub: (install the latest version)

    • scikit-image: (install the latest version)

    • timm: (install the latest version)  <-- RMBG-2.0 specific

    • kornia: (install the latest version)  <-- RMBG-2.0 specific

    III. Installation Commands (using pip):

    A. For a new RMBG-1.4 environment:

          python3 -m venv rmbg14_env  # Create environment (choose your name)
    source rmbg14_env/bin/activate  # Activate
    pip install torch==2.2.2 torchvision==0.17.2 Pillow numpy typing_extensions transformers huggingface_hub scikit-image
        

    B. For a new RMBG-2.0 environment:

          python3 -m venv rmbg2_env  # Create environment (choose your name)
    source rmbg2_env/bin/activate  # Activate
    pip install torch==2.2.2 torchvision==0.17.2 Pillow numpy typing_extensions transformers huggingface_hub scikit-image timm kornia
        

    C. Adding RMBG-2.0 support to an existing RMBG-1.4 environment:
    Only do this if use existing rmbg 1.4 env

          source /path/to/your/existing/env/bin/activate  # Activate existing env
    pip install timm kornia
        

    IV. In your Quick Action Bash scripts, you need to configure these two crucial paths:

    • PYTHON_PATH: The path to the Python executable within the appropriate virtual environment.

      • For RMBG-1.4 (using sec_env): /Users/mbp/Documents/sec_env/bin/python

      • For RMBG-2.0 (using sec_env): /Users/mbp/Documents/sec_env/bin/python

    • LOCAL_MODEL_DIR: The path to the directory containing the downloaded model files.

      • For RMBG-1.4: /Users/mbp/Documents/models/rmbg/models--briaai--RMBG-1.4

      • For RMBG-2.0: /Users/mbp/Documents/models/rmbg/models--briaai--RMBG-2.0

    V. Key Points and Clarifications:

    • Shared Versions: The core library versions (torch, torchvision, Pillow, numpy, typing_extensions, transformers, huggingface_hub, scikit-image) are the same for both models, based on our testing and the requirements of the transformers library. This simplifies things if you want to use the same versions.

    • timm and kornia: These are only needed for RMBG-2.0. RMBG-1.4 does not require them.

    • Latest Versions: For packages where a specific version isn't critical (like huggingface_hub, timm, kornia, scikit-image), it's generally fine to install the latest version using pip install <package_name>.

    • Virtual Environments: Using separate virtual environments for each model (or at least for RMBG-2.0) is highly recommended for best practice, even though sharing an environment can work.

    • Pillow: pillow is a friendly fork of PIL, so technically it's not "PIL" anymore, it should be "Pillow".