yu4u/noise2noise のインストールと動作確認(画像のノイズ除去)(TensorFlow 1.15.5,Python 3.7 を使用)(Windows 上)

次で配布されているソフトウェアを使ってみる手順を示す.

URL: https://github.com/yu4u/noise2noise

目次

  1. 前準備
  2. 画像のノイズ除去(yu4u/noise2noise,Python 3.7, TensorFlow 1.15.5)

利用条件等は,利用者で確認すること.

前準備

Python 3.7 のインストール(Windows 上) [クリックして展開]

以下のいずれかの方法で Python 3.7 をインストールする。Python がインストール済みの場合、この手順は不要である。

方法1:winget によるインストール

管理者権限コマンドプロンプトで以下を実行する。管理者権限のコマンドプロンプトを起動するには、Windows キーまたはスタートメニューから「cmd」と入力し、表示された「コマンドプロンプト」を右クリックして「管理者として実行」を選択する。

winget install -e --id Python.Python.3.7 --scope machine --silent --accept-source-agreements --accept-package-agreements --override "/quiet InstallAllUsers=1 PrependPath=1 AssociateFiles=1 InstallLauncherAllUsers=1"

--scope machine を指定することで、システム全体(全ユーザー向け)にインストールされる。このオプションの実行には管理者権限が必要である。インストール完了後、コマンドプロンプトを再起動すると PATH が自動的に設定される。

方法2:インストーラーによるインストール

  1. Python 公式サイト(https://www.python.org/downloads/)にアクセスし、「Download Python 3.x.x」ボタンから Windows 用インストーラーをダウンロードする。
  2. ダウンロードしたインストーラーを実行する。
  3. 初期画面の下部に表示される「Add python.exe to PATH」に必ずチェックを入れてから「Customize installation」を選択する。このチェックを入れ忘れると、コマンドプロンプトから python コマンドを実行できない。
  4. 「Install Python 3.xx for all users」にチェックを入れ、「Install」をクリックする。

インストールの確認

コマンドプロンプトで以下を実行する。

python --version

バージョン番号(例:Python 3.7.x)が表示されればインストール成功である。「'python' は、内部コマンドまたは外部コマンドとして認識されていません。」と表示される場合は、インストールが正常に完了していない。

Git のインストール(Windows 上) [クリックして展開]

管理者権限コマンドプロンプトで以下を実行する.管理者権限は,winget の --scope machine オプションでシステム全体にインストールするために必要となる.

REM Git をシステム領域にインストール
winget install --scope machine --id Git.Git -e --silent --disable-interactivity --force --accept-source-agreements --accept-package-agreements --override "/VERYSILENT /NORESTART /NOCANCEL /SP- /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS /COMPONENTS=""icons,ext\reg\shellhere,assoc,assoc_sh"" /o:PathOption=Cmd /o:CRLFOption=CRLFCommitAsIs /o:BashTerminalOption=MinTTY /o:DefaultBranchOption=main /o:EditorOption=VIM /o:SSHOption=OpenSSH /o:UseCredentialManager=Enabled /o:PerformanceTweaksFSCache=Enabled /o:EnableSymlinks=Disabled /o:EnableFSMonitor=Disabled"

TensorFlow 1.15.5, Keras 2.3.1 のインストール

コマンドプロンプト管理者として実行し,次のコマンドを実行

C:\venv\py37\Scripts\activate.bat
python -m pip uninstall -y tensorflow tensorflow-cpu tensorflow-gpu tensorflow-intel tensorflow-text tensorflow-estimator tf-models-official tf_slim tensorflow_datasets tensorflow-hub keras keras-tuner keras-visualizer scipy pandas matplotlib
# TensorFlow 1.15.5 のため numpy, protobuf の古いバージョンを使用.エラーが出にくいと考えられる numpy 1.16.2, protobuf 3.19.4 を使用
python -m pip install -U numpy==1.16.2 protobuf==3.19.4 tensorflow-gpu==1.15.5 keras==2.3.1 scipy==1.5.4

画像のノイズ除去(yu4u/noise2noise,Python 3.7, TensorFlow 1.15.5 を使用)

Windows での手順を下に示す.Ubuntu でも同様の手順になる.

  1. Windows で,コマンドプロンプト管理者として実行
  2. ダウンロード
    cd /d c:%HOMEPATH%
    rmdir /s /q noise2noise
    git clone https://github.com/yu4u/noise2noise
    cd noise2noise
    
  3. 前提パッケージのインストール
    C:\venv\py37\Scripts\activate.bat
    python -m pip install -r requirements.txt
    python -m pip install -U numpy==1.16.2 protobuf==3.19.4 tensorflow-gpu==1.15.5 keras==2.3.1 scipy==1.5.4
    
  4. データセットのダウンロード

    https://github.com/yu4u/noise2noise の記載による

    mkdir dataset
    cd dataset
    curl -O https://cv.snu.ac.kr/research/VDSR/train_data.zip
    curl -O https://cv.snu.ac.kr/research/VDSR/test_data.zip
    powershell -command "Expand-Archive -DestinationPath . -Path train_data.zip"
    powershell -command "Expand-Archive -DestinationPath . -Path test_data.zip"
    cd ..
    
  5. 学習と,動作確認

    train model using (noise, noise) pairs (noise2noise)

    C:\venv\py37\Scripts\activate.bat
    python train.py --image_dir dataset/291 --test_dir dataset/Set14 --image_size 128 --batch_size 8 --lr 0.001 --output_path gaussian
    python test_model.py --weight_file gaussian --image_dir dataset/Set14