Matting Anythingをgoogle colabで試してみた
Matting Anythingとは
Matting AnythingとはSegmentationとInpaintingを両立させたAnything modelです。
リンク
準備
Google Colabを開き、メニューから「ランタイム→ランタイムのタイプを変更」でランタイムを「GPU」に変更します。
環境構築
インストール手順です。
!git clone https://github.com/SHI-Labs/Matting-Anything
%cd Matting-Anything
# Install all dependencies
!pip install -r requirements.txt
# Install segment-anything
!python -m pip install -e segment-anything
# Install Grounding DINO
!export BUILD_WITH_CUDA=True
!export CUDA_HOME=/usr/local/cuda/
!python -m pip install -e GroundingDINO
#Install diffusers
!pip install --upgrade diffusers[torch]
推論
(1)モデルのダウンロード
# Download GroundingDINO model
!wget https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth -P /content/Matting-Anything/checkpoints
# Download MAM model
%cd /content/Matting-Anything/checkpoints
import gdown
url = "https://drive.google.com/file/d/1GNjlD5A7gN3UZTtzqev5W21w4y21nO8f/view?usp=sharing"
gdown.download(url=url, output="mam_sam_vitb.pth", quiet=False, fuzzy=True)
(2)WebUIの起動
%cd /content/Matting-Anything
!python gradio_app.py --share
とりあえず以下の画像をぶち込みます。これはRealistic Visionで作成したやつ。

結果画像


おおーいい感じ
僕の好きなポケモンをやってみましたが

結果


いい感じにアルファブレンドww
流石にAnythingじゃなかったみたい。
最後に
今回はMatting AnythingというSegmentationとInpaintingを両立できるAnything modelを試してみました。組み合わせるといろんなAnything modelができる。いい世界です。
今後ともLLM, Diffusion model, Image Analysis, 3Dに関連する試した記事を投稿していく予定なのでよろしくお願いします。