import torch as t
from torch.autograd import Variable as V
from torch import nn
input= V(t.randn(2,3))
model = nn.Linear(3,4)
output1 = model(input)
output2 = nn.functional.linear(input,model.weight,model.bias)
b1 = nn.functional.relu(input)
b2 = nn.ReLU()(input)print(b1==b2)
import torch as t
from torch.autograd import Variable as V
from torch import nn
from torch.nn import functional as F
classNet(nn.Module):def__init__(self):super(Net,self).__init__()
self.conv1 = nn.Conv2d(3,6,5)
self.conv2 = nn.Conv2d(6,16,5)
self.fc1 = nn.Linear(16*5*5,120)
self.fc2 = nn.Linear(120,84)
self.fc3 = nn.Linear(84,10)defforward(self, x):
x = F.pool(F.relu(self.conv1(x)),2)# 池化窗口2*2
x = F.pool(F.relu(self.conv2(x)),2)
x = x.view(-1,16*5*5)
x = F.relu(self.fc1)
x = F.relu(self.fc2)
x = self.fc3(x)return x