# PyTorch 写法
class MLP(torch.nn.Module):
def __init__(self, input_size, hidden_size, output_size):
super(MLP, self).__init__()
self.fc1 = torch.nn.Linear(input_size, hidden_size)
with torch.no_grad():
self.fc1.weight.fill_(1.0)
self.fc1.bias.fill_(0.1)
def forward(self, x):
x = self.fc1(x)
return x
# Paddle 写法
class MLP(paddle.nn.Layer):
def __init__(self, input_size, hidden_size, output_size):
super(MLP, self).__init__()
self.fc1 = paddle.nn.Linear(in_features=input_size, out_features=hidden_size)
with paddle.no_grad():
self.fc1.weight.fill_(1.0)
self.fc1.bias.fill_(0.1)
def forward(self, x):
x = self.fc1(x)
return x