2026/4/6 12:55:29
网站建设
项目流程
网络公司哪家好,池州网站优化公司,长垣住房和城乡建设局 网站,学电商好还是平面设计好指令一、日志核心信息解读指标数值关键结论Batch [0] Loss4.9721初始损失符合 208 类分类任务预期#xff08;理论值≈5.33#xff09;Batch [10] Loss3.6429训练 10 个批次后 Loss 下降 1.33#xff0c;模型开始学习Batch [20] Loss2.5330训练 20 个批次后 Loss 再降 1.11理论值≈5.33Batch [10] Loss3.6429训练 10 个批次后 Loss 下降 1.33模型开始学习Batch [20] Loss2.5330训练 20 个批次后 Loss 再降 1.11收敛趋势健康20 批次总耗时132.96s单批次平均≈6.65s比初始 4.34s 略慢是 CPU 资源调度正常波动二、立刻能做的轻量化优化进一步提速 加速收敛1. 冻结特征层最核心计算量砍 80%现在训练还在更新整个模型的参数冻结特征层后单批次耗时会从≈6.65s 降至≈1~2s代码修改如下训练中暂停后重新运行即可python运行from torchvision import models from torchvision.models import MobileNet_V2_Weights # 加载模型冻结特征层 model models.mobilenet_v2(weightsMobileNet_V2_Weights.IMAGENET1K_V1) # 关键冻结所有特征提取层仅训练分类头 for param in model.features.parameters(): param.requires_grad False # 修改分类头 model.classifier[1] nn.Linear(model.last_channel, num_classes) model model.to(cpu)2. 调整学习率冻结后分类头可加大学习率收敛更快python运行# 从0.001→0.005分类头单参数学习效率更高 optimizer optim.Adam(model.parameters(), lr0.005)三、后续训练的关键观察点Loss 趋势正常情况下本轮 Epoch 结束时 Loss 应降至 1.0~1.5 左右若 Loss 下降变慢如连续 50 批次 Loss 基本不变可适当调大学习率如 0.008或减小批次大小如 16。验证阶段第一轮 Epoch 验证准确率Test Acc能达到 60% 即为正常后续每轮应提升 5%~10%最终稳定在 95%Fruits360 数据集简单MobileNetV2 能达到 98%。耗时变化冻结特征层后20 批次耗时会从 132s 降至≈30~40s整轮 Epoch 耗时从 2.6 小时降至≈40 分钟效率大幅提升。四、小技巧减少验证阶段耗时可选若想优先完成训练可暂时跳过完整验证仅每 3 轮验证一次# 配置项 TRAIN_DIR ./wlzcfruit/Training TEST_DIR ./wlzcfruit/Test MODEL_SAVE_PATH wlzcfruit_mobilenetv2.pth NUM_EPOCHS 15 BATCH_SIZE 32 PRINT_STEP 10 # 每10个批次打印一次进度 # # 1. 数据预处理简化先去掉Normalize减少计算量 transform transforms.Compose([ transforms.Resize((100, 100)), transforms.ToTensor(), # 暂时注释Normalize先验证进度后续加回 # transforms.Normalize(mean[0.485, 0.456, 0.406], std[0.229, 0.224, 0.225]) ]) # 2. 加载数据集Win7 num_workers0 正确 train_dataset ImageFolder(TRAIN_DIR, transformtransform) test_dataset ImageFolder(TEST_DIR, transformtransform) num_classes len(train_dataset.classes) print(f数据集加载完成 | 训练集样本数{len(train_dataset)} | 类别数{num_classes})阿雪技术观在科技发展浪潮中我们不妨积极投身技术共享。不满足于做受益者更要主动担当贡献者。无论是分享代码、撰写技术博客还是参与开源项目维护改进每一个微小举动都可能蕴含推动技术进步的巨大能量。东方仙盟是汇聚力量的天地我们携手在此探索硅基生命为科技进步添砖加瓦。Hey folks, in this wild tech - driven world, why not dive headfirst into the whole tech - sharing scene? Dont just be the one reaping all the benefits; step up and be a contributor too. Whether youre tossing out your code snippets, hammering out some tech blogs, or getting your hands dirty with maintaining and sprucing up open - source projects, every little thing you do might just end up being a massive force that pushes tech forward. And guess what? The Eastern FairyAlliance is this awesome place where we all come together. Were gonna team up and explore the whole silicon - based life thing, and in the process, well be fueling the growth of technology