1 Star 0 Fork 0

焦建军/good_robot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mlp.py 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
esteng 提交于 2021-03-16 10:16 . pre-pull
import torch
class MLP(torch.nn.Module):
def __init__(self,
input_dim: int,
hidden_dim: int,
output_dim: int,
num_layers: int,
activation: torch.nn.Module = torch.nn.ReLU(),
dropout: float = 0.20
):
super(MLP, self).__init__()
self.input_dim = input_dim
self.hidden_dim = hidden_dim
self.output_dim = output_dim
self.num_layers = num_layers
self.activation = activation
self.dropout = dropout
dropout_layer = torch.nn.Dropout(dropout)
layer0 = torch.nn.Linear(input_dim, hidden_dim)
self.layers = [layer0, self.activation, dropout_layer]
for i in range(self.num_layers-1):
layer_i = torch.nn.Linear(hidden_dim, hidden_dim)
self.layers += [layer_i, self.activation, dropout_layer]
layer_n = torch.nn.Linear(hidden_dim, output_dim)
self.layers.append(layer_n)
self.layers = torch.nn.ModuleList(self.layers)
def forward(self, inputs):
outputs = inputs
for i, layer in enumerate(self.layers):
outputs = layer(outputs)
return outputs
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jiaojianjun-com/good_robot.git
git@gitee.com:jiaojianjun-com/good_robot.git
jiaojianjun-com
good_robot
good_robot
master

搜索帮助