def smooth_L1_loss(self, y_true, y_pred):
absolute_loss = tf.abs(y_true - y_pred)
square_loss = 0.5 * (y_true - y_pred)**2
l1_loss = tf.where(tf.less(absolute_loss, 1.0), square_loss, absolute_loss - 0.5)
return tf.reduce_sum(l1_loss, axis=-1)
2 conf的损失函数:Log loss
y_true shape:(batch_size, n_boxes, n_classes)
def log_loss(self, y_true, y_pred):
# 确保y_pred中不含0,否则会使log函数崩溃的
y_pred = tf.maximum(y_pred, 1e-15)
# Compute the log loss
log_loss = -tf.reduce_sum(y_true * tf.log(y_pred), axis=-1)
return log_loss
3 hard negative mining
主要思路:
1.根据正样本的个数和正负比例,确定负样本的个数,negative_keep
2.找到confidence loss最大的negative_keep个负样本,计算他们的分类损失之和
3.计算正样本的分类损失之和,分类损失是正样本和负样本的损失和
4.计算正样本的位置损失localization loss.无法计算负样本位置损失 %>_<%
- 对回归损失和位置损失之和
def compute_loss(self, y_true, y_pred):
self.neg_pos_ratio = tf.constant(self.neg_pos_ratio)
self.n_neg_min = tf.constant(self.n_neg_min)
self.alpha = tf.constant(self.alpha)
batch_size = tf.shape(y_pred)[0] # Output dtype: tf.int32
n_boxes = tf.shape(y_pred)[1]
# Output dtype: tf.int32, note that `n_boxes` in this context denotes the total number of boxes per image, not the number of boxes per cell.
## 计算每个box的类别和框的损失
classification_loss = tf.to_float(self.log_loss(y_true[:,:,:-12], y_pred[:,:,:-12]))
# Output shape: (batch_size, n_boxes)
localization_loss = tf.to_float(self.smooth_L1_loss(y_true[:,:,-12:-8], y_pred[:,:,-12:-8]))
# Output shape: (batch_size, n_boxes)
## 为正的和负的groud truth 制作mask
#此时需要对y_true提前进行编码。
#对于类别只有所属的类别是1,其他全是0,对于出ground truth之外的box的类别,背景设为1,其余全设为0
negatives = y_true[:,:,0] # Tensor of shape (batch_size, n_boxes)
positives = tf.to_float(tf.reduce_max(y_true[:,:,1:-12], axis=-1))
# Tensor of shape (batch_size, n_boxes)
#统计正样本的个数
n_positive = tf.reduce_sum(positives)
# 掩盖负的box,计算正样本box的损失之和
pos_class_loss = tf.reduce_sum(classification_loss * positives, axis=-1) # Tensor of shape (batch_size,)
# 计算所有负样本的box的损失之和
neg_class_loss_all = classification_loss * negatives # Tensor of shape (batch_size, n_boxes)
#计算损失非零的负样本的个数
n_neg_losses = tf.count_nonzero(neg_class_loss_all, dtype=tf.int32) # The number of non-zero loss entries in `neg_class_loss_all`
**自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。**
**深知大多数Linux运维工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!**
**因此收集整理了一份《2024年Linux运维全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。**
![img](https://img-blog.csdnimg.cn/img_convert/873f71376f5f6415414a20c8bde55b08.png)
![img](https://img-blog.csdnimg.cn/img_convert/4c95fe5f582253849fd53919d5abb389.png)
![img](https://img-blog.csdnimg.cn/img_convert/92f9a7a9db4473fb3702d349f39d65bd.png)
![img](https://img-blog.csdnimg.cn/img_convert/dea089cde9b76ffad426448508220bce.png)
![img](https://img-blog.csdnimg.cn/img_convert/102bdf541dfe9550cec07efee20d493a.png)
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Linux运维知识点,真正体系化!**
**由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新**
**如果你觉得这些内容对你有帮助,可以添加VX:vip1024b (备注Linux运维获取)**
![img](https://img-blog.csdnimg.cn/img_convert/73ae7076aca7f93b3c7be35c8016efbb.jpeg)
### 最后的话
最近很多小伙伴找我要Linux学习资料,于是我翻箱倒柜,整理了一些优质资源,涵盖视频、电子书、PPT等共享给大家!
### 资料预览
给大家整理的视频资料:
![](https://img-blog.csdnimg.cn/img_convert/1367f36e0bd4681e9217c9325e8ef541.png)
给大家整理的电子书资料:
![](https://img-blog.csdnimg.cn/img_convert/6c14dc3be5a85ce848c7312f221971e6.png)
**如果本文对你有帮助,欢迎点赞、收藏、转发给朋友,让我有持续创作的动力!**
**一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
![img](https://img-blog.csdnimg.cn/img_convert/805b37dbc7e9412091c5790337c95251.jpeg)
走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
[外链图片转存中...(img-iXY6uS17-1712766857615)]