「Deep Learning」理解Pytorch中的「torch.nn.functional」

Sina Weibo:小锋子Shawn
Tencent E-mail:[email protected]
http://blog.csdn.net/dgyuanshaofeng/article/details/79875282

torch.nn里面有各种“layer”,torch.nn.functional里面有类似的。两者的区别和关系,在我看来,类似于Keras里面的序贯式模型和函数式模型。举例来说:
1、nn里面的conv1d层

import torch
import torch.nn as nn
from torch.autograd import Variable
m = nn.Conv1d(16, 33, 3, stride=2)
# 16: input_channel; 33:output_channel
input = Variable(torch.randn(20, 16, 50))
output = m(input) # 20x33x24

2、functional里面的conv1d函数

import torch
import torch.nn.functional as F
from torch.autograd import Variable
filters = Variable(torch.randn(33, 16, 3))
# 16: input_channel; 33:output_channel
inputs = Variable(torch.randn(20, 16, 50))
F.conv1d(inputs, filters, stride=2)

你可能感兴趣的:(「Deep Learning」理解Pytorch中的「torch.nn.functional」)