【Bug已解决】Pytorch What‘s the difference between define layer in __init__() and directly use in… 解决方案
【Bug已解决】Pytorch Whats the difference between define layer ininit() and directly use in forward()? 解决方案问题描述在 PyTorch 中定义神经网络模型时许多初学者尤其是从 Keras/TensorFlow 迁移过来的开发者经常会混淆两种层定义方式方式一在__init__()中定义层class Model(nn.Module): def __init__(self): super().__init__() self.fc nn.Linear(10, 5) # 在 __init__ 中定义 def forward(self, x): return self.fc(x) # 在 forward 中使用方式二在forward()中直接创建层class Model(nn.Module): def __init__(self): super().__init__() def forward(self, x): fc nn.Linear(10, 5) # 在 forward 中直接创建 return fc(x)这两种方式看起来都能工作但存在根本性的差异。方式二会导致模型参数不被注册到state_dict()无法保存和加载优化器找不到参数无法进行梯度更新每次 forward 都重新创建层导致参数随机初始化模型永远无法学习模型结构无法通过print(model)正确显示无法使用model.to(device)将参数移动到 GPU本文将系统分析这两种方式的区别解释其底层原理并提供完整的对比代码。错误复现错误 1在 forward 中创建层导致参数不注册import torch import torch.nn as nn class BadModel(nn.Module): def __init__(self): super().__init__() def forward(self, x): # 错误在 forward 中创建层 fc nn.Linear(10, 5) return fc(x) model BadModel() # 检查参数 print(参数数量:, len(list(model.parameters()))) # 0没有参数被注册 print(state_dict:, model.state_dict()) # 空字典 # 尝试训练 optimizer torch.optim.SGD(model.parameters(), lr0.01) x torch.randn(3, 10) y torch.randn(3, 5) for epoch in range(3): optimizer.zero_grad() output model(x) loss nn.MSELoss()(output, y) loss.backward() optimizer.step() print(fEpoch {epoch1}, Loss: {loss.item():.4f}) # Loss 不会下降因为 optimizer 管理的参数列表为空错误 2每次 forward 参数都不同class BadModel2(nn.Module): def __init__(self): super().__init__() def forward(self, x): fc nn.Linear(10, 5) return fc(x) model BadModel2() x torch.randn(1, 10) # 同样的输入两次 forward 结果不同 out1 model(x) out2 model(x) print(两次输出是否相同:, torch.equal(out1, out2)) # False # 因为每次 forward 都创建新的随机初始化的 Linear 层错误 3无法保存和加载模型class BadModel3(nn.Module): def __init__(self): super().__init__() def forward(self, x): self.fc nn.Linear(10, 5) # 即使赋值给 self也不被正确注册 return self.fc(x) model BadModel3() x torch.randn(1, 10) model(x) # 前向传播后 fc 才存在 # 尝试保存 torch.save(model.state_dict(), bad_model.pth) # 保存的是空字典因为 fc 不是在 __init__ 中注册的 nn.Module # 加载到新模型 new_model BadModel3() new_model.load_state_dict(torch.load(bad_model.pth)) # RuntimeError: Error(s) in loading state_dict - 没有键可以加载根因分析1. PyTorch 的模块注册机制PyTorch 的nn.Module通过__setattr__方法自动追踪子模块和参数。当你在__init__()中执行self.fc nn.Linear(10, 5)时nn.Module.__setattr__被调用检测到赋值的是nn.Module类型将fc注册到self._modules字典中fc的参数自动被model.parameters()包含fc出现在model.state_dict()中而在forward()中创建的层不会经过这个注册流程除非你显式调用add_module因此不会被追踪。2. 参数生命周期定义位置参数创建时机参数生命周期参数是否可训练__init__()模型实例化时与模型同生命周期是forward()每次 forward 调用单次 forward 调用否每次新建3. 优化器的参数管理# 优化器在创建时获取参数列表的引用 optimizer torch.optim.SGD(model.parameters(), lr0.01) # model.parameters() 返回的是 __init__ 中注册的参数 # forward 中创建的参数不在其中因此不会被优化器更新4.nn.functional的区别torch.nn.functional中的函数如F.linear、F.conv2d是无状态的操作它们不创建可学习参数。如果你在forward中使用F.linear需要自己管理权重class FunctionalModel(nn.Module): def __init__(self): super().__init__() # 在 __init__ 中定义参数 self.weight nn.Parameter(torch.randn(5, 10)) self.bias nn.Parameter(torch.randn(5)) def forward(self, x): # 在 forward 中使用 functional API return F.linear(x, self.weight, self.bias)这是正确的做法——参数在__init__中定义forward中只做计算。解决方案方案一标准方式——在__init__中定义所有层推荐class CorrectModel(nn.Module): def __init__(self, input_dim, hidden_dim, output_dim): super().__init__() # 所有有可学习参数的层都在 __init__ 中定义 self.fc1 nn.Linear(input_dim, hidden_dim) self.bn1 nn.BatchNorm1d(hidden_dim) self.fc2 nn.Linear(hidden_dim, hidden_dim) self.bn2 nn.BatchNorm1d(hidden_dim) self.fc3 nn.Linear(hidden_dim, output_dim) self.dropout nn.Dropout(0.3) def forward(self, x): x torch.relu(self.bn1(self.fc1(x))) x self.dropout(x) x torch.relu(self.bn2(self.fc2(x))) x self.dropout(x) return self.fc3(x)方案二使用nn.functional配合__init__中的参数import torch.nn.functional as F class FunctionalModel(nn.Module): def __init__(self, input_dim, hidden_dim, output_dim): super().__init__() # 参数在 __init__ 中定义 self.w1 nn.Parameter(torch.randn(hidden_dim, input_dim) * 0.01) self.b1 nn.Parameter(torch.zeros(hidden_dim)) self.w2 nn.Parameter(torch.randn(output_dim, hidden_dim) * 0.01) self.b2 nn.Parameter(torch.zeros(output_dim)) def forward(self, x): x F.relu(F.linear(x, self.w1, self.b1)) return F.linear(x, self.w2, self.b2)方案三使用nn.Sequential容器class SequentialModel(nn.Module): def __init__(self, input_dim, hidden_dim, output_dim): super().__init__() self.features nn.Sequential( nn.Linear(input_dim, hidden_dim), nn.BatchNorm1d(hidden_dim), nn.ReLU(), nn.Dropout(0.3), nn.Linear(hidden_dim, hidden_dim), nn.BatchNorm1d(hidden_dim), nn.ReLU(), nn.Dropout(0.3), ) self.classifier nn.Linear(hidden_dim, output_dim) def forward(self, x): x self.features(x) return self.classifier(x)方案四动态层——使用nn.ModuleList或nn.ModuleDict当层的数量或结构是动态的使用nn.ModuleListclass DynamicModel(nn.Module): def __init__(self, input_dim, hidden_dims, output_dim): super().__init__() # 使用 ModuleList 存储可变数量的层 layers [] prev_dim input_dim for hidden_dim in hidden_dims: layers.append(nn.Linear(prev_dim, hidden_dim)) layers.append(nn.BatchNorm1d(hidden_dim)) layers.append(nn.ReLU()) prev_dim hidden_dim self.layers nn.ModuleList(layers) self.output nn.Linear(prev_dim, output_dim) def forward(self, x): for layer in self.layers: x layer(x) return self.output(x)完整修复代码以下是一个完整的对比示例展示正确和错误的层定义方式及其影响import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torch.utils.data import DataLoader, TensorDataset import time # 错误示例 class WrongModel(nn.Module): 错误在 forward 中创建层 def __init__(self): super().__init__() def forward(self, x): fc1 nn.Linear(100, 256) fc2 nn.Linear(256, 10) x torch.relu(fc1(x)) return fc2(x) # 正确示例 class CorrectModel(nn.Module): 正确在 __init__ 中定义层 def __init__(self): super().__init__() self.fc1 nn.Linear(100, 256) self.fc2 nn.Linear(256, 10) def forward(self, x): x torch.relu(self.fc1(x)) return self.fc2(x) class FunctionalStyleModel(nn.Module): 正确使用 functional API __init__ 中的参数 def __init__(self): super().__init__() self.w1 nn.Parameter(torch.randn(256, 100) * (1.0 / 100 ** 0.5)) self.b1 nn.Parameter(torch.zeros(256)) self.w2 nn.Parameter(torch.randn(10, 256) * (1.0 / 256 ** 0.5)) self.b2 nn.Parameter(torch.zeros(10)) def forward(self, x): x F.relu(F.linear(x, self.w1, self.b1)) return F.linear(x, self.w2, self.b2) class SequentialStyleModel(nn.Module): 正确使用 Sequential 容器 def __init__(self): super().__init__() self.features nn.Sequential( nn.Linear(100, 256), nn.ReLU(), nn.Dropout(0.3), nn.Linear(256, 256), nn.ReLU(), nn.Dropout(0.3), ) self.classifier nn.Linear(256, 10) def forward(self, x): x self.features(x) return self.classifier(x) class DynamicLayerModel(nn.Module): 正确使用 ModuleList 处理动态层 def __init__(self, input_dim100, hidden_dims[256, 128], output_dim10): super().__init__() layers [] prev_dim input_dim for h_dim in hidden_dims: layers.append(nn.Linear(prev_dim, h_dim)) layers.append(nn.BatchNorm1d(h_dim)) layers.append(nn.ReLU()) prev_dim h_dim self.layers nn.ModuleList(layers) self.output_layer nn.Linear(prev_dim, output_dim) def forward(self, x): for layer in self.layers: x layer(x) return self.output_layer(x) # 对比测试 def compare_models(): 对比不同层定义方式的差异 print( * 70) print(对比不同层定义方式) print( * 70) models { WrongModel (forward中创建): WrongModel(), CorrectModel (__init__中定义): CorrectModel(), FunctionalStyleModel (functional参数): FunctionalStyleModel(), SequentialStyleModel (Sequential): SequentialStyleModel(), DynamicLayerModel (ModuleList): DynamicLayerModel(), } x torch.randn(5, 100) for name, model in models.items(): print(f\n--- {name} ---) # 参数数量 num_params sum(p.numel() for p in model.parameters()) num_trainable sum(p.numel() for p in model.parameters() if p.requires_grad) print(f 总参数量: {num_params}) print(f 可训练参数量: {num_trainable}) # state_dict sd model.state_dict() print(f state_dict 键数量: {len(sd)}) if len(sd) 0: print(f state_dict 键: {list(sd.keys())[:5]}...) else: print(f state_dict 为空!) # 前向传播 try: out model(x) print(f 前向传播输出形状: {out.shape}) except Exception as e: print(f 前向传播失败: {e}) # 模型结构 print(f 模型结构:) for line in str(model).split(\n): print(f {line}) def test_training(): 测试训练效果对比 print(\n * 70) print(训练效果对比) print( * 70) # 准备数据 torch.manual_seed(42) X torch.randn(500, 100) y torch.randint(0, 10, (500,)) dataset TensorDataset(X, y) dataloader DataLoader(dataset, batch_size32, shuffleTrue) # 测试正确模型 print(\n--- 正确模型 (CorrectModel) ---) model CorrectModel() optimizer optim.Adam(model.parameters(), lr0.001) criterion nn.CrossEntropyLoss() for epoch in range(5): total_loss 0 correct 0 total 0 for batch_x, batch_y in dataloader: optimizer.zero_grad() output model(batch_x) loss criterion(output, batch_y) loss.backward() optimizer.step() total_loss loss.item() correct output.argmax(1).eq(batch_y).sum().item() total batch_y.size(0) print(f Epoch {epoch1}: Loss{total_loss/len(dataloader):.4f}, fAcc{100.*correct/total:.2f}%) # 测试错误模型 print(\n--- 错误模型 (WrongModel) ---) wrong_model WrongModel() optimizer_wrong optim.Adam(wrong_model.parameters(), lr0.001) for epoch in range(5): total_loss 0 correct 0 total 0 for batch_x, batch_y in dataloader: optimizer_wrong.zero_grad() output wrong_model(batch_x) loss criterion(output, batch_y) loss.backward() optimizer_wrong.step() total_loss loss.item() correct output.argmax(1).eq(batch_y).sum().item() total batch_y.size(0) print(f Epoch {epoch1}: Loss{total_loss/len(dataloader):.4f}, fAcc{100.*correct/total:.2f}%) print( (Loss 不下降因为参数没有被优化器管理)) def test_save_load(): 测试保存和加载 print(\n * 70) print(保存和加载测试) print( * 70) # 正确模型 print(\n--- 正确模型 ---) model CorrectModel() x torch.randn(1, 100) out_before model(x) torch.save(model.state_dict(), correct_model.pth) print(f 保存的 state_dict 键: {list(model.state_dict().keys())}) new_model CorrectModel() new_model.load_state_dict(torch.load(correct_model.pth, weights_onlyTrue)) out_after new_model(x) print(f 加载后输出一致: {torch.allclose(out_before, out_after)}) # 错误模型 print(\n--- 错误模型 ---) wrong_model WrongModel() wrong_model(x) # 触发 forward torch.save(wrong_model.state_dict(), wrong_model.pth) print(f 保存的 state_dict: {wrong_model.state_dict()}) print( (空字典无法保存任何参数)) def test_reproducibility(): 测试前向传播的可重复性 print(\n * 70) print(前向传播可重复性测试) print( * 70) x torch.randn(1, 100) # 正确模型 model CorrectModel() model.eval() with torch.no_grad(): out1 model(x) out2 model(x) print(f正确模型 - 两次输出相同: {torch.allclose(out1, out2)}) # 错误模型 wrong_model WrongModel() with torch.no_grad(): out1 wrong_model(x) out2 wrong_model(x) print(f错误模型 - 两次输出相同: {torch.allclose(out1, out2)}) print( (不同因为每次 forward 都创建新的随机层)) def test_device_transfer(): 测试设备迁移 print(\n * 70) print(设备迁移测试) print( * 70) device torch.device(cuda if torch.cuda.is_available() else cpu) # 正确模型 model CorrectModel() model model.to(device) x torch.randn(1, 100).to(device) out model(x) print(f正确模型 - 输出设备: {out.device}) # 错误模型 wrong_model WrongModel() wrong_model wrong_model.to(device) x torch.randn(1, 100).to(device) try: out wrong_model(x) print(f错误模型 - 输出设备: {out.device}) print( (forward 中创建的层在 CPU 上可能导致设备不匹配错误)) except Exception as e: print(f错误模型 - 运行失败: {e}) # 何时可以在 forward 中使用层 def demonstrate_acceptable_forward_usage(): 演示在 forward 中可以接受的使用方式 print(\n * 70) print(forward 中可接受的使用方式) print( * 70) # 1. 使用 nn.functional无状态操作 class FunctionalModel(nn.Module): def __init__(self): super().__init__() self.weight nn.Parameter(torch.randn(5, 10)) self.bias nn.Parameter(torch.zeros(5)) def forward(self, x): # F.relu 是无状态的可以在 forward 中使用 return F.relu(F.linear(x, self.weight, self.bias)) # 2. 使用无参数的层 class NoParamLayerModel(nn.Module): def __init__(self): super().__init__() self.fc nn.Linear(10, 5) def forward(self, x): # Dropout 和 ReLU 在 eval 模式下无参数 # 但最好也在 __init__ 中定义以保持一致性 dropout nn.Dropout(0.5) return dropout(torch.relu(self.fc(x))) # 3. 条件执行不同的层 class ConditionalModel(nn.Module): def __init__(self): super().__init__() self.fc1 nn.Linear(10, 20) self.fc2 nn.Linear(10, 20) self.fc_out nn.Linear(20, 5) def forward(self, x, use_fc1True): # 条件选择已定义的层不是创建新层 if use_fc1: x self.fc1(x) else: x self.fc2(x) return self.fc_out(torch.relu(x)) print(1. nn.functional 无状态操作 - 可以在 forward 中使用) print(2. 无参数层如 Dropout- 可以但不推荐在 forward 中创建) print(3. 条件选择已定义的层 - 完全正确) print(4. 创建有参数的新层 - 绝对错误) # 主程序 def main(): print(PyTorch 层定义方式对比__init__() vs forward()) print( * 70) # 对比模型 compare_models() # 训练效果 test_training() # 保存加载 test_save_load() # 可重复性 test_reproducibility() # 设备迁移 test_device_transfer() # 可接受的 forward 用法 demonstrate_acceptable_forward_usage() print(\n * 70) print(总结) print( * 70) print( 核心规则 - 所有有可学习参数的层必须在 __init__() 中定义 - forward() 中只做计算不创建新的有参数层 - 使用 nn.functional API 时参数也应在 __init__() 中定义 - 无参数操作如 F.relu, F.dropout可以在 forward 中直接使用 - 动态层结构使用 nn.ModuleList 或 nn.ModuleDict ) if __name__ __main__: main()常见陷阱与注意事项1.nn.ReLUvsF.relu# nn.ReLU 是一个模块有状态应在 __init__ 中定义 class Model(nn.Module): def __init__(self): super().__init__() self.fc nn.Linear(10, 5) self.relu nn.ReLU() # 在 __init__ 中定义 def forward(self, x): return self.relu(self.fc(x)) # F.relu 是一个函数无状态可以在 forward 中直接使用 class Model2(nn.Module): def __init__(self): super().__init__() self.fc nn.Linear(10, 5) def forward(self, x): return F.relu(self.fc(x)) # 直接使用无需在 __init__ 中定义2. Dropout 的特殊性# nn.Dropout 虽然无可学习参数但有训练/评估模式状态 # 最好在 __init__ 中定义 class Model(nn.Module): def __init__(self): super().__init__() self.fc nn.Linear(10, 5) self.dropout nn.Dropout(0.5) # 在 __init__ 中定义 def forward(self, x): return self.dropout(self.fc(x)) # F.dropout 也可以在 forward 中使用但需手动指定 training 参数 class Model2(nn.Module): def __init__(self): super().__init__() self.fc nn.Linear(10, 5) def forward(self, x): return F.dropout(self.fc(x), p0.5, trainingself.training)3. BatchNorm 的状态# BatchNorm 有 running_mean, running_var 等缓冲区 # 必须在 __init__ 中定义否则这些统计量不会被追踪 class Model(nn.Module): def __init__(self): super().__init__() self.fc nn.Linear(10, 5) self.bn nn.BatchNorm1d(5) # 必须在 __init__ 中 def forward(self, x): return self.bn(self.fc(x))4. 动态创建层的正确方式# 如果层结构依赖输入使用 nn.ModuleList 预定义所有可能的层 class DynamicModel(nn.Module): def __init__(self): super().__init__() # 预定义所有可能用到的层 self.layers nn.ModuleList([ nn.Linear(10, 20) for _ in range(5) ]) def forward(self, x, layer_idx): # 根据条件选择已定义的层 return self.layers[layer_idx](x)5. 自定义层中的子层class CustomLayer(nn.Module): def __init__(self, in_dim, out_dim): super().__init__() # 自定义层内部的子层也必须在 __init__ 中定义 self.fc nn.Linear(in_dim, out_dim) self.bn nn.BatchNorm1d(out_dim) def forward(self, x): return self.bn(self.fc(x)) # 使用自定义层 class Model(nn.Module): def __init__(self): super().__init__() self.layer1 CustomLayer(100, 256) # 在 __init__ 中定义 self.layer2 CustomLayer(256, 10) def forward(self, x): return self.layer2(torch.relu(self.layer1(x)))总结在 PyTorch 中定义层的核心规则有参数的层必须在__init__()中定义nn.Linear、nn.Conv2d、nn.BatchNorm等有可学习参数的层必须在__init__中创建才能被parameters()和state_dict()追踪。forward()中只做计算forward 函数应该只使用已定义的层进行前向计算不创建新的有参数层。nn.functional是无状态替代F.relu、F.dropout、F.linear等函数不需要在__init__中定义但使用F.linear时权重参数仍需在__init__中定义。动态结构用ModuleList当层结构是动态的使用nn.ModuleList或nn.ModuleDict在__init__中预定义所有层。错误方式的后果在 forward 中创建层会导致参数不注册、模型不可训练、无法保存加载、前向传播不可重复。无参数层也建议在__init__中定义虽然nn.ReLU、nn.Dropout无可学习参数但为了一致性和正确的模式管理建议在__init__中定义。理解这一区别是正确使用 PyTorch 构建神经网络的基础也是从 Keras 迁移到 PyTorch 时最需要注意的概念之一。

