赞
踩
【持续更新中…】
from torch.autograd import Variable
作用:自动微分变量,用于构建计算图
设尺寸为N*C*H*W,其中N代表batchsize,C表示通道数(例如RGB三通道),H,W分别表示feature map的宽高。
torch.nn.BatchNorm2d(num_features, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True, device=None, dtype=None)
torch.nn.Linear(in_features: int, out_features: int, bias: bool = True, device=None, dtype=None)
self.conv4 = torch.nn.Sequential(
torch.nn.Conv2d(64, 64, 2, 2, 0),
torch.nn.BatchNorm2d(64),
torch.nn.ReLU()#ReLU激活函数)
self.mlp1 = torch.nn.Linear(2 * 2 * 64, 100)#torch.nn.Linear定义全连接层,conv4为2*2*64
self.mlp2 = torch.nn.Linear(100, 10)
argparse是一个Python模块:命令行选项、参数和子命令解析器。
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('integers', metavar='N', type=int, nargs='+', help='an integer for the accumulator')
例如在神经网络训练过程中,我们需要定义训练的初始学习率,并设置默认值为0.00001,可通过以下代码实现:
parser.add_argument('--learning-rate', '-l', metavar='LR', type=float, default=1e-5,
help='Learning rate', dest='lr')
args = parser.parse_args()
torch.max(out,1)[1]
output = torch.max(input, dim)
函数会返回两个tensor,第一个tensor是每行的最大值;第二个tensor是每行最大值的索引。
(PS:第一个tensor value
是不需要的,我们仅提取第二个tensor并将数据转换为array格式)
torch.max(out,1)[1].numpy()
model_dict=torch.load('D:\JetBrains\pythonProject\CMRI\CNN\CNN_Log')
parameters=list(model_dict.named_parameters())
在CNN中,汇合层(Pooling layer)通过max pooling 或average pooling等操作,使汇合后结果中一个元素对应于原输入数据的一个子区域,因此汇合操作实际上就是一种”降采样“操作
常用方法:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。