NN設計1(ネットワーク)
まず、ネットワークのクラス定義から示す。
code:nn.py
import torch.nn as nn
class Net(nn.Module):
def __init__(self, n_input, n_hidden, n_output):
super().__init__()
self.lin1 = nn.Linear(n_input, n_hidden)
self.lin2 = nn.Linear(n_hidden, n_output)
self.relu = nn.ReLU()
self.softmax = nn.Softmax(dim=1)
def forward(self, x):
x = self.lin1(x)
x = self.relu(x)
x = self.lin2(x)
x = self.softmax(x)
return x
このプログラムを実行してもクラス定義が行われるだけで画面には何も表示されない。次頁に進んでください。
/icons/hr.icon
※ ブラウザのバックボタンで戻る