私的AI研究会 > cudaGPU
「PyTorch ではじめる AI開発」CPU でのモデル学習にあまりに時間がかかるので、手元にあるGPUを試してみる。
VertualBox 環境下では残念ながら GPU のサポートは受けられないようなので、Windows10 環境で環境構築を行うことにする。
アーキテクチャ (読み方) | プロセスルール | 採用シリーズ |
Kepler (ケプラー) | 28nm | GeForce GTX/GT 600シリーズ |
GeForce GTX/GT 700シリーズ | ||
GeForce GTX TITANシリーズ | ||
Maxwell (マクスウェル) | 28nm | GeForce GTX 700シリーズ |
GeForce GTX 900シリーズ | ||
Pascal (パスカル) | 16nm/14nm | GeForce GTX 10シリーズ |
Turing (チューリング) | 12nm | GeForce RTX 20シリーズ |
GeForce GTX 16シリーズ | ||
Ampere (アンペア) | 8nm | GeForce RTX 30シリーズ |
Ada Lovelace (エイダラブレス) | 5nm | GeForce RTX 40シリーズ |
コマンド | パラメータ | 用途 |
cd (chdir) | 現在のカレンディレクトリを表示 | |
パス | カレンディレクトリの変更 | |
dir | カレンディレクトリのファイルやフォルダ一覧 | |
パス | 指定したパスのファイル表示 | |
tree | カレンディレクトリのツリー表示 | |
パス | 指定したパスのツリー表示 | |
ren | 対象ファイル名 新しいファイル名 | ファイル名を変更 |
move | 移動するファイル名 移動先パス | ファイルを移動 |
変更前ディレクトリ 変更後ディレクトリ | ディレクトリ名を変更 | |
copy | コピー元 コピー先 | ファイルをコピー |
del | ファイル | ファイルやフォルダを削除 |
help | コマンド名 | コマンドのヘルプ表示 |
cls | コンソールのクリア | |
md (mkdir) | (パス)ディレクトリ名 | ディレクトリの作成 |
rm (rmdir) | (パス)ディレクトリ名 | ディレクトリの削除 |
type | (パス)ファイル名 | テキストファイルの中身表示 |
more | (パス)ファイル名 | テキストファイルの1画面表示 |
ipconfig | ネットワークの設定確認 | |
exit | コマンドプロンプトを終了 |
(base) C:\Users\izuts>conda create -n py37 python=3.7 : done # # To activate this environment, use # # $ conda activate py_37 # # To deactivate an active environment, use # # $ conda deactivate (base) C:\Users\izuts>conda activate py37 (py37) C:\Users\izuts> (py37) C:\Users\izuts>conda info -e # conda environments: # base C:\Users\izuts\anaconda3 py37 * C:\Users\izuts\anaconda3\envs\py37・以降の操作は「Anaconda Prompt」から「py37」仮想環境を起動した状態で行う。
(py37) > pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio===0.8.0 -f https://download.pytorch.org/whl/torch_stable.html Looking in links: https://download.pytorch.org/whl/torch_stable.html Collecting torch==1.8.0+cu111 : Successfully installed numpy-1.21.2 pillow-8.3.2 torch-1.8.0+cu111 torchaudio-0.8.0 torchvision-0.9.0+cu111 typing-extensions-3.10.0.2
(py37) > conda install opencv : (py37) > conda install pandas : (py37) > conda install tqdm : (py37) > conda install matplotlib : (py37) > conda install PyYAML :
(py37) > pip install scikit-learn : (py37) > pip install pycocotools : (py37) > pip install facenet-pytorch :
(py37) > python -c "import torch"※「python3」ではエラーとなるので「python」コマンドを使用する。
(py37) > python -c "import tkinter"
(py37) > python -c "import torch;print(torch.zeros(1).cuda())" tensor([0.], device='cuda:0') (py37) > python -c "import torch;print(torch.cuda.is_available())" True (py37) > python -c "import torch;print(torch.cuda.get_device_name(torch.device('cuda:0')))" NVIDIA GeForce GTX 1050 Ti
(py37) cd \workspace_py37\chapter01 (py37) > python chapt01_1.py Traceback (most recent call last): File "chapt01_1.py", line 12, in <module> ret, frame = cap.read() # 1フレーム読み込み KeyboardInterrupt
「cuda_test.py」 import torch print(torch.__version__) print(f"cuda, {torch.cuda.is_available()}") print(f"compute_{''.join(map(str,(torch.cuda.get_device_capability())))}") device_num:int = torch.cuda.device_count() print(f"find gpu devices, {device_num}") for idx in range(device_num): print(f"cuda:{idx}, {torch.cuda.get_device_name(idx)}") print("end")
(py37) cd \workspace_py37 (py37) > python cuda_test.py 1.8.0+cu111 cuda, True compute_61 find gpu devices, 1 cuda:0, NVIDIA GeForce GTX 1050 Ti end
「PyTorch ではじめる AI開発」の演習で作成したプログラム一式を Windows環境下のワークスペース「workspace_py37」にコピーして実行する。
RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase. This probably means that you are not using fork to start your child processes and you have forgotten to use the proper idiom in the main module: if __name__ == '__main__': freeze_support() ... The "freeze_support()" line can be omitted if the program is not going to be frozen to produce an executable.
(py37) cd \workspace_py37\chapter02 (py37) > python chapt02_1w.py test #0 lr=0.001 weight=0.1 epoch #0: train_loss:0.2363738864660263 valid_loss:0.671642541885376 score:{'daytime': 0.8198986642100414, 'twilight': 0.6198243412797992, 'midnight': 0.8382004735595896, 'total': 0.8051609539945263, 'average': 0.6876712328767123} epoch #1: train_loss:0.11925811320543289 valid_loss:0.7707163691520691 score:{'daytime': 0.8119376782971253, 'twilight': 0.6402966625463535, 'midnight': 0.9232995658465991, 'total': 0.8327183271832719, 'average': 0.7711415525114155} epoch #2: train_loss:0.09785430878400803 valid_loss:1.1248260736465454 score:{'daytime': 0.8047670639219935, 'twilight': 0.6153846153846154, 'midnight': 0.9255242227042662, 'total': 0.8252544837615123, 'average': 0.7934246575342466} : test #14 lr=5e-05 weight=0.5 epoch #0: train_loss:0.5843794941902161 valid_loss:0.5459811091423035 score:{'daytime': 0.8226044226044227, 'twilight': 0.7152103559870548, 'midnight': 0.888248479026577, 'total': 0.8311780756910665, 'average': 0.8257534246575342} epoch #1: train_loss:0.42763030529022217 valid_loss:0.38860195875167847 score:{'daytime': 0.8707763734846531, 'twilight': 0.5974955277280858, 'midnight': 0.9057025717480431, 'total': 0.8431883302943476, 'average': 0.6885844748858447} epoch #2: train_loss:0.3030227720737457 valid_loss:0.31260067224502563 score:{'daytime': 0.9316497392259128, 'twilight': 0.6093928980526918, 'midnight': 0.9251551661190215, 'total': 0.890420399724328, 'average': 0.611324200913242}
機種 | 開始日時 | 終了日時 | 処理時間 (h:m) |
GeForce GTX 1050 Ti Intel® Core™ i7-6700 | 10/12 19:01 | 10/13 00:09 | 05:08 |
DELL Latitude 7520 Intel® Core™ i7-1185G7 CPU | 09/05 14:35 | 09/07 02:02 | 35:27 |
HP EliteDesk 800 Intel® Core™ i7-6700 CPU | 09/05 11:00 | 09/07 05:15 | 41:55 |
(py37) cd \workspace_py37\chapter05 (py37) > date /t 2021/10/14 (py37) > time /t 05:05 (py37) > python chapt05_2w.py Using cache found in C:\Users\izuts/.cache\torch\hub\pytorch_vision_v0.6.0 100%|██████████████████████████████████| 11294/11294 [5:56:55<00:00, 1.90s/it] epoch #0: train_loss:0.14030972123146057 100%|██████████████████████████████████| 11294/11294 [5:56:12<00:00, 1.89s/it] epoch #1: train_loss:0.1263476312160492 100%|██████████████████████████████████| 11294/11294 [5:52:53<00:00, 1.87s/it] epoch #2: train_loss:0.12263970822095871 100%|██████████████████████████████████| 11294/11294 [5:52:45<00:00, 1.87s/it] epoch #3: train_loss:0.12062573432922363 100%|██████████████████████████████████| 11294/11294 [5:53:30<00:00, 1.88s/it] epoch #4: train_loss:0.11797807365655899 100%|██████████████████████████████████| 11294/11294 [5:54:05<00:00, 1.88s/it] epoch #5: train_loss:0.11718424409627914 100%|██████████████████████████████████| 11294/11294 [5:53:51<00:00, 1.88s/it] epoch #6: train_loss:0.11532850563526154 100%|██████████████████████████████████| 11294/11294 [5:52:37<00:00, 1.87s/it] epoch #7: train_loss:0.11388455331325531 (py37) > dir ドライブ N のボリューム ラベルは WORK1 です ボリューム シリアル番号は 8008-71B6 です \workspace_py37\chapter05 のディレクトリ 2021/10/12 18:58 <DIR> . 2021/10/12 18:58 <DIR> .. 2021/10/12 15:51 <DIR> annotations 2021/10/16 04:18 244,646,735 chapt05-model1.pth 2021/09/22 04:50 1,889 chapt05_1a.py 2021/09/22 05:38 4,015 chapt05_2a.py 2021/10/12 19:01 4,277 chapt05_2w.py 2021/10/03 16:47 5,070 chapt05_3a.py 2021/10/04 10:11 10,806,542 chapt05_output.avi 2021/10/12 16:04 <DIR> imgs 2021/10/12 16:11 <DIR> mask 2021/10/12 16:44 <DIR> train2014 6 個のファイル 255,468,528 バイト 6 個のディレクトリ 1,438,868,893,696 バイトの空き領域
機種 | 開始日時 | 終了日時 | 処理時間 (h:m) |
GeForce GTX 1050 Ti Intel® Core™ i7-6700 | 10/14 05:05 | 10/16 04:18 | 46:47 |
Intel® NUC BXNUC10I5FNH Core™ i5-10210U CPU | 09/27 19:40 | 10/04 09:12 | 157:30 |
DELL Latitude 7520 Intel® Core™ i7-1185G7 CPU | 09/26 10:36 | 10/05 07:20 | 212:36 |
(py37) > cd ~/workspace_py37/chapter07 (py37) $ date 2021年 10月 24日 日曜日 09:57:43 JST (py37) $ python3 chapt07_1a.py : 100%|█████████████████████████████████████| 1590/1590 [4:57:35<00:00, 11.23s/it] epoch #0: train_loss:4.0809502601623535 100%|█████████████████████████████████████| 1590/1590 [4:58:51<00:00, 11.28s/it] epoch #1: train_loss:4.114153861999512 : 100%|█████████████████████████████████████| 1590/1590 [5:03:13<00:00, 11.44s/it] epoch #48: train_loss:3.2765839099884033 100%|█████████████████████████████████████| 1590/1590 [5:03:24<00:00, 11.45s/it] epoch #49: train_loss:3.271886110305786 Model saved with cpu 'chapt07-model.pth' at 'checkpoints/line2illust/'※ 時間がかかるので、バッチサイズ 4 → 40 に変更。エポック数 50 で実行。
(py37) > cd \workspace_py37\chapter07 (py37) > python chapt07_1b.py : 100%|██████████████████████████████████| 31785/31785 [3:05:38<00:00, 2.85it/s] epoch #9: train_loss:3.872145175933838 Model saved with GPU 'chapt07-model.pth' at 'checkpoints/line2illust/'※ 時間がかかりそうなので、エポック回数10で実行。GPUボードのメモリー(4GB)のためバッチサイズは 2とする。
機種 | 開始日時 | 終了日時 | 処理時間 (h:m) |
Intel® NUC BXNUC10I5FNH Core™ i5-10210U CPU | 10/24 09:57 | 11/03 21:36 | 251:21 |
※GeForce GTX 1050 Ti Intel® Core™ i7-6700 | 11/07 17:57 | 11/09 01:47 | 30:50 |
(py37) > cd \workspace_py37\chapter08 (py37) > python chapt08_1w.py 100%|█████████████████████████████████████████| 20/20 [33:30<00:00, 100.54s/it]・CPU (Intel® Core™ i7-1185G7)
(py37) $ cd \workspace_py37\chapter08 (py37) $ python3 chapt08_1a.py 100%|██████████████████████████████████████| 20/20 [49:23:56<00:00, 8891.84s/it]
機種 | 開始日時 | 終了日時 | 処理時間 (h:m) |
GeForce GTX 1050 Ti Intel® Core™ i7-6700 | 10/13 04:31 | 10/13 05:05 | 00:34 |
DELL Latitude 7520 Intel® Core™ i7-1185G7 CPU | 10/13 12:50 | 10/15 15:14 | 49:24 |
(py37) > cd ~\workspace_py37\chapter09 (py37) > python3 chapt09_1a.py 100%|███████████████████████████████| 100000/100000 [28:34:11<00:00, 1.03s/it]・CPU (Intel® Core™ i7-1185G7)
(py37) $ cd ~/workspace_py37/chapter09 (py37) $ python3 chapt09_1a.py 0%| | 11/100000 [01:19<199:44:48, 7.19s/it] :
機種 | 開始日時 | 終了日時 | 処理時間 (h:m) |
GeForce GTX 1050 Ti Intel® Core™ i7-6700 | 10/17 09:30 | 10/18 13:05 | 27:35 |
DELL Latitude 7520 Intel® Core™ i7-1185G7 CPU | --/-- --:-- | --/-- --:-- | --:-- |