A-卷积网络压缩方法总结( 五 )

tensorflow代码示例如下:
# 将类别标签进行one-hot编码one_hot = tf.one_hot(y, n_classes,1.0,0.0) # n_classes为类别总数, n为类别标签# one_hot = tf.cast(one_hot_int, tf.float32)teacher_tau = tf.scalar_mul(1.0/args.tau, teacher) # teacher为teacher模型直接输出张量, tau为温度系数Tstudent_tau = tf.scalar_mul(1.0/args.tau, student) # 将模型直接输出logits张量student处于温度系数Tobjective1 = tf.nn.sigmoid_cross_entropy_with_logits(student_tau, one_hot)objective2 = tf.scalar_mul(0.5, tf.square(student_tau-teacher_tau))"""student模型最终的损失函数由两部分组成:第一项是由小模型的预测结果与大模型的“软标签”所构成的交叉熵(cross entroy);第二项为预测结果与普通类别标签的交叉熵 。"""tf_loss = (args.lamda*tf.reduce_sum(objective1) + (1-args.lamda)*tf.reduce_sum(objective2))/batch_sizetf.scalar_mul 函数为对 tf 张量进行固定倍率 scalar 缩放函数 。一般 T 的取值在 1 - 20 之间 , 这里我参考了开源代码,取值为 3 。我发现在开源代码中 student 模型的训练,有些是和 teacher 模型一起训练的,有些是 teacher 模型训练好后直接指导 student 模型训练 。
六,浅层/轻量网络浅层网络:通过设计一个更浅(层数较少)结构更紧凑的网络来实现对复杂模型效果的逼近, 但是浅层网络的表达能力很难与深层网络相匹敌 。因此 , 这种设计方法的局限性在于只能应用解决在较为简单问题上 。如分类问题中类别数较少的 task
轻量网络:使用如 MobilenetV2、ShuffleNetv2 等轻量网络结构作为模型的 backbone可以大幅减少模型参数数量 。
参考资料

  1. 神经网络模型压缩和加速之知识蒸馏
  2. https://github.com/chengshengchan/model_compression/blob/master/teacher-student.py
  3. https://github.com/dkozlov/awesome-knowledge-distillation
  4. XNOR-Net
  5. 解析卷积神经网络-深度学习实践手册
  6. 知识蒸馏(Knowledge Distillation)简述(一)

推荐阅读