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

自建网站怎么做后台管理系统教育类php开源网站

自建网站怎么做后台管理系统,教育类php开源网站,wordpress 变小程序,刚刚发生了一件大事1.特征图可视化#xff0c;这种方法是最简单#xff0c;输入一张照片#xff0c;然后把网络中间某层的输出的特征图按通道作为图片进行可视化展示即可。 2.特征图可视化代码如下#xff1a; def featuremap_visual(feature, out_dirNone, # 特征图保存路径文件save_feat…1.特征图可视化这种方法是最简单输入一张照片然后把网络中间某层的输出的特征图按通道作为图片进行可视化展示即可。 2.特征图可视化代码如下 def featuremap_visual(feature, out_dirNone, # 特征图保存路径文件save_featureTrue, # 是否以图片形式保存特征图show_featureTrue, # 是否使用plt显示特征图feature_titleNone, # 特征图名字默认以shape作为titlenum_ch-1, # 显示特征图前几个通道-1 or None 都显示nrow8, # 每行显示多少个特征图通道padding10, # 特征图之间间隔多少像素值pad_value1 # 特征图之间的间隔像素):import matplotlib.pylab as pltimport torchvisionimport os# feature feature.detach().cpu()b, c, h, w feature.shapefeature feature[0]feature feature.unsqueeze(1)if c num_ch 0:feature feature[:num_ch]img torchvision.utils.make_grid(feature, nrownrow, paddingpadding, pad_valuepad_value)img img.detach().cpu()img img.numpy()images img.transpose((1, 2, 0))# title str(images.shape) if feature_title is None else str(feature_title)title str(hwc-) str(h) - str(w) - str(c) if feature_title is None else str(feature_title)plt.title(title)plt.imshow(images)if save_feature:# rootrC:\Users\Administrator\Desktop\CODE_TJ\123# plt.savefig(os.path.join(root,1.jpg))out_root title .jpg if out_dir or out_dir is None else os.path.join(out_dir, title .jpg)plt.savefig(out_root)if show_feature: plt.show()3.结合resnet网络整体可视化(主要将其featuremap_visual函数插入forward中即可)整体代码如下 resnet网络结构在我博客 残差网络ResNet(超详细代码解析) :你必须要知道backbone模块成员之一 - tangjunjun - 博客园 author: tangjun contact: 511026664qq.com time: 2020/12/7 22:48 desc: 残差ackbone改写用于构建特征提取模块 import torch.nn as nn import torch from collections import OrderedDictdef Conv(in_planes, out_planes, **kwargs):3x3 convolution with paddingpadding kwargs.get(padding, 1)bias kwargs.get(bias, False)stride kwargs.get(stride, 1)kernel_size kwargs.get(kernel_size, 3)out nn.Conv2d(in_planes, out_planes, kernel_sizekernel_size, stridestride, paddingpadding, biasbias)return outclass BasicBlock(nn.Module):expansion 1def __init__(self, inplanes, planes, stride1, downsampleNone):super(BasicBlock, self).__init__()self.conv1 Conv(inplanes, planes, stridestride)self.bn1 nn.BatchNorm2d(planes)self.relu nn.ReLU(inplaceTrue)self.conv2 Conv(planes, planes)self.bn2 nn.BatchNorm2d(planes)self.downsample downsampleself.stride stridedef forward(self, x):residual xout self.conv1(x)out self.bn1(out)out self.relu(out)out self.conv2(out)out self.bn2(out)if self.downsample is not None:residual self.downsample(x)out residualout self.relu(out)return outclass Bottleneck(nn.Module):expansion 4def __init__(self, inplanes, planes, stride1, downsampleNone):super(Bottleneck, self).__init__()self.conv1 nn.Conv2d(inplanes, planes, kernel_size1, biasFalse)self.bn1 nn.BatchNorm2d(planes)self.conv2 nn.Conv2d(planes, planes, kernel_size3, stridestride,padding1, biasFalse)self.bn2 nn.BatchNorm2d(planes)self.conv3 nn.Conv2d(planes, planes * 4, kernel_size1, biasFalse)self.bn3 nn.BatchNorm2d(planes * 4)self.relu nn.ReLU(inplaceTrue)self.downsample downsampleself.stride stridedef forward(self, x):residual xout self.conv1(x)out self.bn1(out)out self.relu(out)out self.conv2(out)out self.bn2(out)out self.relu(out)out self.conv3(out)out self.bn3(out)if self.downsample is not None:residual self.downsample(x)out residualout self.relu(out)return outclass Resnet(nn.Module):arch_settings {18: (BasicBlock, (2, 2, 2, 2)),34: (BasicBlock, (3, 4, 6, 3)),50: (Bottleneck, (3, 4, 6, 3)),101: (Bottleneck, (3, 4, 23, 3)),152: (Bottleneck, (3, 8, 36, 3))}def __init__(self,depth50,in_channelsNone,pretrainedNone,frozen_stages-1# num_classesNone):super(Resnet, self).__init__()self.inplanes 64self.inchannels in_channels if in_channels is not None else 3 # 输入通道# self.num_classesnum_classesself.block, layers self.arch_settings[depth]self.frozen_stages frozen_stagesself.conv1 nn.Conv2d(self.inchannels, 64, kernel_size7, stride2, padding3, biasFalse)self.bn1 nn.BatchNorm2d(64)self.relu nn.ReLU(inplaceTrue)self.maxpool nn.MaxPool2d(kernel_size3, stride2, padding1)self.layer1 self._make_layer(self.block, 64, layers[0], stride1)self.layer2 self._make_layer(self.block, 128, layers[1], stride2)self.layer3 self._make_layer(self.block, 256, layers[2], stride2)self.layer4 self._make_layer(self.block, 512, layers[3], stride2)# self.avgpool nn.AvgPool2d(7)# self.fc nn.Linear(512 * self.block.expansion, self.num_classes)self._freeze_stages() # 冻结函数if pretrained is not None:self.init_weights(pretrainedpretrained)def _freeze_stages(self):if self.frozen_stages 0:self.norm1.eval()for m in [self.conv1, self.norm1]:for param in m.parameters():param.requires_grad Falsefor i in range(1, self.frozen_stages 1):m getattr(self, layer{}.format(i))m.eval()for param in m.parameters():param.requires_grad Falsedef init_weights(self, pretrainedNone):if isinstance(pretrained, str):self.load_checkpoint(pretrained)elif pretrained is None:for m in self.modules():if isinstance(m, nn.Conv2d):nn.init.kaiming_normal_(m.weight, a0, modefan_out, nonlinearityrelu)if hasattr(m, bias) and m.bias is not None: # m包含该属性且m.bias非None # hasattr(对象属性)表示对象是否包含该属性nn.init.constant_(m.bias, 0)elif isinstance(m, nn.BatchNorm2d):m.weight.data.fill_(1)m.bias.data.zero_()def load_checkpoint(self, pretrained):checkpoint torch.load(pretrained)if isinstance(checkpoint, OrderedDict):state_dict checkpointelif isinstance(checkpoint, dict) and state_dict in checkpoint:state_dict checkpoint[state_dict]if list(state_dict.keys())[0].startswith(module.):state_dict {k[7:]: v for k, v in checkpoint[state_dict].items()}unexpected_keys [] # 保存checkpoint不在module中的keymodel_state self.state_dict() # 模型变量for name, param in state_dict.items(): # 循环遍历pretrained的权重if name not in model_state:unexpected_keys.append(name)continueif isinstance(param, torch.nn.Parameter):# backwards compatibility for serialized parametersparam param.datatry:model_state[name].copy_(param) # 试图赋值给模型except Exception:raise RuntimeError(While copying the parameter named {}, whose dimensions in the model are {} not equal whose dimensions in the checkpoint are {}..format(name, model_state[name].size(), param.size()))missing_keys set(model_state.keys()) - set(state_dict.keys())print(missing_keys:, missing_keys)def _make_layer(self, block, planes, num_blocks, stride1):downsample Noneif stride ! 1 or self.inplanes ! planes * block.expansion:downsample nn.Sequential(nn.Conv2d(self.inplanes, planes * block.expansion, kernel_size1, stridestride, biasFalse),nn.BatchNorm2d(planes * block.expansion),)layers []layers.append(block(self.inplanes, planes, stride, downsample))self.inplanes planes * block.expansionfor i in range(1, num_blocks):layers.append(block(self.inplanes, planes))return nn.Sequential(*layers)def forward(self, x):outs []x self.conv1(x)x self.bn1(x)x self.relu(x)x self.maxpool(x)x self.layer1(x)outs.append(x)featuremap_visual(x)x self.layer2(x)outs.append(x)featuremap_visual(x)x self.layer3(x)outs.append(x)featuremap_visual(x)x self.layer4(x)outs.append(x)# x self.avgpool(x)# x x.view(x.size(0), -1)# x self.fc(x)return tuple(outs)def featuremap_visual(feature,out_dirNone, # 特征图保存路径文件save_featureTrue, # 是否以图片形式保存特征图show_featureTrue, # 是否使用plt显示特征图feature_titleNone, # 特征图名字默认以shape作为titlenum_ch-1, # 显示特征图前几个通道-1 or None 都显示nrow8, # 每行显示多少个特征图通道padding10, # 特征图之间间隔多少像素值pad_value1 # 特征图之间的间隔像素):import matplotlib.pylab as pltimport torchvisionimport os# feature feature.detach().cpu()b, c, h, w feature.shapefeature feature[0]feature feature.unsqueeze(1)if c num_ch 0:feature feature[:num_ch]img torchvision.utils.make_grid(feature, nrownrow, paddingpadding, pad_valuepad_value)img img.detach().cpu()img img.numpy()images img.transpose((1, 2, 0))# title str(images.shape) if feature_title is None else str(feature_title)title str(hwc-) str(h) - str(w) - str(c) if feature_title is None else str(feature_title)plt.title(title)plt.imshow(images)if save_feature:# rootrC:\Users\Administrator\Desktop\CODE_TJ\123# plt.savefig(os.path.join(root,1.jpg))out_root title .jpg if out_dir or out_dir is None else os.path.join(out_dir, title .jpg)plt.savefig(out_root)if show_feature: plt.show()import cv2 import numpy as npdef imnormalize(img,mean[123.675, 116.28, 103.53],std[58.395, 57.12, 57.375],to_rgbTrue):if to_rgb:img cv2.cvtColor(img, cv2.COLOR_BGR2RGB)img img.astype(np.float32)return (img - mean) / stdif __name__ __main__:import matplotlib.pylab as pltimg cv2.imread(1.jpg) # 读取图片img imnormalize(img)img torch.from_numpy(img)img torch.unsqueeze(img, 0)img img.permute(0, 3, 1, 2)img torch.tensor(img, dtypetorch.float32)img img.to(cuda:0)model Resnet(depth50)model.init_weights(pretrained./resnet50.pth) # 可以使用也可以注释model model.cuda()out model(img)运行结果 参考 PyTorch模型训练特征图可视化 - tangjunjun - 博客园 (cnblogs.com)
http://www.yayakq.cn/news/3961/

