Ubuntu22.04DesktopでSwinIRのインストール記録

AI・機械学習 コンピュータ
AI・機械学習

SwinIRをインストールしたのでその作業ログを残しておきます。

pythonの仮想環境を作成

cd ~/git 
python3 -m venv swinirvenv

環境名をswinirvenvにしました。

仮想環境の開始

source ~/git/swinirvenv/bin/activate

仮想環境の終了要確認

deactivate

必要なパッケージをインストール

python -m pip install --upgrade pip
python -m pip install -U --ignore-installed pip
python -m pip install -U torch torchvision torchaudio numpy --index-url https://download.pytorch.org/whl/cu115
cd ~/git
git clone --recursive https://github.com/JingyunLiang/SwinIR
cd SwinIR
python -m pip install -U timm
python -m pip install -U opencv-python

モデルのダウンロード


cd ~/git/SwinIR/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
curl -L -O https://github.com/JingyunLiang/SwinIR/releases/download/v0.0/004_grayDN_DFWB_s128w8_SwinIR-M_noise15.pth
curl -L -O https://github.com/JingyunLiang/SwinIR/releases/download/v0.0/004_grayDN_DFWB_s128w8_SwinIR-M_noise25.pth
curl -L -O https://github.com/JingyunLiang/SwinIR/releases/download/v0.0/004_grayDN_DFWB_s128w8_SwinIR-M_noise50.pth

仮想環境の開始と入出力ディレクトリを指定した実行用のシェルスクリプト

#!/bin/bash
cd ~
venvFile=`pwd`'/git/swinirvenv/bin/activate'
dataRoot='/mnt/workspace'
inputDir=$dataRoot'/inputs'
outputDir=$dataRoot'/outputs'
logfile=$dataRoot'/logs/SwinIR.log'

cd $outputDir
if [ `ls -U1 | wc -l` -ne 0 ]; then
    rm *
fi;
cd $inputDir
if [ `ls -U1 | wc -l` -eq 0 ]; then
    echo 'Not File';
    exit 1
fi;
cd ~/git/SwinIR
source $venvFile
echo '*** SwinIR Start ***' >> $logfile
date >> $logfile
python main_test_swinir.py --tile 512 --task real_sr --scale 4 --large_model --model_path model_zoo/swinir/003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN.pth --folder_lq $inputDir >> $logfile
date >> $logfile
echo '*** SwinIR End ***' >> $logfile
deactivate
mv results/swinir_real_sr_x4_large/* $outputDir
cd ~

実行環境に合わせて修正する必要あり。
自分の環境ではメモリ不足になるので、tileオプションをつけています。

コメント