用pytorch的两种方法创建神经网络

import torch
import torch.nn.functional as F

replace following class code with an easy sequential network

class Net(torch.nn.Module):
def init(self, n_feature, n_hidden, n_output):
super(Net, self).init()
self.hidden = torch.nn.Linear(n_feature, n_hidden) # hidden layer
self.predict = torch.nn.Linear(n_hidden, n_output) # output layer

def forward(self, x):
    x = F.relu(self.hidden(x))      # activation function for hidden layer
    x = self.predict(x)             # linear output
    return x

net1 = Net(1, 10, 1)

easy and fast way to build your network

net2 = torch.nn.Sequential(
torch.nn.Linear(1, 10),
torch.nn.ReLU(),
torch.nn.Linear(10, 1)
)

print(net1) # net1 arch

上一篇:css3 地球自转公转


下一篇:linux dmsetup管理LVM命令详解