Index ソフト・ハード LightGBM | Sample |
datasets myData MNIST ranking nn.Module 機能・要件 構成・方式 タスク 導入 |
nn.Module ・torch.nn.Moduleクラスのサブクラス化によるモデルの定義
import torch
import torch.nn as nn
INPUT_FEATURES = 2 # データ(特徴)の入力ユニット数
OUTPUT_NEURONS = 1 # ニューロン数、出力ユニット数
activation = torch.nn.Tanh() # 活性化関数(tanh関数)
class NeuralNetwork(nn.Module):
def __init__(self): # メソッド1、層定義
super(NeuralNetwork, self).__init__()
self.layer1 = nn.Linear(INPUT_FEATURES,OUTPUT_NEURONS)
# Linearは全結合(Affine)
def forward(self, input): # メソッド2、活性化関数で変換し、データを流す。
output = activation(self.layer1(input)) # 出力=活性化関数(第1層(入力))
return output
model = NeuralNetwork() # モデル(NeuralNetworkクラス)のインスタンス化
model # モデルの内容を出力
|
All Rights Reserved. Copyright (C) ITCL |