神经网络构建

 

构建数据集:

网络搭建:

class nn(nn.Module):
    def __init__(self):
        super(nn, self).__init__()
        self.nets = nn.Sequential(
            # 网络细节
# 针对单元(图像···)
)
def forward(self, x):
# 针对批数据batch
# 如Conv2d的输入尺度为 [batch_size, channels, height, weight] x
= self.nets(x)return x

 

训练:

loss = nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)

train_pred = model(data[0].cuda())
train_loss = loss(train_label, data[1].cuda())
train_loss.backward()
optimizer.step()

 

posted @ 2019-11-15 20:50  Junzhao  阅读(204)  评论(0)    收藏  举报