金子邦彦研究室人工知能Windows でのインストールと動作確認(人工知能関係)JingyunLiang/SwinIR のインストールと動作確認(超解像,画像のノイズ除去)(Python,PyTorch を使用)(Windows 上)

JingyunLiang/SwinIR のインストールと動作確認(超解像,画像のノイズ除去)(Python,PyTorch を使用)(Windows 上)

SwinIRは,超解像,ノイズ除去の一手法

目次

  1. 前準備
  2. SwinIR のダウンロード
  3. 超解像の実行,ノイズ除去の実行

[image]
003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN.pth による結果

[image]
005_colorDN_DFWB_s128w8_SwinIR-M_noise25.pth による結果

文献】 Liang, Jingyun and Cao, Jiezhang and Sun, Guolei and Zhang, Kai and Van Gool, Luc and Timofte, Radu, SwinIR: Image Restoration Using Swin Transformer, arXiv preprint arXiv:2108.10257, 2021.

関連する外部ページ

GitHub のページ: https://github.com/JingyunLiang/SwinIR

前準備

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

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

関連する外部ページ

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

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]

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

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

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

  2. 次のコマンドを実行する.

    python -m pip install -U timm
    

SwinIR のダウンロード

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

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

  2. ダウンロード

    cd %HOMEPATH%
    rmdir /s /q SwinIR
    git clone --recursive https://github.com/JingyunLiang/SwinIR
    

    [image]
  3. 公開されている学習済みモデルを確認

    [image]

    https://github.com/JingyunLiang/SwinIR

  4. 公開されている学習済みモデルのファイルを確認

    https://github.com/JingyunLiang/SwinIR/releases

    [image]
  5. 学習済みモデルのダウンロード
    cd %HOMEPATH%
    cd swinir
    cd model_zoo
    mkdir swinir
    cd swinir
    curl -L -O https://github.com/JingyunLiang/SwinIR/releases/download/v0.0/003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN.pth
    curl -L -O https://github.com/JingyunLiang/SwinIR/releases/download/v0.0/003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_PSNR.pth
    curl -L -O https://github.com/JingyunLiang/SwinIR/releases/download/v0.0/005_colorDN_DFWB_s128w8_SwinIR-M_noise15.pth
    curl -L -O https://github.com/JingyunLiang/SwinIR/releases/download/v0.0/005_colorDN_DFWB_s128w8_SwinIR-M_noise25.pth
    curl -L -O https://github.com/JingyunLiang/SwinIR/releases/download/v0.0/005_colorDN_DFWB_s128w8_SwinIR-M_noise50.pth
    

    [image]

超解像の実行,ノイズ除去の実行

  • 超解像

    4倍に拡大.003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN.pth, 003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_PSNR.pth を使用.

    https://github.com/JingyunLiang/SwinIRに記載の手順で行っている.

    testsets/RealSRSet+5imagesのディレクトリにある画像ファイルが処理される. 結果は results の下にできる

    cd %HOMEPATH%
    cd swinir
    python main_test_swinir.py --task real_sr --scale 4 --large_model --model_path model_zoo/swinir/003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN.pth --folder_lq testsets/RealSRSet+5images
    python main_test_swinir.py --task real_sr --scale 4 --large_model --model_path model_zoo/swinir/003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_PSNR.pth --folder_lq testsets/RealSRSet+5images
    

    [image]
    元画像

    [image]
    003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN.pth による結果

    [image]
    003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_PSNR.pth による結果
  • カラー画像のノイズ除去

    https://github.com/JingyunLiang/SwinIRに記載の手順で行っている.

    「--noise 15」,「--noise 25」,「--noise 50」の 3通りで実行される.

    testsets/McMaster のディレクトリにある画像ファイルが処理される. 結果は results の下にできる

    python main_test_swinir.py --task color_dn --noise 15 --model_path model_zoo/swinir/a005_colorDN_DFWB_s128w8_SwinIR-M_noise15.pth --folder_gt testsets/McMaster
    python main_test_swinir.py --task color_dn --noise 25 --model_path model_zoo/swinir/005_colorDN_DFWB_s128w8_SwinIR-M_noise25.pth --folder_gt testsets/McMaster
    python main_test_swinir.py --task color_dn --noise 50 --model_path model_zoo/swinir/005_colorDN_DFWB_s128w8_SwinIR-M_noise50.pth --folder_gt testsets/McMaster
    

    [image]
    元画像

    [image]
    005_colorDN_DFWB_s128w8_SwinIR-M_noise15.pth による結果

    [image]
    005_colorDN_DFWB_s128w8_SwinIR-M_noise25.pth による結果

    [image]
    005_colorDN_DFWB_s128w8_SwinIR-M_noise50.pth による結果