相关新闻

面向教学的数字摄影测量工作站:让相对定向、核线与DEM生成都看得见

面向教学的数字摄影测量工作站:让相对定向、核线与DEM生成都看得见

简介:E-FOTO 是一个面向教学的数字摄影测量工作站项目,采用免费开源方式提供软件与学习材料,旨在帮助学生理解摄影测量原理。这份 DOC 文档围绕项目理念、主要模块与开发进展展开,属于典型的教学/技术资料。文档共1个文件&#xf…

2026/10/15 14:30:40 阅读更多 →
18650锂电池热失控仿真模型技术解析与应用

18650锂电池热失控仿真模型技术解析与应用

1. 项目背景与核心价值18650锂电池作为目前应用最广泛的圆柱形锂离子电池,其热安全问题一直是行业关注的焦点。热失控(Thermal Runaway)是指电池在过热情况下发生的不可控连锁反应,可能引发起火甚至爆炸。我们团队开发的5.6版本热…

2026/10/15 14:30:40 阅读更多 →
【Bug已解决】Tensorflow: Hierarchical Softmax Implementation 解决方案

【Bug已解决】Tensorflow: Hierarchical Softmax Implementation 解决方案

【Bug已解决】Tensorflow: Hierarchical Softmax Implementation 解决方案 问题描述 在自然语言处理(NLP)和大规模分类任务中,词汇表(vocabulary)通常非常庞大,动辄数万甚至数十万。传统的 softmax 函数在计…

