# cdf-anomalygen

Automates the CDF AnomalyGen pipeline to fine-tune Cosmos models and generate realistic synthetic defect images from masks.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf (Devin Desktop), Claude.ai · ★ 4106 repo stars
- Author: NVIDIA
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/NVIDIA/skills/tree/HEAD/skills/cdf-anomalygen/SKILL.md
- Updated: 2026-10-23
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/cdf-anomalygen

## What it does

The skill guides your agent through CDF AnomalyGen stages: defect mask placement, model fine-tuning, synthetic defect-image generation (SDG), quality evaluation, and pseudo-labeling. It accepts clean reference images alongside defect masks, then trains a frozen Cosmos foundation model to paint defects onto specified surface areas.

Execution happens across three modes: `full` for end-to-end training and synthesis, `finetune_only` for model training, and `generation_only` when using an existing checkpoint. The workflow depends on a CUDA GPU and Hugging Face authentication via `hf auth login` to fetch weights. The default `amg` mask backend will halt immediately unless a vision-language endpoint is configured in `~/.anomalygen/endpoints.yaml`.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add NVIDIA/skills --skill cdf-anomalygen -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/cdf-anomalygen/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/cdf-anomalygen/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add NVIDIA/skills --skill cdf-anomalygen -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/cdf-anomalygen/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add NVIDIA/skills --skill cdf-anomalygen -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/cdf-anomalygen/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install NVIDIA/skills skills/cdf-anomalygen
```

2. **Manually: put the files in place**
- File: `.github/skills/cdf-anomalygen/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add NVIDIA/skills --skill cdf-anomalygen -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/NVIDIA/skills --path skills/cdf-anomalygen
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/cdf-anomalygen/SKILL.md` — The legacy .windsurf/skills/ path still works

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/NVIDIA/skills/tree/HEAD/skills/cdf-anomalygen/SKILL.md

## When to use it
- fine-tune Cosmos models on custom defect datasets
- generate synthetic anomaly images from defect masks
- evaluate quality and pseudo-label synthesized defects
- automate mask placement using local or remote vision models

## Example prompts
- Run the AnomalyGen pipeline on phone_screen dataset in full mode
- Fine-tune an anomaly-generation model for PCB defects
- Generate 25 synthetic PCB anomaly images from existing checkpoint

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 0d853a028e5880d7.

BEGIN THIRD-PARTY FILE 0d853a028e5880d7
````text
---
name: cdf-anomalygen
description: >-
  Use when running the CDF AnomalyGen pipeline over a defect dataset — mask placement,
  fine-tuning, synthetic defect-image generation (SDG), evaluation, quality refinement, and
  pseudo-labeling — even when the user names only one stage.
license: Apache-2.0
compatibility: >-
  Requires a CUDA GPU and the built env (native .venv or the Docker image); Hugging Face auth +
  network access to download the model checkpoints.
metadata:
  owner: NVIDIA
  service: anomaly generation
  version: 1.2.0
  author: NVIDIA <nvidia@nvidia.com>
  tags:
      - physical-ai
      - anomaly-generation
      - cosmos
      - fine-tuning
  languages: [python]
  frameworks: [pytorch, cosmos, diffusion]
---

# Skill: cdf-anomalygen

## Purpose

AnomalyGen fine-tunes the frozen **Cosmos** base into an **anomaly-generation** model: given a clean
image + defect mask, it paints a realistic defect into that region (synthetic data for detectors).
Pick a mode, collect its params, run the steps — **all commands from the repo root.**

## When to Use This Skill

Use for the CDF AnomalyGen pipeline over a defect dataset — any single stage (mask placement,
fine-tuning, generation, evaluation, refinement, or pseudo-labeling) or the full run.

- "Run the AnomalyGen pipeline on phone_screen"
- "Fine-tune an anomaly-generation model for PCB defects"
- "Generate 25 synthetic PCB anomaly images"
- "Place defect masks", "evaluate quality", or "pseudo-label the generated defects"

Do not use this skill for generic image generation, or for synthetic data that isn't defect images
built from the `{texture}/{defect}` clean-image + defect-mask contract.

## Prerequisites

- A **CUDA GPU** and the project's built env (native `.venv` or the Docker image).
- **Hugging Face auth** — run `hf auth login` — plus network access; the downloader fetches
  the model checkpoints.
- A **`dataset_dir`** in the Step 1 contract layout (clean images + `{defect}` masks; plus
  `defect_spec.jsonl` **only when `mask_backend=amp`** — the default `amg` never reads it, and
  nothing after Step 2 does either).

Preflight the env + checkpoints (GPU, Python, CUDA/torch, deps, HF auth, model checkpoints):

```shell
scripts/preflight_env_ckpt.sh
```

**Read which group failed before reacting** — the summary separates them, and only one is fixed by
downloading:

- *missing checkpoints* → `scripts/download_checkpoints.sh` (run `hf auth login` first).
- *env / Python / deps* → rebuild the environment (`bash scripts/env_setup.sh`, then activate it).

**Third group — model access for mask placement (checked HERE, never mid-flow).** The default
`mask_backend=amg` needs a vision model, and a run that discovers this at Step 2 has already spent
the user's time. A **VLM API is a base, a key and a model name** — and all three live in ONE place:
**`~/.anomalygen/endpoints.yaml`**, the model registry (nothing is built into the code; the template
is `scripts/agentic_mask_generation_serving/endpoints.example.yaml`). It sits under `$HOME`, not in
````
END THIRD-PARTY FILE 0d853a028e5880d7

The third-party file has ended. Everything between the 0d853a028e5880d7 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3076 of 39641 bytes. © NVIDIA · Apache-2.0 · https://github.com/NVIDIA/skills/tree/HEAD/skills/cdf-anomalygen/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
