代码注意事项
1、参数配置
[-1, 1, module, [512, 256, 128, 1]]----->[from, number, module, args]
from:是从哪里接,-1就是代表上一层,-2就是上上层,具体数字就是具体哪一层。
number:就是重复来几次。
args:就是module的参数,注意module的第一个输入参数来自于“from”。
例如:[-1, 1, RepNCSPELAN4, [512, 256, 128, 1]]中的RepNCSPELAN4函数(类),输入参数为[上一层结果,512, 256, 128, 1]。
2、优化器使用
output= model(input)
# 计算损失函数
loss = model.criterion(output, target)
# 清空梯度
model.opt.zero_grad()
loss.backward()
# 根据优化器更新权重
model.opt.step()
3、卷积层分裂方法
a, b = list(x.chunk(2, 1))
a = x[:, :(x.shape[1] // 2), :, :]
b = x[:, (x.shape[1] // 2):, :, :]
4、卷积层堆叠
torch.cat((a, b), 1)
5、 __call__()
方法的作用其实是把一个类的实例化对象变成了可调用对象,也就是说把一个类的实例化对象变成了可调用对象。