torch.nn
(1)用于搭建网络结构的序列容器:torch.nn.Sequential
models = torch.nn.Sequential( torch.nn.Linear(input_data, hidden_layer), torch.nn.ReLU(), torch.nn.Linear(hidden_layer, output_data) ) from collections import OrderedDict # 使用有序字典 使模块有自定义的名次 models2 = torch.nn.Sequential(OrderedDict([ ("Line1",torch.nn.Linear(input_data, hidden_layer)), ("ReLu1",torch.nn.ReLU()), ("Line2",torch.nn.Linear(hidden_layer, output_data))]) )
(2)线性层:torch.nn.Linear
(3)激活函数:torch.nn.ReLU
(4)损失函数:torch.nn.MSELoss(均方误差函数),troch.nn.L1Loss(平均绝对误差函数),torch.nn.CrossEntropyLoss(交叉熵)
原文地址:https://www.cnblogs.com/zuhaoran/p/11458440.html
时间: 2024-11-01 16:51:10