我正在使用 pytorch 实践人工智能研究,所以我想要一些技巧来改进我创建的模型。
模型的输入/目标遵循角色:
if input[0] + input[1] >= 0:
target = 10
else:
target = -10
inputs = torch.rand(1000000, 2).sub(.5).mul(200)
# tensor([[ 25.8606, -40.9372],
# [ 79.3800, 44.6780],
# [ 76.0107, -77.0862],
# [-21.3406, -27.1793],
# [ 71.2402, -81.8930],
# [ 37.5089, 73.1345],
# [ 73.6303, 69.5081],
# [-52.1048, -70.0359],
# [ 45.5813, -86.4757],
# [ 96.3207, 5.4885]])
targets = (inputs.sum(1, keepdim=True) > 10).float().sub(.5).mul(20)
# tensor([[-10.],
# [ 10.],
# [-10.],
# [-10.],
# [-10.],
# [ 10.],
# [ 10.],
# [-10.],
# [-10.],
# [ 10.]])
型号
import os
from pprint import pprint
import torch
from torch import nn
class Model2D(nn.Module):
CHECKPOINT_DIR = './checkpoints'
def __init__(self):
super().__init__()
self.layer_1 = nn.Linear(in_features=2, out_features=4)
self.layer_2 = nn.Linear(in_features=4, out_features=2)
self.layer_3 = nn.Linear(in_features=2, out_features=1)
def forward(self, x: torch.Tensor) -> torch.Tensor:
return self.layer_3(self.layer_2(self.layer_1(x)))
def save(self):
torch.save(obj=self.state_dict(),
f=f"{self.CHECKPOINT_DIR}/Model2D.pth")
def load(self):
if (os.path.isfile(f"{self.CHECKPOINT_DIR}/Model2D.pth")):
self.load_state_dict(torch.load(f"{self.CHECKPOINT_DIR}/Model2D.pth"))
print("The checkpoints loaded with the following values for weights and bias: ")
pprint(self.state_dict())
这是Train loss和Test loss
问题是我的模型没有学到更多。我认为这是因为层的数量/类型。
有人可以帮助我提供一些改进模型的技巧吗?
我记得妈妈说:去读书吧! 这对我有用,如果你愿意,我可以将她的联系方式发送到你的人工智能模型......