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

360网站备案查询快速排名优化推广价格

360网站备案查询,快速排名优化推广价格,威海城乡与住房建设部网站,网络安全培训机构排名神经网络调参指南 知识点回顾: 随机种子内参的初始化神经网络调参指南 参数的分类调参的顺序各部分参数的调整心得 参数可视化 import torch import torch.nn as nn import matplotlib.pyplot as plt import numpy as np# 设置设备 device torch.device("cud…

神经网络调参指南

知识点回顾:

  1. 随机种子
  2. 内参的初始化
  3. 神经网络调参指南
    1. 参数的分类
    2. 调参的顺序
    3. 各部分参数的调整心得

参数可视化

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_size=3, padding=1)# 池化层:2x2窗口,尺寸减半self.pool = nn.MaxPool2d(kernel_size=2)# 全连接层:展平后连接到10个输出(对应10个类别)# 输入尺寸:16通道 × 16x16特征图 = 16×16×16=4096self.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_path=None):plt.figure(figsize=(12, 5))# 权重直方图plt.subplot(1, 2, 1)plt.hist(weights.cpu().numpy().flatten(), bins=50)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]), cmap='viridis')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), cmap='viridis')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}")

指南

1. 参数初始化----有预训练的参数直接起飞

2. batchsize---测试下能允许的最高值

3. epoch---这个不必多说,默认都是训练到收敛位置,可以采取早停策略

4. 学习率与调度器----收益最高,因为鞍点太多了,模型越复杂鞍点越多

5. 模型结构----消融实验或者对照试验

6. 损失函数---选择比较少,试出来一个即可,高手可以自己构建

7. 激活函数---选择同样较少

8. 正则化参数---主要是droupout,等到过拟合了用,上述所有步骤都为了让模型过拟合

http://www.ds6.com.cn/news/102584.html

相关文章:

  • 佛山新网站建设方案权重查询站长工具
  • 昆明网站建设SEO公司常州网站推广
  • 怎么做网站图片seo灵感关键词生成器
  • 深圳网站开发专业网盘资源
  • 机械配件网站建设百度广告推广费用年费
  • 怎么访问域名网站吗杭州seo 云优化科技
  • 网站防止挂马应该怎么做百度竞价是什么意思?
  • 东莞市门户网站建设怎么样个人网页怎么做
  • wordpress 加载流程优化大师是干什么的
  • 网站地图页面设计网络公司推广公司
  • 太原市网站建设网站上海网络公司seo
  • 怎样开发一个网站2345网址导航浏览器
  • 汇鑫网站建设seo快速建站
  • 代理记账如何获取客户优化培训学校
  • 湛江哪家公司建网站最好怎么制作网页推广
  • 网站上做旅游卖家要学什么软件佛山seo培训机构
  • wordpress数据库容量seo推广排名公司
  • 深圳服装设计学院seo推广培训资料
  • 做脚奴网站简述企业网站推广的一般策略
  • 楚雄市网站建设公司不知怎么入门
  • 网站建设公司的市场开发方案站长工具域名解析
  • seo移动网站页面怎么做培训总结精辟句子
  • wordpress 后台管理设置seo网站推广公司
  • 网站seo怎么做运营推广计划
  • 外贸网站免费模板关键词挖掘工具网站
  • 互动网站建设新闻发布会新闻通稿
  • 做网站需要注意哪些代推广平台
  • 自己怎么做点击量好的网站百度一下了你就知道官网
  • 做网站的素材和步骤大学生网页设计作业
  • 嘉兴网站建设服务营销推广网站