2026/10/15 14:30:40 阅读更多 →

最新新闻

基于YOLOv8/YOLOv10/YOLOv11/YOLOv12与SpringBoot的麻将识别检测系统(DeepSeek智能分析+web交互界面+前后端分离+YOLO数据)

基于YOLOv8/YOLOv10/YOLOv11/YOLOv12与SpringBoot的麻将识别检测系统(DeepSeek智能分析+web交互界面+前后端分离+YOLO数据)

摘要 随着中国传统智力游戏数字化发展的深入推进,麻将作为极具代表性的国粹文化,其智能化识别与分析技术具有重要的应用价值。本研究设计并实现了一套基于深度学习与现代化Web架构的麻将牌智能识别系统,专门针对42种标准麻将牌型进行高精度检…

2026/10/15 15:17:01 阅读更多 →
基于Django的民宿预订系统开发实践与架构设计

基于Django的民宿预订系统开发实践与架构设计

1. 项目背景与核心价值民宿预订系统是近年来共享经济浪潮下的典型应用场景。与传统酒店管理系统不同,民宿业务具有房源分散、房型多样、房东自主管理等特点,这对系统的灵活性和扩展性提出了更高要求。基于Django框架开发民宿预订系统,能够充分…

2026/10/15 15:17:01 阅读更多 →
SpringBoot+Vue构建智慧养老健康监测系统实践

