码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 知识蒸馏 pytorch官网源码分析


    参考连接:

    Knowledge Distillation Tutorial — PyTorch Tutorials 2.2.1+cu121 documentation

    方法一  :    

    知识蒸馏的损失函数只接受两个相同维度的输入,所以我们需要采取措施使他们在进入损失函数之前是相同维度的。我们将使用平均池化层对在教师模型卷积运算后的logits进行池化,使得logits维度和学生保持一样。

    方法二:

    原来的教师模型:

    只有forward函数内有调整

    1. class DeepNN(nn.Module):
    2. def forward(self, x):
    3. x = self.features(x)
    4. x = torch.flatten(x, 1)
    5. x = self.classifier(x)
    6. return x

    加入了池化后的教师模型:

    1. class ModifiedDeepNNCosine(nn.Module):
    2. def forward(self, x):
    3. x = self.features(x)
    4. flattened_conv_output = torch.flatten(x, 1)
    5. x = self.classifier(flattened_conv_output)
    6. flattened_conv_output_after_pooling = torch.nn.functional.avg_pool1d(flattened_conv_output, 2)
    7. return x, flattened_conv_output_after_pooling

    原来的学生模型

    1. class LightNN(nn.Module):
    2. def forward(self, x):
    3. x = self.features(x)
    4. x = torch.flatten(x, 1)
    5. x = self.classifier(x)
    6. return x

    更新后的学生模型:

    1. class ModifiedLightNNCosine(nn.Module):
    2. def forward(self, x):
    3. x = self.features(x)
    4. flattened_conv_output = torch.flatten(x, 1)
    5. x = self.classifier(flattened_conv_output)
    6. return x, flattened_conv_output

    方法三:

    Teacher accuracy: 75.60%
    Student accuracy without teacher: 70.41%
    Student accuracy with CE + KD: 70.19%
    Student accuracy with CE + CosineLoss: 70.87%
    Student accuracy with CE + RegressorMSE: 71.40%
  • 相关阅读:
    Mybatis苞米豆(baomidou)使用说明书
    Redis-Cluster模式基操篇
    Java#10(String 类的构造方法和练习)
    Docker部署EMQX
    【数据集】指针式圆形表计关键点数据集
    Pytorch学习笔记(一)官方60min入门教程之张量
    数据结构与算法(十):动态规划与贪心算法
    [SpringBoot] @Value 与 @ConfigurationProperties 对比
    JavaScript(短信验证码)
    面向嵌入式系统设计师的多核技术培训
  • 原文地址:https://blog.csdn.net/llf000000/article/details/136377486
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号