環境構築 - yoshitaku55/ai_knowledge GitHub Wiki

環境構築

  • Pythonインストール  https://www.python.org/downloads/  下部のリリースバージョンから選択、64bit版インストーラを入手(Windows x86-64 executable installer)

​ インストール手順:以下参考

http://gothedistance.sakura.ne.jp/schoo/


  • VSCodeインストール(プラグイン japanese Python を入れる)

https://code.visualstudio.com/docs/?dv=win

https://www.kkaneko.jp/tools/win/vscode.html



  • 開発作業フォルダ作成、仮想環境・Flask準備

​ 仮想環境・Flask準備

​ → https://github.com/KazuSan0616/EasyDiagnosticsMaker/blob/master/README.md

​ (仮想環境、Flaskの準備 参照)

​ ・VSCodeで仮想環境のフォルダを開く

​ ・Pythonインタープリタの設定→VSCodeのコマンドパレット(Ctrl+Shift+P ) で開く

​ ①コマンドパレットにinterpreter 入力

​ ②仮想環境のパスを入力

​ ・settings.jsonにポリシー設定追加→VSCodeのsettings.json 開き方

https://qiita.com/y-w/items/614843b259c04bb91495

​ ・必要なライブラリ(Flask)インストール

​ ・他必要なライブラリをインストール

​ ※tensorflow インストールをする場合、事前に

​ 「Microsoft C++ Redistributable for Visual Studio 2015, 2017 and 2019」のインストールも必要

train.py
		pip install scikit-learn
		pip install numpy
		pip install scipy
        pip install pandas
train_handwrite.py
	pip install scikit-learn
	pip install numpy
	pip install scipy
    pip install pandas
    pip install keras
    pip install tensorflow
    pip install matplotlib
    pip install Pillow
run_server.py
	pip install opencv-python

  • Debug環境作成

https://www.atmarkit.co.jp/ait/articles/1807/24/news024_2.html

​ 1.「VS CodeでのFlaskアプリのデバッグ実行」参照

​ ①launch.jsonファイルを作成

​ ②launch.jsonファイルに「Flaskアプリをデバッグするための構成」を追加

  各項目詳細は上記記事参照

​ ③Python: Flask (0.11.x or later)をデバッグ実行で、FLASK_APPに指定したファイルが実行される

​ ④ターミナル上で「Ctrl+C」で実行中止

​ 2.「VS CodeでPythonアプリをデバッグ実行」

  ※以下の記事は、pythonアプリをデバッグするための構成について記載。

   機械学習を行うソースファイルを選択し、デバッグ実行(「Python: Current File」)するのに使用。

  https://www.atmarkit.co.jp/ait/articles/1806/05/news023_2.html

{
    // IntelliSense を使用して利用可能な属性を学べます。
    // 既存の属性の説明をホバーして表示します。
    // 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Flask (0.11.x or later)",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
              "FLASK_APP": "app.py"
            },
            "args": [
              "run",
              "--no-debugger",
              "--no-reload"
            ]
        }
    ]
}

  • WebAPI作成

​ 学習モデルを作成、ロードしてWebAPIを起動の流れを参考にする

https://qiita.com/fam_taro/items/1464c42324f15d7b8223

​ 学習モデルの作成

​ →VSCode ターミナル

​ cd C:\work\HandWriteService\HandWriteService\train (trainディレクトリにカレントDir移動)

​ python train.py を実行

​ WebAPIに投げるcurlコマンドは以下を参考。

​ curl http://127.0.0.1:5000/predict -X POST -H "Content-Type: application/json" -d {"feature":[1,1,1,1]}

​ ※Windowsコマンドからcurl を実行する場合、dataの「"」を「\」エスケープすること。

https://qiita.com/tokoroten-lab/items/291b463e45f422abd425



  • サーバーを公開する設定(WebAPI側に必要: 公開前に事前に要設定)

https://qiita.com/tomboyboy/items/122dfdb41188176e45b5