相关文章:

  • 肥东住房和城乡建设部网站人力资源公司代缴社保合法吗
  • wordpress咋建站建网站定制
  • 在网站文字上做超链接php网站开发好找工作吗
  • 建设银行官方网站4399网页游戏开服表
  • 企业品牌类网站有哪些做网站策划容易遇到哪些问题
  • 曲周企业做网站推广WordPress哪些主题是免费的
  • 网站做一半能退吗合肥专业网站优化哪家好
  • .net网站开发实例食品建设网站的目的
  • 专门做品牌网站设计服务wordpress+怎么改密码
  • 那些知名网站是外包做的一流的商城网站建设
  • 余姚网站建设设计图片加字制作免费
  • 免备案网站建设WordPress 标签 模板
  • 网站群发软文软件西安软件开发公司排行
  • 网站建设与管理试题及答案关键词和网站的关系
  • 银川住房和城乡建设局网站佛山用户网站建站
  • 网站建设案例好么品牌网站如何做seo
  • 在线作图网站如何生成网站
  • 网站建设确认报告平度城乡建设局网站
  • 国内最大的开源网站自己制作头像的网站 设计 动漫
  • 石家庄 外贸网站建设公司网站开发人员的 生活
  • app开发公司需要多少人兰州网站优化哪家好
  • 360平台怎么做网站优化wordpress响应式商场
  • 买网站送域名php做图片交互网站代码
  • 网站建设 三网wordpress 发短信
  • 洛宁网站开发网站服务器如何维护
  • 销售网站建设赚钱吗网络货运怎么做的
  • 自适应网站模版哈尔滨精品建站
  • 自媒体采集网站建设国外flash网站模板
  • 简单大方网站外链查询工具
  • WordPress主题中文主题合肥网站推广优化公司