Agent skill

PyTorch 组合损失函数 (SSIM + L1 + L2)

实现一个用于图像复原任务的组合损失函数,包含结构相似性(SSIM)、平均绝对误差(L1)和均方误差(L2)的加权和,并配置对应的Adam优化器和ReduceLROnPlateau学习率调度器。

ECNU-ICALKgithub.com/ECNU-ICALKGitHub ↗
claude-code
Install
npx skills add ECNU-ICALK/AutoSkill --skill pytorch-组合损失函数-ssim-l1-l2 --agent claude-code

Same command for any agent — swap --agent for codex, cursor, copilot.

Facts
Files in the skill folder: 1
SKILL.md size: 2 KB
Bundled scripts: none
Version: 0.1.0
Path: SkillBank/ConvSkill/chinese_gpt4_8_GLM4.7/pytorch-组合损失函数-ssim-l1-l2/SKILL.md
Open the folder on GitHub →
Where it comes from
Stars: 539
Language: Python

Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.

From the SKILL.md

# PyTorch 组合损失函数 (SSIM + L1 + L2) 实现一个用于图像复原任务的组合损失函数,包含结构相似性(SSIM)、平均绝对误差(L1)和均方误差(L2)的加权和,并配置对应的Adam优化器和ReduceLROnPlateau学习率调度器。 ## Prompt # Role & Objective 你是一个PyTorch深度学习专家,负责实现用于图像复原(如Res-UNET)的组合损失函数。 # Operational Rules & Constraints 1. **损失函数定义**: - 创建一个继承自 `nn.Module` 的类 `CombinedLoss`。 - 在 `__init__` 中接收并存储三个权重参数:`ssim_weight` (默认 0.03), `l1_weight` (默认 0.21), `l2_weight` (默认 0.76)。 - 初始化 `nn.L1Loss()` 和 `nn.MSELoss()` 实例。 2. **前向传播逻辑**: - 在 `forward` 方法中,接收 `predictions` 和 `targets`。 - 计算 SSIM 损失:`ssim_loss = 1 - pytorch_ssim.ssim(predictions, targets)`。 - 计算 L1 损失:`l1_loss = self.l1_loss(predictions, targets)`。 - 计算 L2 损失:`l2_loss = self.l2_loss(predictions, targets)`。 - 计算组合损失:`total_loss = self.ssim_weight * ssim_loss + self.l1_weight * l1_loss + self.l2_weight * l2_loss`。 - 返回 `total_loss`。 3. **优化器与调度器配置**: - 优化器使用 `torch.optim.Adam`,参数包括 `betas=(0.5, 0.999)` 和指定的学习率。 - 学习率调度器使用 `torch.optim.lr_scheduler.ReduceLROnPlateau`,参数为 `mode='min'` 和 `patience=5`。 # Anti-Patterns - 不要在 `forward` 中直接实例化损失函数(如 `nn.L1Loss()`),应在 `__init__` 中完成。 - 不要混淆权重变量和损失函数实例(例如不要写成 `self.l1_weight * self.l1_loss`)。 ## Triggers - 构建SSIM L1 L2组合损失函数 - 实现Res-UNET的损失函数 - combined loss function

What's inside
Steps it walks through
  1. Prompt
  2. Triggers
More from AutoSkill
All skills →
About this skill
What does the PyTorch 组合损失函数 (SSIM + L1 + L2) skill do?

实现一个用于图像复原任务的组合损失函数,包含结构相似性(SSIM)、平均绝对误差(L1)和均方误差(L2)的加权和,并配置对应的Adam优化器和ReduceLROnPlateau学习率调度器。

How do I install it?

Run `npx skills add ECNU-ICALK/AutoSkill --skill pytorch-组合损失函数-ssim-l1-l2 --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.

Where does this skill come from?

From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.

Is a popular skill a good skill?

Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.

Keep going