CV&感知算法面试常见手撕代码题目汇总(三)【附参考实现代码】
在如今互联网大厂面试环节中,现场手撕代码已经成为了每位面试者必须要经历的一关。目前85%以上的互联网公司都将面试者的现场编程能力作为能否拿到Offer的核心评价指标。如果可以在规定时间内流畅、顺利完成面试官给出题目的候选人,拿到高质量面评的概率要比其他人高出很多。
本文作为《一站式智驾感知算法求职宝典》专栏中算法岗面试常见手撕题目汇总系列的第三篇文章,继续为大家收录和整理互联网大厂面试中的高频手撕算法题目,并且给出了参考实现代码,便于同学们实习和求职前复习,从而在面试手撕代码环节更加游刃有余!
无论你是即将开始秋招的应届毕业生,还是打算找实习的算法小白,这份凝结了互联网大厂高频手撕算法题目的高质量文章将为你的面试之路保驾护航!
一、Softmax函数实现
题目要求:实现Softmax函数
import torch import torch.nn.functional as F def custom_softmax(x, dim=None): x_exp = torch.exp(x) x_sum = x_exp.sum(dim=dim) return x_exp / x_sum if __name__ == "__main__": torch.manual_seed(0) x = torch.randn(10) # custom softmax print(f"custom softmax output: \n{custom_softmax(x, dim=-1)}") # official softmax print(f"official softmax output: \n{F.softmax(x, dim=-1)}")
二、Focal Loss损失函数实现
题目要求:实现2D目标检测、BEV感知中常用的Focal Loss损失函数
import torch import torch.nn as nn import torch.nn.functional as F class FocalLoss(nn.Module): def __init__(self, alpha=0.25, gamma=2., reduction='mean'): super(FocalLoss, self).__init__() self.alpha = alpha self.gamma = gamma self.reduction = reduction def forward(self, pred_logit, gt_label): ce_loss = F.binary_cross_entropy_with_logits(pred_logit, gt_label, reduction='none') probs = torch.sigmoid(pred_logit) p = torch.where(gt_label == 1, probs, 1 - prob
剩余60%内容,订阅专栏后可继续查看/也可单篇购买
一站式智驾感知算法求职宝典 文章被收录于专栏
作为24届上岸自动驾驶感知算法的学长,将自己在秋招中的面试经验和心得体会总结成《一站式智驾感知算法求职宝典》,宝典包含【求职简历如何准备】、【论文/实习/科研项目经历如何包装】、【Leetcode算法刷题思路】、【十五家智驾感知算法面经汇总(附参考答案)】、【CV&感知算法面试常见代码题目汇总(附参考代码)】、【互联网大厂笔试ACM模式输入输出类型题目汇总】等多个板块,祝你拿下心仪Offer!