SpringBoot+Vue构建智慧养老健康监测系统实践

1. 项目背景与核心价值随着全球老龄化进程加速,老年人健康管理已成为社会关注焦点。传统健康监测方式存在数据分散、响应滞后等痛点,而基于SpringBootVue的远程监控系统正好填补了这一市场空白。这个毕设选题编号14066的项目,实际上瞄准了一个…

2026/10/15 15:17:01 阅读更多 →
别再问“哪个AI最能写”了:AI专业做毕设,真正该按环节挑工具(TaoToken 统一 Key 版)

别再问“哪个AI最能写”了:AI专业做毕设,真正该按环节挑工具(TaoToken 统一 Key 版)

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/15 15:17:01 阅读更多 →
BIC极大手性效应:原理、仿真与应用

BIC极大手性效应:原理、仿真与应用

1. 项目背景与核心概念在电磁学和光子学领域,Bound states in the continuum(BIC)和手性光学效应是近年来备受关注的两个前沿研究方向。BIC指的是一种特殊的光学模式,尽管其能量位于连续谱中,却能表现出局域态的特性。…

2026/10/15 15:17:01 阅读更多 →
DiffiT实战:用视觉Transformer替代U-Net的扩散模型训练与调优

DiffiT实战:用视觉Transformer替代U-Net的扩散模型训练与调优

