Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
PyTorchで簡単なNN作り
Search
betashort
May 09, 2020
170
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PyTorchで簡単なNN作り
betashort
May 09, 2020
More Decks by betashort
See All by betashort
2020研究室勉強会No.0
betashort
0
75
Pythonで解く計量時系列分析1
betashort
0
60
なんでもできるPython-脳機能画像とPython-
betashort
1
160
勉強会を企画したときの資料
betashort
0
36
Featured
See All Featured
Accessibility Awareness
sabderemane
1
230
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
76k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
580
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
730
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
The Curse of the Amulet
leimatthew05
3
15k
Discover your Explorer Soul
emna__ayadi
2
1.3k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
500
Evolving SEO for Evolving Search Engines
ryanjones
0
300
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
Transcript
PyTorchで簡単なNN作り 勉強会NO1
単純なNNモデルの作り⽅ 1. データの読み込み 2. モデルの定義 3. 学習 4. モデルの評価 5.
(モデルの保存) 6. 推論
ソースコードについて https://github.com/betashort/python/blob/master/NN/PyTorch_NN.ipynb • 下のリンクに今回のソースコードがあります
1. データの読み込み • torch.utils.data.Dataset() • torch.utils.data.DataLoader()
2. モデルの定義 class NNNet(nn.Module): def __init__(self, in_features, num_class=2): super(NNNet, self).__init__()
self.net = nn.Sequential( nn.Linear(5, 3), nn.ReLU(), nn.Linear(3, 2), ) def forward(self, x): out = self.net(x) return out input output forward
3. 学習の⼿順-⽤意するもの- 1. 損失関数(LossFunction) #==== 損失関数の定義 ==== criterion = nn.CrossEntropyLoss()
#==== Optimizerの定義 ==== learning_rate = 0.01 optimizer = torch.optim.Adam( model.parameters(), lr=learning_rate) 2. 最適化アルゴリズム(Optimizer) Loss Function input output correct loss optimize
3. 学習の⼿順-更新- #==== Optimizerの初期化 ==== optimizer.zero_grad() forward backward input output
Loss Function optimize #==== forward processing ==== outputs = model(images) #==== Loss calcuration ==== loss = criterion(outputs, labels) #==== backward processing ==== loss.backward() #==== update optimizer ==== optimizer.step()
4. モデルの評価 l 精度はいいか? l Lossは減少しているか? l 過学習してないか?
5. モデルの保存とロード • 学習が終わったモデルは、再現できるように保存する #====== 保存 ======= torch.save(model.state_dict(), "model.pth") •
学習済みのモデルを、読み込む model = NNNet(64) #====== ロード ======= model.load_state_dict(torch.load("model.pth", map_location=device))
6. 推論 model.eval() with torch.no_grad(): outputs = model.forward(x) input output
forward 重みを固定する
7. 畳み込み層とプーリング層 nn.Conv2d(in_channels = 1, out_channels = 16, kernel_size =
3, stride=1, padding=0) torch.nn.Conv2dで定義
7. 畳み込み層とプーリング層 nn.MaxPool2d(kernel_size=2, stride=2) プーリング層 • MaxPooling • AveragePooling