金子邦彦研究室人工知能Windows で動く人工知能関係 Pythonアプリケーション,オープンソースソフトウエア)FastSAM のインストールと動作確認(セグメンテーション)(PyTorch を使用)(Windows 上)

FastSAM のインストールと動作確認(セグメンテーション)(PyTorch を使用)(Windows 上)

前準備

Git のインストール(Windows 上)

Gitは,バージョン管理システム.ソースコードの管理や複数人での共同に役立つ.

サイト内の関連ページ

Windows での Git のインストール: 別ページ »で説明している.

関連する外部ページ

Git の公式ページ: https://git-scm.com/

Python のインストール(Windows 上)

サイト内の関連ページ

関連する外部ページ

Python の公式ページ: https://www.python.org/

Build Tools for Visual Studio 2022,NVIDIA ドライバ,NVIDIA CUDA ツールキット 11.8,NVIDIA cuDNN 8.6 のインストール(Windows 上)

サイト内の関連ページ

NVIDIA グラフィックスボードを搭載しているパソコンの場合には, NVIDIA ドライバNVIDIA CUDA ツールキットNVIDIA cuDNN のインストールを行う.

関連する外部ページ

PyTorch のインストール(Windows 上)

  1. Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  2. PyTorch のページを確認

    PyTorch のページ: https://pytorch.org/index.html

  3. 次のようなコマンドを実行(実行するコマンドは,PyTorch のページの表示されるコマンドを使う).

    次のコマンドは, PyTorch 2.0 (NVIDIA CUDA 11.8 用) をインストールする. 但し,Anaconda3を使いたい場合には別手順になる.

    事前に NVIDIA CUDA のバージョンを確認しておくこと(ここでは,NVIDIA CUDA ツールキット 11.8 が前もってインストール済みであるとする).

    PyTorch で,GPU が動作している場合には,「torch.cuda.is_available()」により,True が表示される.

    python -m pip install -U --ignore-installed pip
    python -m pip install -U torch torchvision torchaudio numpy --index-url https://download.pytorch.org/whl/cu118
    python -c "import torch; print(torch.__version__, torch.cuda.is_available())" 
    

    [image]

    Anaconda3を使いたい場合には, Anaconda プロンプト (Anaconda Prompt)管理者として実行し, 次のコマンドを実行する. (PyTorch と NVIDIA CUDA との連携がうまくいかない可能性があるため,Anaconda3を使わないことも検討して欲しい).

    conda install -y pytorch torchvision torchaudio pytorch-cuda=11.8 cudnn -c pytorch -c nvidia
    py -c "import torch; print(torch.__version__, torch.cuda.is_available())" 
    

    サイト内の関連ページ

    関連する外部ページ

Fast SAM のインストール(Windows 上)

  1. Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  2. ダウンロードとインストール

    python -m pip install git+https://github.com/openai/CLIP.git
    cd %HOMEPATH%
    rmdir /s /q FastSAM
    git clone --recursive -b spliting_model https://github.com/CASIA-IVA-Lab/FastSAM.git
    cd FastSAM
    python -m pip install -r requirements.txt
    mkdir weights
    
  3. 学習済みモデル

    https://github.com/CASIA-IVA-Lab/FastSAM#model-checkpoints から FastSAM-x.pt を ダウンロードし,weight の下に置く

    [image]

Fast SAM の動作確認(Windows 上)

公式ページ https://github.com/CASIA-IVA-Lab/FastSAM の記載に従い,デモを実行.

  1. 次のコマンドを実行

    Everything モードの実行

    cd %HOMEPATH%\FastSAM
    del output\dogs.jpg
    python Inference.py --model_path ./weights/FastSAM-x.pt --img_path ./images/dogs.jpg
    output\dogs.jpg
    

    [image]
  2. 次のコマンドを実行

    プロンプトを指定して実行

    プロンプトは英語で指定すること.

    cd %HOMEPATH%\FastSAM
    del output\dogs.jpg
    python Inference.py --model_path ./weights/FastSAM-x.pt --img_path ./images/dogs.jpg  --text_prompt "the yellow dog"
    output\dogs.jpg
    

    [image]