简介:DiffiT是NVIDIA团队提出的一种将视觉变换器引入扩散模型的图像生成新架构,面向生成式AI研究者、计算机视觉方向学生及扩散模型开发者,用于解决传统去噪网络过度依赖卷积残差U-Net、注意力机制设计缺乏统一范式的问题。资源包内含1个PDF文…

2026/10/15 15:16:00 阅读更多 →

日新闻

Docker Compose 容器化部署 ChirpStack LoRaWAN 网络服务器实战

Docker Compose 容器化部署 ChirpStack LoRaWAN 网络服务器实战

1. 为什么选择容器化方式部署 LoRa 网络服务LoRa 物联网项目落地时,网络服务器是整个链路的核心枢纽。它负责接收网关上报的数据包、完成去重与解密、再把有效载荷分发给上层应用。早期大家习惯把网络服务器直接装在物理机上,依赖一堆系统库和特定版本的…

2026/10/15 0:00:46 阅读更多 →
共享LLM服务下的跨模型自动扩缩容:Kubernetes实战与避坑指南

共享LLM服务下的跨模型自动扩缩容:Kubernetes实战与避坑指南

1. 共享推理服务里,扩缩容到底难在哪做过大模型推理服务部署的人,大概都经历过这样的场景:一个团队共用一套推理集群,A 业务跑的是 7B 的小模型,B 业务跑的是 72B 的大模型,C 业务白天流量高、晚上几乎归零…

