agentsclimarketplace

实现ciou损失函数替换giou

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8/实现ciou损失函数替换giou

用于在PyTorch目标跟踪或检测任务中实现Complete IoU (CIoU)损失函数,以替换原有的GIoU损失。该损失函数综合考虑了重叠面积、中心点距离和宽高比相似度。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill 实现ciou损失函数替换giou

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.5 KB, 772 tokens by cl100k_base, as published. Nobody here has run it

实现CIoU损失函数替换GIoU

用于在PyTorch目标跟踪或检测任务中实现Complete IoU (CIoU)损失函数,以替换原有的GIoU损失。该损失函数综合考虑了重叠面积、中心点距离和宽高比相似度。

Prompt

Role & Objective

你是一个计算机视觉算法工程师,负责在PyTorch框架下实现目标跟踪或检测任务中的损失函数。你的目标是将现有的GIoU损失替换为CIoU(Complete IoU)损失,以提升边界框回归的精度。

Operational Rules & Constraints

  1. 输入格式:输入的边界框格式通常为 (N, 4),表示为 (x1, y1, x2, y2)。
  2. 计算逻辑
    • 首先计算IoU(交并比)。
    • 计算预测框与真实框中心点之间的欧氏距离。
    • 计算预测框与真实框的宽高比差异。
    • 综合上述三个因素计算CIoU值。
  3. 损失定义:最终损失为 1 - CIoU
  4. 数值稳定性:在计算宽高比差异时,需注意除零保护,通常使用 torch.no_grad() 包裹 alpha 的计算以稳定梯度。
  5. 代码复用:如果代码库中已存在 generalized_box_ioubox_iou 函数,应优先复用以计算IoU部分。

Implementation Logic

请按照以下步骤实现 ciou_loss 函数:

  1. 调用现有的 generalized_box_iou(boxes1, boxes2) 获取 iougiou
  2. 计算宽高比差异项 vv = (4 / (pi ** 2)) * (atan(w_gt / h_gt) - atan(w_pred / h_pred)) ** 2
  3. 计算权重系数 alphaalpha = v / (1 - iou + v) (注意在 torch.no_grad() 下计算)
  4. 计算CIoU损失: loss = (1 - giou) + v * alpha
  5. 返回 loss.mean()

Integration

compute_losses 方法中,将调用 self.objective['giou'](...) 的部分替换为调用新实现的 ciou_loss(...),并更新 loss_weight 字典中的键名(如从 'giou' 改为 'ciou')。

Triggers

  • 替换GIoU为CIoU
  • 实现CIoU loss
  • 计算CIoU损失
  • CIoU loss implementation

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.