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

百度营销官网河北网站seo优化

百度营销官网,河北网站seo优化,龙岩app制作,呼和浩特市手机网站知识点回顾#xff1a; 随机种子内参的初始化神经网络调参指南 参数的分类调参的顺序各部分参数的调整心得 import torch import numpy as np import os import random# 全局随机函数 def set_seed(seed42, deterministicTrue):设置全局随机种子#xff0… 知识点回顾 随机种子内参的初始化神经网络调参指南 参数的分类调参的顺序各部分参数的调整心得 import torch import numpy as np import os import random# 全局随机函数 def set_seed(seed42, deterministicTrue):设置全局随机种子确保实验可重复性参数:seed: 随机种子值默认为42deterministic: 是否启用确定性模式默认为True# 设置Python的随机种子random.seed(seed) os.environ[PYTHONHASHSEED] str(seed) # 确保Python哈希函数的随机性一致比如字典、集合等无序# 设置NumPy的随机种子np.random.seed(seed)# 设置PyTorch的随机种子torch.manual_seed(seed) # 设置CPU上的随机种子torch.cuda.manual_seed(seed) # 设置GPU上的随机种子torch.cuda.manual_seed_all(seed) # 如果使用多GPU# 配置cuDNN以确保结果可重复if deterministic:torch.backends.cudnn.deterministic Truetorch.backends.cudnn.benchmark False# 设置随机种子 set_seed(42) import torch import torch.nn as nn import matplotlib.pyplot as plt import numpy as np# 设置设备 device torch.device(cuda:0 if torch.cuda.is_available() else cpu)# 定义极简CNN模型仅1个卷积层1个全连接层 class SimpleCNN(nn.Module):def __init__(self):super(SimpleCNN, self).__init__()# 卷积层输入3通道输出16通道卷积核3x3self.conv1 nn.Conv2d(3, 16, kernel_size3, padding1)# 池化层2x2窗口尺寸减半self.pool nn.MaxPool2d(kernel_size2)# 全连接层展平后连接到10个输出对应10个类别# 输入尺寸16通道 × 16x16特征图 16×16×164096self.fc nn.Linear(16 * 16 * 16, 10)def forward(self, x):# 卷积池化x self.pool(self.conv1(x)) # 输出尺寸: [batch, 16, 16, 16]# 展平x x.view(-1, 16 * 16 * 16) # 展平为: [batch, 4096]# 全连接x self.fc(x) # 输出尺寸: [batch, 10]return x# 初始化模型 model SimpleCNN() model model.to(device)# 查看模型结构 print(model)# 查看初始权重统计信息 def print_weight_stats(model):# 卷积层conv_weights model.conv1.weight.dataprint(\n卷积层 权重统计:)print(f 均值: {conv_weights.mean().item():.6f})print(f 标准差: {conv_weights.std().item():.6f})print(f 理论标准差 (Kaiming): {np.sqrt(2/3):.6f}) # 输入通道数为3# 全连接层fc_weights model.fc.weight.dataprint(\n全连接层 权重统计:)print(f 均值: {fc_weights.mean().item():.6f})print(f 标准差: {fc_weights.std().item():.6f})print(f 理论标准差 (Kaiming): {np.sqrt(2/(16*16*16)):.6f})# 改进的可视化权重分布函数 def visualize_weights(model, layer_name, weights, save_pathNone):plt.figure(figsize(12, 5))# 权重直方图plt.subplot(1, 2, 1)plt.hist(weights.cpu().numpy().flatten(), bins50)plt.title(f{layer_name} 权重分布)plt.xlabel(权重值)plt.ylabel(频次)# 权重热图plt.subplot(1, 2, 2)if len(weights.shape) 4: # 卷积层权重 [out_channels, in_channels, kernel_size, kernel_size]# 只显示第一个输入通道的前10个滤波器w weights[:10, 0].cpu().numpy()plt.imshow(w.reshape(-1, weights.shape[2]), cmapviridis)else: # 全连接层权重 [out_features, in_features]# 只显示前10个神经元的权重重塑为更合理的矩形w weights[:10].cpu().numpy()# 计算更合理的二维形状尝试接近正方形n_features w.shape[1]side_length int(np.sqrt(n_features))# 如果不能完美整除添加零填充使能重塑if n_features % side_length ! 0:new_size (side_length 1) * side_lengthw_padded np.zeros((w.shape[0], new_size))w_padded[:, :n_features] ww w_padded# 重塑并显示plt.imshow(w.reshape(w.shape[0] * side_length, -1), cmapviridis)plt.colorbar()plt.title(f{layer_name} 权重热图)plt.tight_layout()if save_path:plt.savefig(f{save_path}_{layer_name}.png)plt.show()# 打印权重统计 print_weight_stats(model)# 可视化各层权重 visualize_weights(model, Conv1, model.conv1.weight.data, initial_weights) visualize_weights(model, FC, model.fc.weight.data, initial_weights)# 可视化偏置 plt.figure(figsize(12, 5))# 卷积层偏置 conv_bias model.conv1.bias.data plt.subplot(1, 2, 1) plt.bar(range(len(conv_bias)), conv_bias.cpu().numpy()) plt.title(卷积层 偏置)# 全连接层偏置 fc_bias model.fc.bias.data plt.subplot(1, 2, 2) plt.bar(range(len(fc_bias)), fc_bias.cpu().numpy()) plt.title(全连接层 偏置)plt.tight_layout() plt.savefig(biases_initial.png) plt.show()print(\n偏置统计:) print(f卷积层偏置 均值: {conv_bias.mean().item():.6f}) print(f卷积层偏置 标准差: {conv_bias.std().item():.6f}) print(f全连接层偏置 均值: {fc_bias.mean().item():.6f}) print(f全连接层偏置 标准差: {fc_bias.std().item():.6f}) 浙大疏锦行
http://www.hkea.cn/news/14340865/

相关文章:

  • 云南住房和城乡建设厅网站南阳微网站开发
  • ppt怎么做网站c 怎么做网站开发
  • 市桥做网站有网站源码去哪里做
  • 团队建设游戏网站什么是ui界面设计
  • 肥西县建设局官方网站商丘专业做网站公司
  • 免费推广网站58吉林建设厅网站首页
  • 黑龙江省住房和建设厅网站微信公众号功能开发
  • 企业网站软件下载交互设计主要做什么
  • iis配置wap网站tradekey外贸平台官网
  • 学生做网站教程安康建设网站
  • 删负面的网站选择seo网站排名优化
  • 网站备案 二级域名网站建设需要用到的技术
  • 不让在建设门户网站wordpress收录提高
  • 网站系统cms石狮app网站开发哪家好
  • 哈尔滨网站建设哪儿好薇网站链群怎么做
  • 做一个网站放网上要多少钱宁波软件开发公司排名
  • 做网站哪里wordpress评论显示数字ip
  • 鹿泉外贸网站建设汕头seo管理
  • 广州比较好的网站设计微信小程序app
  • 专做洗衣柜的网站建行网址多少
  • 网络建设服务与网站运营推广青岛seo霸屏
  • 网站升级中 html域名到期换个公司做网站
  • 网站如何提交百度收录ninety ajax wordpress
  • 威海临港区建设局网站下载网站怎么下载
  • 制作网站的步骤和过程网站升级改造建设方案
  • 搜狗短链接生成长沙专业seo优化推荐
  • 推广简短吸引人的话厦门seo代理商
  • 企业网站 静态页面怎样创建网站域名平台
  • 模板网站的建设方式与方法包装设计价格
  • php中网站搜索功能实现平台网址怎么查询