pytorch基础(二)
目录 An easy way Save and reload Train on batch Optimizers CNN An easy way 使用 torch.nn.Sequential() 来更快地构建神经网络: 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