2026/10/15 0:00:46 阅读更多 →
Systemd 启动阶段根文件系统只读之谜:fstab 与 remount-fs 服务深度解析

Systemd 启动阶段根文件系统只读之谜:fstab 与 remount-fs 服务深度解析

1. 引子:一次内核恐慌引发的追查先从一个真实场景说起。某次我给一台老旧的嵌入式设备折腾系统裁减,为了把启动时间压进两秒以内,我手贱地把一串自认为“没用”的 systemd 服务给 disable 了,其中就包括systemd-remount-fs.servic…

2026/10/15 0:00:46 阅读更多 →

周新闻

流感时间序列预测实战:ARIMA/LSTM全流程拆解与避坑指南

流感时间序列预测实战:ARIMA/LSTM全流程拆解与避坑指南

简介:基于 ARIMA、LSTM、Transformer 等模型的流感时间序列预测 Python 源码,面向计算机相关专业课程设计与期末大作业学生,以及项目实战学习者。内容覆盖预处理、平稳性检验、定阶、残差分析、多模型对比预测的完整时序建模流程,…

2026/10/14 3:30:28 阅读更多 →
影刀RPA新手教程:键盘模拟输入实战——输入文本与模拟按键的区别

影刀RPA新手教程:键盘模拟输入实战——输入文本与模拟按键的区别

