金子邦彦研究室人工知能Windows でのインストールと動作確認(人工知能関係)MMEditing のインストールと動作確認(超解像,画像のノイズ除去,イメージ・インペインティング,イメージ・マッティング)(PyTorch,Python を使用)(Windows 上)

MMEditing のインストールと動作確認(超解像,画像のノイズ除去,イメージ・インペインティング,イメージ・マッティング)(PyTorch,Python を使用)(Windows 上)

MMEditing は, OpenMMLab の構成物で, イメージ・インペインティング(image inpainting),画像のノイズ除去 (画像のノイズ除去 (image restoration)), イメージ・マッティング (image matting), 超解像 (super resolution), 画像生成の機能を持つ.

【目次】

  1. 前準備
  2. MMEditing のインストール(Windows 上)
  3. MMEditing の動作確認(Windows 上)

前準備

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

Windows での Git のインストール: 別ページ »で説明

関連する外部ページ

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

7-Zip のインストール(Windows 上)

Windows での 7-Zip のインストール: 別ページ »で説明

関連する外部ページ

7-Zip の公式ページ: https://sevenzip.osdn.jp/

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

Windows での Python 3.10,関連パッケージ,Python 開発環境のインストール: 別ページ »で説明

サイト内の関連ページ

Python のまとめ: 別ページ »にまとめ

関連する外部ページ

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

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

Windows での Build Tools for Visual Studio 2022NVIDIA ドライバNVIDIA CUDA ツールキット 11.8,NVIDIA cuDNN v8.6 のインストールと動作確認: 別ページ »で説明

関連する外部ページ

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

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

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

  2. PyTorch のページを確認

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

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

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

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

    (途中省略)
    [image]

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

インストールの方法は複数ある. ここでは, NVIDIA CUDA ツールキットを使うことも考え, インストールしやすい方法として,ソースコードからビルドしてインストールする方法を案内している.

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

MMCV のインストールを行う.

インストールの方法は複数ある. ここでは, NVIDIA CUDA ツールキットを使うことも考え, インストールしやすい方法として,ソースコードからビルドしてインストールする方法を案内している.

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

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

  2. PyTorch がインストールできていることを確認するために,PyTorch のバージョンを表示
    python -c "import torch; TORCH_VERSION = '.'.join(torch.__version__.split('.')[:2]); print(TORCH_VERSION)"
    

    [image]
  3. PyTorch が NVIDIA CUDA ツールキットを認識できていることを確認するために, PyTorch が認識しているNVIDIA CUDA ツールキット のバージョンを表示

    このとき,実際には 11.8 をインストールしているのに,「cu117」のように古いバージョンが表示されることがある.このような場合は,気にせずに続行する.

    python -c "import torch; CUDA_VERSION = torch.__version__.split('+')[-1]; print(CUDA_VERSION)"
    

    [image]
  4. MMCV 1.6.2 のインストール

    MMTracking が MMCV 1.6.2 に依存している (2022/12). MMTracking を利用するので MMCV 1.6.2 をインストール

    https://mmcv.readthedocs.io/en/latest/get_started/installation.html に記載の手順による

    python -m pip install -U pip
    python -m pip install -U opencv-python
    python -m pip install mmcv-full==1.6.2
    

    [image]
  5. MMCV をインストールできたことの確認

    python -c "from mmcv.ops import get_compiling_cuda_version, get_compiler_version; print(get_compiling_cuda_version()); print(get_compiler_version())"
    

    [image]

MIM,MMEditing のインストール(Windows 上)

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

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

  2. MIM, MMClassification, MMSegmentation, MMDetection, MMTracking, MMEditing のインストール.

    python -m pip install -U git+https://github.com/open-mmlab/mim.git
    python -m pip install -U git+https://github.com/open-mmlab/mmediting.git
    python -c "import mmedit; print(mmedit.__version__)"
    
  3. MMEditing のファイルをダウンロードし,使える状態にする

    cd %HOMEPATH%
    rmdir /s /q mmediting
    git clone https://github.com/open-mmlab/mmediting.git
    cd mmediting
    python setup.py develop
    
  4. MMEditing のデモファイルのダウンロード

    cd %HOMEPATH%
    cd mmediting
    curl -O https://download.openmmlab.com/mmediting/demo_files.zip 
    "c:\Program Files\7-Zip\7z.exe" x demo_files.zip

MMEditing の動作確認(Windows 上)

