当前位置: 首页 > news >正文

8有免费建网站网站设计视频

8有免费建网站,网站设计视频,淘宝客网站一定要备案吗,wordpress cpu 100%三 模型创建与nn.Module 3.1 nn.Module 模型构建两要素#xff1a; 构建子模块——__init()__拼接子模块——forward#xff08;#xff09; 一个module可以有多个module#xff1b; 一个module相当于一个运算#xff0c;都必须实现forward函数#xff1b; 每一个mod…三 模型创建与nn.Module 3.1 nn.Module 模型构建两要素 构建子模块——__init()__拼接子模块——forward 一个module可以有多个module 一个module相当于一个运算都必须实现forward函数 每一个module有8个字典管理属性。 self._parameters OrderedDict() self._buffers OrderedDict() self._backward_hooks OrderedDict() self._forward_hooks OrderedDict() self._forward_pre_hooks OrderedDict() self._state_dict_hooks OrderedDict() self._load_state_dict_pre_hooks OrderedDict() self._modules OrderedDict() 3.2 网络容器 nn.Sequential() 是nn.Module()的一个容器用于按照顺序包装一组网络层 顺序性网络层之间严格按照顺序构建 自带forward 各网络层之间严格按顺序执行常用于block构建 class LeNetSequential(nn.Module): def __init__(self, classes): super(LeNetSequential, self).__init__() self.features nn.Sequential( nn.Conv2d(3, 6, 5), nn.ReLU(), nn.MaxPool2d(kernel_size2, stride2), nn.Conv2d(6, 16, 5), nn.ReLU(), nn.MaxPool2d(kernel_size2, stride2),) self.classifier nn.Sequential( nn.Linear(16*5*5, 120), nn.ReLU(), nn.Linear(120, 84), nn.ReLU(), nn.Linear(84, classes),) def forward(self, x): x self.features(x) x x.view(x.size()[0], -1) x self.classifier(x) return x nn.ModuleList() 是nn.Module的容器用于包装网络层以迭代方式调用网络层。 主要方法 append()在ModuleList后面添加网络层 extend:拼接两个ModuleList. Insert():指定在ModuleList中插入网络层。 nn.ModuleList迭代性常用于大量重复网构建通过for循环实现重复构建 class ModuleList(nn.Module): def __init__(self): super(ModuleList, self).__init__() self.linears nn.ModuleList([nn.Linear(10, 10) for i in range(20)]) def forward(self, x): for i, linear in enumerate(self.linears): x linear(x) return x nn.ModuleDict() 以索引方式调用网络层 主要方法 • clear()清空ModuleDict • items()返回可迭代的键值对(key-value pairs) • keys()返回字典的键(key) • values()返回字典的值(value) • pop()返回一对键值并从字典中删除 n.ModuleDict索引性常用于可选择的网络层 class ModuleDict(nn.Module): def __init__(self): super(ModuleDict, self).__init__() self.choices nn.ModuleDict({ conv: nn.Conv2d(10, 10, 3), pool: nn.MaxPool2d(3) }) self.activations nn.ModuleDict({ relu: nn.ReLU(), prelu: nn.PReLU() }) def forward(self, x, choice, act): x self.choices[choice](x) x self.activations[act](x) return x 3.3卷积层 nn.ConV2d() nn.Conv2d(in_channels, out_channels,kernel_size, stride1,padding0, dilation1, groups1, biasTrue, padding_modezeros) in_channels输入通道数比如RGB图像是3而后续的网络层的输入通道数为前一卷积层的输出通道数 out_channels输出通道数等价于卷积核个数 kernel_size卷积核尺寸 stride步 padding填充个数 dilation空洞卷积大小 groups分组卷积设置 bias偏置 conv_layer nn.Conv2d(3, 1, 3)   # input:(i, o, size) weights:(o, i , h, w) nn.init.xavier_normal_(conv_layer.weight.data) # calculation img_conv conv_layer(img_tensor) 这里使用 input*channel 为 3output_channel 为 1 卷积核大小为 3×3 的卷积核nn.Conv2d(3, 1, 3)使用nn.init.xavier_normal*()方法初始化网络的权值。 我们通过conv_layer.weight.shape查看卷积核的 shape 是(1, 3, 3, 3)对应是(output_channel, input_channel, kernel_size, kernel_size)。所以第一个维度对应的是卷积核的个数每个卷积核都是(3,3,3)。虽然每个卷积核都是 3 维的执行的却是 2 维卷积。 转置卷积nn.ConvTranspose2d 转置卷积又称为反卷积(Deconvolution)和部分跨越卷积(Fractionally-stridedConvolution) 用于对图像进行上采样(UpSample) 为什么称为转置卷积 假设图像尺寸为4*4卷积核为3*3padding0stride1 正常卷积 转置卷积 假设图像尺寸为2*2卷积核为3*3padding0stride1 nn.ConvTranspose2d(in_channels, out_channels, kernel_size, stride1, padding0, output_padding0, groups1, biasTrue, dilation1, padding_modezeros) 输出尺寸计算 # flag 1 flag 0 if flag: conv_layer nn.ConvTranspose2d(3, 1, 3, stride2)   # input:(i, o, size) nn.init.xavier_normal_(conv_layer.weight.data) # calculation img_conv conv_layer(img_tensor) print(卷积前尺寸:{}\n卷积后尺寸:{}.format(img_tensor.shape, img_conv.shape)) img_conv transform_invert(img_conv[0, 0:1, ...], img_transform) img_raw transform_invert(img_tensor.squeeze(), img_transform) plt.subplot(122).imshow(img_conv, cmapgray) plt.subplot(121).imshow(img_raw) plt.show() 3.4池化层nn.MaxPool2d nn.AvgPool2d 池化运算对信号进行 “收集”并 “总结”类似水池收集水资源因而 得名池化层 “收集”多变少 “总结”最大值/平均值 nn.MaxPool2d nn.MaxPool2d(kernel_size, strideNone, padding0, dilation1, return_indicesFalse, ceil_modeFalse) 主要参数 • kernel_size池化核尺寸 • stride步长 • padding 填充个数 • dilation池化核间隔大小 • ceil_mode尺寸向上取整 • return_indices记录池化像素索引 # flag 1 flag 0 if flag: maxpool_layer nn.MaxPool2d((2, 2), stride(2, 2))   # input:(i, o, size) weights:(o, i , h, w) img_pool maxpool_layer(img_tensor) nn.AvgPool2d nn.AvgPool2d(kernel_size, strideNone, padding0, ceil_modeFalse, count_include_padTrue, divisor_overrideNone) 主要参数 • kernel_size池化核尺寸 • stride步长 • padding 填充个数 • ceil_mode尺寸向上取整 • count_include_pad填充值用于计算 • divisor_override 除法因子 avgpoollayer nn.AvgPool2d((2, 2), stride(2, 2))   # input:(i, o, size) weights:(o, i , h, w) img_pool avgpoollayer(img_tensor) img_tensor torch.ones((1, 1, 4, 4)) avgpool_layer nn.AvgPool2d((2, 2), stride(2, 2), divisor_override3) img_pool avgpool_layer(img_tensor) print(raw_img:\n{}\npooling_img:\n{}.format(img_tensor, img_pool)) nn.MaxUnpool2d 功能对二维信号图像进行最大值池化 上采样 主要参数 • kernel_size池化核尺寸 • stride步长 • padding 填充个数 # pooling img_tensor torch.randint(high5, size(1, 1, 4, 4), dtypetorch.float) maxpool_layer nn.MaxPool2d((2, 2), stride(2, 2), return_indicesTrue) img_pool, indices maxpool_layer(img_tensor) # unpooling img_reconstruct torch.randn_like(img_pool, dtypetorch.float) maxunpool_layer nn.MaxUnpool2d((2, 2), stride(2, 2)) img_unpool maxunpool_layer(img_reconstruct, indices) print(raw_img:\n{}\nimg_pool:\n{}.format(img_tensor, img_pool)) print(img_reconstruct:\n{}\nimg_unpool:\n{}.format(img_reconstruct, img_unpool)) 3.5线性层 nn.Linear(in_features, out_features, biasTrue) 功能对一维信号向量进行线性组合 主要参数 • in_features输入结点数 • out_features输出结点数 • bias 是否需要偏置 计算公式y s inputs torch.tensor([[1., 2, 3]]) linear_layer nn.Linear(3, 4) linear_layer.weight.data torch.tensor([[1., 1., 1.], [2., 2., 2.], [3., 3., 3.], [4., 4., 4.]]) linear_layer.bias.data.fill_(0.5) output linear_layer(inputs) print(inputs, inputs.shape) print(linear_layer.weight.data, linear_layer.weight.data.shape) print(output, output.shape) 3.6 激活函数层 nn.Sigmoid nn.tanh: nn.ReLU nn.LeakyReLU negative_slope: 负半轴斜率 nn.PReLU init: 可学习斜率 nn.RReLU lower: 均匀分布下限 upper:均匀分布上限 参考资料 深度之眼课程
http://www.hkea.cn/news/14328666/

