[PYTHON] Deep Learning with Shogi AI on Mac and Google Colab

Book "Deep Learning Learned with Shogi AI" by Tadao Yamaoka Original source code https://github.com/TadaoYamaoka/python-dlshogi.git

Purpose

Run "Deep Learning with Shogi AI" on iMac and Google Colab. Build the basic environment on the iMac and use the GPU of Google Colab only when learning.

environment

iMac iMac 2020 27inch default model 3.1GHz 6-core 10th generation Intel Core i5 processor Up to 4.5GHz when using Turbo Boost 8GB 2,666MHz DDR4 memory 256GB SSD storage Radeon Pro 5300 (with 4GB GDDR6 memory) OS : Catalina Python: 3.8.2 and 2.7 pre-installed. This time I used 3.8.2. Google Colab Python 3.6.9

Summary of results

Prepare files on the iMac side and sync with Google Drive. image.png Learning execution on the Google Colab side. image.png Play on iMac. image.png Game video https://youtu.be/vPCsmi3_Zu8

table of contents

Use Google Colab </ b> [Getting Google Colab ready](https://qiita.com/kazunoriri/items/ef116e1cf88b4649a9b7#google-colab%E3%82%92%E4%BD%BF%E3%81%88%E3%82% 8B% E7% 8A% B6% E6% 85% 8B% E3% 81% AB% E3% 81% 99% E3% 82% 8B) Local side Google Colab side [Mount the drive](https://qiita.com/kazunoriri/items/ef116e1cf88b4649a9b7#%E3%83%89%E3%83%A9%E3%82%A4%E3%83%96%E3%82% 92% E3% 83% 9E% E3% 82% A6% E3% 83% B3% E3% 83% 88% E3% 81% 99% E3% 82% 8B) [Enable GPU](https://qiita.com/kazunoriri/items/ef116e1cf88b4649a9b7#gpu%E3%82%92%E6%9C%89%E5%8A%B9%E3%81%AB%E3% 81% 99% E3% 82% 8B) [Install chainer](https://qiita.com/kazunoriri/items/ef116e1cf88b4649a9b7#chainer%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83% 88% E3% 83% BC% E3% 83% AB) [Install python-shogi and pydlshogi](https://qiita.com/kazunoriri/items/ef116e1cf88b4649a9b7#python-shogi%E3%81%A8pydlshogi%E3%82%92%E3%82%A4%E3%83% B3% E3% 82% B9% E3% 83% 88% E3% 83% BC% E3% 83% AB) Use Google Colab Local side Colab side Learning execution Experiment   CPU vs GPU

Chapter 1-6 </ b> Chapter 1-5 [Chapter 6 Deep Learning Framework](https://qiita.com/kazunoriri/items/32c45e46bb122ae1ef7c#%E7%AC%AC6%E7%AB%A0-%E3%83%87%E3%82%A3% E3% 83% BC% E3% 83% 97% E3% 83% A9% E3% 83% BC% E3% 83% 8B% E3% 83% B3% E3% 82% B0% E3% 83% 95% E3% 83% AC% E3% 83% BC% E3% 83% A0% E3% 83% AF% E3% 83% BC% E3% 82% AF) Chainer and numpy Warning

Chapter 7 1-4 </ b> [Chapter 7 Policy Network](https://qiita.com/kazunoriri/items/f91e39e36cf179750e5e#%E7%AC%AC7%E7%AB%A0-%E6%96%B9%E7%AD%96%E3% 83% 8D% E3% 83% 83% E3% 83% 88% E3% 83% AF% E3% 83% BC% E3% 82% AF)   7.1~7.4    policy.py [Meaning of 194 filters](https://qiita.com/kazunoriri/items/f91e39e36cf179750e5e#%E3%83%95%E3%82%A3%E3%83%AB%E3%82%BF%E3% 83% BC% E6% 95% B0194% E5% 80% 8B% E3% 81% AE% E6% 84% 8F% E5% 91% B3) [Meaning of 1x1 filter](https://qiita.com/kazunoriri/items/f91e39e36cf179750e5e#1x1%E3%83%95%E3%82%A3%E3%83%AB%E3%82%BF%E3%83 % BC% E3% 81% AE% E6% 84% 8F% E5% 91% B3)    common.py     bb_rotate180()    features.py     make_input_features()     make_input_features_from_board()     make_output_label()     make_features()

Chapter 7 5-7 </ b>  7.5~7.7   read_kifu.py    read_kifu()

Chapter 7 8 </ b>  7.8 [Automatic use of GPU and CPU](https://qiita.com/kazunoriri/items/e8541358bb030742cb19#gpu%E3%81%A8cpu%E3%81%AE%E8%87%AA%E5%8B%95%E4 % BD% BF% E3% 81% 84% E5% 88% 86% E3% 81% 91) [Pickle Protocol](https://qiita.com/kazunoriri/items/e8541358bb030742cb19#pickle%E3%81%AE%E3%83%97%E3%83%AD%E3%83%88%E3%82% B3% E3% 83% AB)   train_policy.py

Chapter 7 9 </ b>  7.9 Learning execution

Chapter 8 1-4 </ b> [Implementation of USI engine](https://qiita.com/kazunoriri/items/e313efd0026d56e65442#usi%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%B3%E3%81 % AE% E5% AE% 9F% E8% A3% 85)   policy_player.py    y = self.model(x)    logits = y.data[0]    probabilities = F.softmax(y).data[0] [Automatic switching between GPU / CPU and PC](https://qiita.com/kazunoriri/items/e313efd0026d56e65442#gpucpu%E3%81%A8pc%E3%81%AE%E8%87%AA%E5%8B%95 % E5% 88% 87% E3% 82% 8A% E6% 9B% BF% E3% 81% 88) Strategy setting All codes Test [Test from command line](https://qiita.com/kazunoriri/items/e313efd0026d56e65442#%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%83% A9% E3% 82% A4% E3% 83% B3% E3% 81% 8B% E3% 82% 89% E3% 83% 86% E3% 82% B9% E3% 83% 88) [Test from Google Colab](https://qiita.com/kazunoriri/items/e313efd0026d56e65442#google-colab%E3%81%8B%E3%82%89%E3%83%86%E3%82%B9%E3 % 83% 88) Coordinates

Chapter 8 5-9 </ b> [Register with GUI software](https://qiita.com/kazunoriri/items/e0791fb8a975b58db275#gui%E3%82%BD%E3%83%95%E3%83%88%E3%81%AB%E7%99 % BB% E9% 8C% B2) [Problem that engine registration is not completed](https://qiita.com/kazunoriri/items/e0791fb8a975b58db275#%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%B3%E7% 99% BB% E9% 8C% B2% E3% 81% 8C% E7% B5% 82% E3% 82% 8F% E3% 82% 89% E3% 81% AA% E3% 81% 84% E5% 95% 8F% E9% A1% 8C) Game

Chapter 9 </ b> [Learning Technique](https://qiita.com/kazunoriri/items/74c800bfa48cba34bb1c#%E5%AD%A6%E7%BF%92%E3%83%86%E3%82%AF%E3%83%8B% E3% 83% 83% E3% 82% AF)   SGD   Momentum SGD   SGD , Batch Normalization

Word </ b>  shogi.BB_SQUARES  shogi.COLORS  shogi.CSA.Parser.parse_file(filepath)  shogi.PIECE_TYPES_WITH_NONE  shogi.MAX_PIECES_IN_HAND  shogi.SQUARES Move class   from_square   to_square Board class   piece_bb   occupied   pieces_in_hand

Recommended Posts