# 进行迭代训练 for epoch in range(1000): out = net(x) loss = criterion(out, y) optimizer.zero_grad() loss.backward() optimizer.step()
# 定义一个测试网络 test = net(x)
# 打印输入输出值 print("input is {}".format(x.detach().numpy())) print('out is {}'.format(test.detach().numpy()))
# 层数脚下表 i = 0
# 打印每层的权重和偏执 for layer in net.modules():
# 打印对应层的权重和偏执 if isinstance(layer, nn.Linear): print("weight_{} is {}".format(i, layer.weight.detach().numpy())) print("bias_{} is {}".format(i, layer.bias.detach().numpy()))