import torch.nn as nn import torch.nn.functional as F import torch import numpy as np from torch.autograd import Variable
classNet(nn.Module): def__init__(self): super(Net, self).__init__() self.fc1 = nn.Linear(1, 1) # an affine operation: y = Wx + b defforward(self, x): x=self.fc1(x) return x net = Net() net
'''神经网络的结构是这样的 Net ( (fc1): Linear (1 -> 1) ) ''' x = torch.arange(0, 100, 0.01,dtype=torch.float32) y = (10 * x + 5 + np.random.normal(0, 1, x.size())).float()
batch_size = 100 w = torch.randn((1,), requires_grad=True,dtype=torch.float32) b = torch.randn((1,), requires_grad=True,dtype=torch.float32)