影刀RPA新手教程:键盘模拟输入实战——输入文本与模拟按键的区别 做影刀RPA自动化,十个新手有八个栽在"往输入框里填东西"这件事上:要么填不进去,要么填了一半,要么直接把原来内容追加在后面。这背后的根因&…

2026/10/14 16:30:29 阅读更多 →
影刀RPA新手教程:阅文起点小说数据采集实战——书籍信息与章节内容

影刀RPA新手教程:阅文起点小说数据采集实战——书籍信息与章节内容

影刀RPA新手教程:阅文起点小说数据采集实战——书籍信息与章节内容 1. 认识影刀:什么场景该用RPA采小说数据 起点中文网的页面结构相对稳定——分类榜单、书籍详情、章节内容三块独立页面,跳转链路清晰。这种场景非常适合影刀自动化&#x…

2026/10/15 13:48:15 阅读更多 →

月新闻

我发现了一个新思路:用 Remotion + Claude Code 像写代码一样自动化生成短视频

我发现了一个新思路:用 Remotion + Claude Code 像写代码一样自动化生成短视频

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/15 0:14:36 阅读更多 →
Windows下 Codex 中 Chrome 和 Computer Use 插件不可用问题排查及解决参考方式:TaoToken 统一 Key 配置与验证

Windows下 Codex 中 Chrome 和 Computer Use 插件不可用问题排查及解决参考方式:TaoToken 统一 Key 配置与验证

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/14 22:45:47 阅读更多 →
黑夜航拍船只数据集训练YOLOV5模型全流程解析

黑夜航拍船只数据集训练YOLOV5模型全流程解析

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/15 9:49:14 阅读更多 →