作用: 类似于reshape(),改变tensor变量维度。
用法:
import torch #一般用法 b=torch.randn(3,2) #3*2矩阵 print(b) print(b.view(1,6)) #变成1*6矩阵 print(b.view(6,1)) ##变成6*1矩阵 #传入数字-1,自动对维度进行变换 a=torch.randn(3,5,2) print(a) print(a.view(3,1,-1).size()) #将a转化成3*1*n形状矩阵,n由系统自动调整二、继承nn.Module
想要在自己定义的NET中调用那些常用的conv等等和模块,就必须继承自nn.Module;如果你的Net定义了__init__()方法,则必须在你的__init__方法中调用nn.Module的构造函数,比如super(your_class).__init__() ,注意,如果你的子类没有定义__init__()方法,则在实例化的时候会默认用nn.Module的,这种情况也对。
class CivilNet(nn.Module):
def __init__(self):
super(CivilNet, self).__init__()
conv1 = nn.Conv2d(3, 6, 5)
pool = nn.MaxPool2d(2, 2)
conv2 = nn.Conv2d(6, 16, 5)
...