超解像 (super resolution) の実行

  1. 次のコマンドを実行

    SRCNN による画像の超解像 (super resolution) の実行

    学習済みモデルを使用.

    MMEditing の SRCNN の説明ページ: https://github.com/open-mmlab/mmediting/blob/master/configs/restorers/srcnn/README.md

    コマンドの説明: https://github.com/open-mmlab/mmediting/blob/master/docs/en/getting_started.md

    python demo/restoration_demo.py ./configs/restorers/srcnn/srcnn_x4k915_g1_1000k_div2k.py https://download.openmmlab.com/mmediting/restorers/srcnn/srcnn_x4k915_1x16_1000k_div2k_20200608-4186f232.pth ./demo_files/lq_images/bird.png ./outputs/bird_SRCNN.png
    
    python -c "import mmcv; mmcv.imshow('./demo_files/lq_images/bird.png')"
    python -c "import mmcv; mmcv.imshow('./outputs/bird_SRCNN.png')"
    
  2. ESRGAN による画像の超解像 (super resolution) の実行

    学習済みモデルを使用.

    MMEditing の ESRGAN の説明ページ: https://github.com/open-mmlab/mmediting/blob/master/configs/restorers/esrgan/README.md

    コマンドの説明: https://github.com/open-mmlab/mmediting/blob/master/docs/en/getting_started.md

    python demo/restoration_demo.py ./configs/restorers/esrgan/esrgan_x4c64b23g32_g1_400k_div2k.py https://download.openmmlab.com/mmediting/restorers/esrgan/esrgan_x4c64b23g32_1x16_400k_div2k_20200508-f8ccaf3b.pth ./demo_files/lq_images/bird.png ./outputs/bird_ESRGAN.png
    
    python -c "import mmcv; mmcv.imshow('./demo_files/lq_images/bird.png')"
    python -c "import mmcv; mmcv.imshow('./outputs/bird_ESRGAN.png')"
    
  3. EDVR による連続画像の超解像 (super resolution) の実行

    学習済みモデルを使用.

    MMEditing の EDVR の説明ページ: https://github.com/open-mmlab/mmediting/blob/master/configs/restorers/edvr/README.md

    コマンドの説明: https://github.com/open-mmlab/mmediting/blob/master/docs/en/getting_started.md

    python demo/restoration_video_demo.py ./configs/restorers/edvr/edvrm_wotsa_x4_g8_600k_reds.py https://download.openmmlab.com/mmediting/restorers/edvr/edvrm_wotsa_x4_8x4_600k_reds_20200522-0570e567.pth demo_files/lq_sequences/city/ ./outputs/city_EDVR --window_size=5
    
    python -c "import mmcv; mmcv.imshow('./demo_files/lq_sequences/city/00000000.png')"
    python -c "import mmcv; mmcv.imshow('./outputs/city_EDVR/00000000.png')"
    python -c "import mmcv; mmcv.imshow('./demo_files/lq_sequences/city/00000001.png')"
    python -c "import mmcv; mmcv.imshow('./outputs/city_EDVR/00000001.png')"
    python -c "import mmcv; mmcv.imshow('./demo_files/lq_sequences/city/00000002.png')"
    python -c "import mmcv; mmcv.imshow('./outputs/city_EDVR/00000002.png')"
    python -c "import mmcv; mmcv.imshow('./demo_files/lq_sequences/city/00000003.png')"
    python -c "import mmcv; mmcv.imshow('./outputs/city_EDVR/00000003.png')"
    python -c "import mmcv; mmcv.imshow('./demo_files/lq_sequences/city/00000004.png')"
    python -c "import mmcv; mmcv.imshow('./outputs/city_EDVR/00000004.png')"
    python -c "import mmcv; mmcv.imshow('./demo_files/lq_sequences/city/00000005.png')"
    python -c "import mmcv; mmcv.imshow('./outputs/city_EDVR/00000005.png')"
    
  4. BasicVSR (Recurrent framework) の実行

    学習済みモデルを使用.

    MMEditing の EDVR の説明ページ: https://github.com/open-mmlab/mmediting/blob/master/configs/restorers/edvr/README.md

    コマンドの説明: https://github.com/open-mmlab/mmediting/blob/master/docs/en/getting_started.md

    python demo/restoration_video_demo.py ./configs/restorers/basicvsr/basicvsr_reds4.py https://download.openmmlab.com/mmediting/restorers/basicvsr/basicvsr_reds4_20120409-0e599677.pth demo_files/lq_sequences/city/ ./outputs/city_BasicVSR
    
    python -c "import mmcv; mmcv.imshow('./demo_files/lq_sequences/city/00000000.png')"
    python -c "import mmcv; mmcv.imshow('./outputs/city_BasicVSR/00000000.png')"
    python -c "import mmcv; mmcv.imshow('./demo_files/lq_sequences/city/00000001.png')"
    python -c "import mmcv; mmcv.imshow('./outputs/city_BasicVSR/00000001.png')"
    python -c "import mmcv; mmcv.imshow('./demo_files/lq_sequences/city/00000002.png')"
    python -c "import mmcv; mmcv.imshow('./outputs/city_BasicVSR/00000002.png')"
    python -c "import mmcv; mmcv.imshow('./demo_files/lq_sequences/city/00000003.png')"
    python -c "import mmcv; mmcv.imshow('./outputs/city_BasicVSR/00000003.png')"
    python -c "import mmcv; mmcv.imshow('./demo_files/lq_sequences/city/00000004.png')"
    python -c "import mmcv; mmcv.imshow('./outputs/city_BasicVSR/00000004.png')"
    python -c "import mmcv; mmcv.imshow('./demo_files/lq_sequences/city/00000005.png')"
    python -c "import mmcv; mmcv.imshow('./outputs/city_BasicVSR/00000005.png')"
    
  5. image inpainting の実行
  6. image matting の実行

demos URL: https://github.com/open-mmlab/mmediting/blob/master/docs/en/getting_started.md

python demo/generation_demo.py configs/example_config.py work_dirs/example_exp/example_model_20200202.pth demo/demo.jpg demo/demo_out.jpg

python demo/generation_demo.py configs/example_config.py work_dirs/example_exp/example_model_20200202.pth demo/demo.jpg demo/demo_out.jpg --unpaired_path demo/demo_unpaired.jpg