相关文章:

  • 网站开发 京东网站制作北京海淀
  • net网站建设教程长沙百度推广排名
  • 松原网站建设公司电话刀客源码
  • 辽宁自助网站建设公司东莞网站优化快速排名
  • 做化妆品网站的原因重庆建设安全管理网站
  • 免费养殖网站模板Wordpress 悬浮菜单
  • 在建工程查询网站网站开发提案模板
  • 空间 网站都有 肿么做网站PHP文件加到WordPress页面
  • 湖北省建设规划网站哪家做网站
  • 400电话网络推广微信网站触屏手机网站建设
  • 整站系统建设网站管理规定
  • 做国外销售都上什么网站wordpress 获取子页面
  • 基于php技术的个人网站设计企业需要缴纳哪些税
  • 浙江嘉兴建设局网站怎么注册中文域名
  • 微商城网站建设平台合同范本互联网营销和传统营销的区别
  • 网站内容与功能模块设计重庆网站建设套餐
  • 电子商务网站用户协议营销型网站建设申请域名时公司类型的域名后缀一般是
  • 网站制作(信科网络)做网站赚钱交税
  • 布吉网站建设找哪家公司比较好摄影网站建设的功能有哪些
  • 咖啡网站建设网络搭建教程
  • 山西旅游网站建设从化营销型网站建设
  • 快速构建网站建设电子商务网站的目的
  • 世代网络高端企业网站建设设计功能公司营销宣传文案
  • 做微信公众号必备的网站小程序推广公司
  • 怎样才能创建网站网站 广州
  • 网站盈利了如何建立微网站详细步骤
  • 做暧暧的网站平面设计基础学什么
  • 襄樊建设网站湖南建设人力资源网证书查询
  • 物业公司网站模板淮北矿业集团工程建设公司网站
  • 我想做卖鱼苗网站怎样做迁移wordpress 500