"<!DOCTYPE html>\n<html lang=\"zh\" data-theme=\"light\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>fulltext.txt — Vercel Design System</title>\n<link rel=\"preconnect\" href=\"https://fonts.googleapis.com\">\n<link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin>\n<link href=\"https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500;600&display=swap\" rel=\"stylesheet\">\n<link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.css\">\n<style>\n\n:root {\n  /* Vercel Palette */\n  --geist-foreground: #171717;\n  --geist-background: #ffffff;\n  --geist-secondary: #4d4d4d;\n  --geist-tertiary: #666666;\n  --geist-quaternary: #808080;\n  --geist-border: #ebebeb;\n  --geist-surface-tint: #fafafa;\n  \n  /* Workflow Accents */\n  --develop-blue: #0a72ef;\n  --preview-pink: #de1d8d;\n  --ship-red: #ff5b4f;\n  \n  /* Interactive & Status */\n  --link-blue: #0072f5;\n  --ds-focus-color: hsla(212, 100%, 48%, 1);\n  --badge-blue-bg: #ebf5ff;\n  --badge-blue-text: #0068d6;\n  \n  /* Shadow-as-Border Philosophy */\n  --shadow-border: rgba(0, 0, 0, 0.08) 0px 0px 0px 1px;\n  --shadow-border-hover: rgba(0, 0, 0, 0.16) 0px 0px 0px 1px;\n  --shadow-card: rgba(0, 0, 0, 0.08) 0px 0px 0px 1px, rgba(0, 0, 0, 0.04) 0px 2px 2px, #fafafa 0px 0px 0px 1px;\n  --shadow-card-hover: rgba(0, 0, 0, 0.12) 0px 0px 0px 1px, rgba(0, 0, 0, 0.06) 0px 4px 6px, #fafafa 0px 0px 0px 1px;\n  --shadow-card-full: rgba(0, 0, 0, 0.08) 0px 0px 0px 1px, rgba(0, 0, 0, 0.04) 0px 2px 2px, rgba(0, 0, 0, 0.04) 0px 8px 8px -8px, #fafafa 0px 0px 0px 1px;\n  --shadow-ring: rgb(235, 235, 235) 0px 0px 0px 1px;\n  \n  /* Radius Scale */\n  --radius-xs: 2px;\n  --radius-sm: 4px;\n  --radius-md: 6px;\n  --radius-lg: 8px;\n  --radius-xl: 12px;\n  --radius-pill: 9999px;\n}\n\n[data-theme=\"dark\"] {\n  --geist-foreground: #ededed;\n  --geist-background: #000000;\n  --geist-secondary: #a1a1a1;\n  --geist-tertiary: #888888;\n  --geist-quaternary: #666666;\n  --geist-border: #222222;\n  --geist-surface-tint: #0a0a0a;\n  \n  --shadow-border: rgba(255, 255, 255, 0.14) 0px 0px 0px 1px;\n  --shadow-border-hover: rgba(255, 255, 255, 0.28) 0px 0px 0px 1px;\n  --shadow-card: rgba(255, 255, 255, 0.12) 0px 0px 0px 1px, rgba(0, 0, 0, 0.4) 0px 2px 4px, #111111 0px 0px 0px 1px;\n  --shadow-card-hover: rgba(255, 255, 255, 0.2) 0px 0px 0px 1px, rgba(0, 0, 0, 0.5) 0px 6px 12px, #111111 0px 0px 0px 1px;\n  --shadow-card-full: rgba(255, 255, 255, 0.12) 0px 0px 0px 1px, rgba(0, 0, 0, 0.5) 0px 8px 16px -4px, #111111 0px 0px 0px 1px;\n  --shadow-ring: rgb(40, 40, 40) 0px 0px 0px 1px;\n  \n  --badge-blue-bg: rgba(10, 114, 239, 0.15);\n  --badge-blue-text: #70b5ff;\n}\n\n* { box-sizing: border-box; }\nhtml { scroll-behavior: smooth; }\nbody {\n  margin: 0;\n  font-family: \"Geist\", Arial, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;\n  background-color: var(--geist-background);\n  color: var(--geist-foreground);\n  font-feature-settings: \"liga\" 1;\n  -webkit-font-smoothing: antialiased;\n  min-height: 100vh;\n}\n\na {\n  color: inherit;\n  text-decoration: none;\n  transition: color 0.15s ease;\n}\n\n/* 导航栏 (Vercel Clean Sticky Nav) */\n.vercel-nav {\n  position: sticky;\n  top: 0;\n  background-color: var(--geist-background);\n  box-shadow: var(--shadow-border);\n  z-index: 100;\n  padding: 0 24px;\n  height: 64px;\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n}\n.nav-brand {\n  display: flex;\n  align-items: center;\n  gap: 12px;\n}\n.vercel-triangle {\n  width: 22px;\n  height: 19px;\n  fill: var(--geist-foreground);\n}\n.nav-title {\n  font-size: 16px;\n  font-weight: 600;\n  letter-spacing: -0.32px;\n  color: var(--geist-foreground);\n}\n.nav-badge-pill {\n  font-family: \"Geist Mono\", ui-monospace, monospace;\n  font-size: 11px;\n  font-weight: 500;\n  text-transform: uppercase;\n  background: var(--badge-blue-bg);\n  color: var(--badge-blue-text);\n  padding: 2px 8px;\n  border-radius: var(--radius-pill);\n}\n\n.nav-links {\n  display: flex;\n  align-items: center;\n  gap: 24px;\n}\n.nav-link {\n  font-size: 14px;\n  font-weight: 500;\n  color: var(--geist-secondary);\n  text-decoration: none;\n  transition: color 0.15s;\n}\n.nav-link:hover, .nav-link.active {\n  color: var(--geist-foreground);\n}\n.nav-link.active {\n  font-weight: 600;\n}\n\n.nav-actions {\n  display: flex;\n  align-items: center;\n  gap: 12px;\n}\n\n/* 按钮规范 */\n.btn-primary-dark {\n  background: var(--geist-foreground);\n  color: var(--geist-background);\n  border: none;\n  padding: 8px 16px;\n  border-radius: var(--radius-md);\n  font-size: 14px;\n  font-weight: 500;\n  cursor: pointer;\n  text-decoration: none;\n  display: inline-flex;\n  align-items: center;\n  gap: 6px;\n  transition: opacity 0.15s;\n}\n.btn-primary-dark:hover {\n  opacity: 0.9;\n}\n.btn-secondary-white {\n  background: var(--geist-background);\n  color: var(--geist-foreground);\n  box-shadow: var(--shadow-border);\n  border: none;\n  padding: 8px 16px;\n  border-radius: var(--radius-md);\n  font-size: 14px;\n  font-weight: 500;\n  cursor: pointer;\n  text-decoration: none;\n  display: inline-flex;\n  align-items: center;\n  gap: 6px;\n  transition: background 0.15s, box-shadow 0.15s;\n}\n.btn-secondary-white:hover {\n  background: var(--geist-surface-tint);\n  box-shadow: var(--shadow-border-hover);\n}\n.theme-toggle-btn {\n  background: transparent;\n  border: none;\n  box-shadow: var(--shadow-border);\n  border-radius: var(--radius-md);\n  width: 36px;\n  height: 36px;\n  cursor: pointer;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  color: var(--geist-foreground);\n}\n\n/* 核心容器 */\n.vercel-container {\n  max-width: 1200px;\n  margin: 0 auto;\n  padding: 56px 24px 100px;\n}\n\n/* Hero Section (Gallery Emptiness + Negative Letter-spacing) */\n.vercel-hero {\n  text-align: center;\n  max-width: 860px;\n  margin: 0 auto 56px;\n}\n.hero-stage-badge {\n  display: inline-flex;\n  align-items: center;\n  gap: 8px;\n  background: var(--geist-surface-tint);\n  box-shadow: var(--shadow-border);\n  padding: 4px 14px;\n  border-radius: var(--radius-pill);\n  font-size: 13px;\n  font-weight: 500;\n  color: var(--geist-secondary);\n  margin-bottom: 24px;\n}\n.stage-dot {\n  width: 7px;\n  height: 7px;\n  border-radius: 50%;\n}\n.vercel-hero h1 {\n  font-size: 48px;\n  font-weight: 600;\n  line-height: 1.05;\n  letter-spacing: -2.4px;\n  color: var(--geist-foreground);\n  margin: 0 0 16px;\n}\n.vercel-hero p {\n  font-size: 20px;\n  font-weight: 400;\n  line-height: 1.80;\n  color: var(--geist-secondary);\n  margin: 0 auto 28px;\n}\n\n/* Workflow Pipeline (Develop -> Preview -> Ship) */\n.workflow-pipeline {\n  display: grid;\n  grid-template-columns: repeat(3, 1fr);\n  gap: 16px;\n  margin-bottom: 48px;\n}\n@media (max-width: 768px) {\n  .workflow-pipeline { grid-template-columns: 1fr; }\n}\n.workflow-step {\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card);\n  border-radius: var(--radius-lg);\n  padding: 20px 22px;\n  transition: box-shadow 0.2s;\n}\n.workflow-step:hover {\n  box-shadow: var(--shadow-card-hover);\n}\n.step-mono-label {\n  font-family: \"Geist Mono\", monospace;\n  font-size: 12px;\n  font-weight: 500;\n  text-transform: uppercase;\n  letter-spacing: 0.5px;\n  margin-bottom: 8px;\n  display: flex;\n  align-items: center;\n  gap: 6px;\n}\n.step-title {\n  font-size: 20px;\n  font-weight: 600;\n  letter-spacing: -0.96px;\n  color: var(--geist-foreground);\n  margin-bottom: 6px;\n}\n.step-desc {\n  font-size: 14px;\n  color: var(--geist-secondary);\n  line-height: 1.5;\n}\n\n/* Metric Cards (Section 4 Spec) */\n.metric-grid {\n  display: grid;\n  grid-template-columns: repeat(4, 1fr);\n  gap: 16px;\n  margin-bottom: 48px;\n}\n@media (max-width: 900px) {\n  .metric-grid { grid-template-columns: repeat(2, 1fr); }\n}\n.metric-card {\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card);\n  border-radius: var(--radius-lg);\n  padding: 20px;\n}\n.metric-number {\n  font-size: 40px;\n  font-weight: 600;\n  line-height: 1.0;\n  letter-spacing: -2.4px;\n  color: var(--geist-foreground);\n  margin-bottom: 8px;\n  font-feature-settings: \"tnum\" 1;\n}\n.metric-label {\n  font-size: 14px;\n  color: var(--geist-secondary);\n  line-height: 1.4;\n}\n\n/* VAD 专栏 Banner (Ship Red & Vercel Clean) */\n.vad-showcase {\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card-full);\n  border-radius: var(--radius-xl);\n  padding: 32px;\n  margin-bottom: 48px;\n  position: relative;\n}\n.vad-header-row {\n  display: flex;\n  align-items: baseline;\n  justify-content: space-between;\n  flex-wrap: wrap;\n  gap: 12px;\n  margin-bottom: 12px;\n}\n.vad-header-row h2 {\n  font-size: 32px;\n  font-weight: 600;\n  letter-spacing: -1.28px;\n  color: var(--geist-foreground);\n  margin: 0;\n}\n.vad-pillars-grid {\n  display: grid;\n  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));\n  gap: 14px;\n  margin-top: 24px;\n}\n.vad-pillar-item {\n  background: var(--geist-surface-tint);\n  box-shadow: var(--shadow-border);\n  border-radius: var(--radius-md);\n  padding: 14px 16px;\n}\n.vad-pillar-title {\n  font-size: 14px;\n  font-weight: 600;\n  color: var(--ship-red);\n  margin-bottom: 4px;\n}\n.vad-pillar-text {\n  font-size: 13px;\n  color: var(--geist-secondary);\n  line-height: 1.5;\n}\n.vad-filter-bar {\n  display: flex;\n  flex-wrap: wrap;\n  align-items: center;\n  justify-content: space-between;\n  gap: 12px;\n  margin: 24px 0 16px;\n  padding: 12px 16px;\n  background: var(--geist-surface-tint);\n  border-radius: var(--radius-md);\n  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);\n}\n.vad-filter-btn {\n  font-family: 'Geist', sans-serif;\n  font-size: 13px;\n  font-weight: 500;\n  padding: 6px 14px;\n  border-radius: 9999px;\n  border: none;\n  background: transparent;\n  color: var(--geist-secondary);\n  cursor: pointer;\n  transition: all 0.15s ease;\n}\n.vad-filter-btn:hover {\n  color: var(--geist-foreground);\n  background: rgba(0,0,0,0.05);\n}\n.vad-filter-btn.active {\n  background: #171717;\n  color: #ffffff;\n}\n.vad-search-input {\n  font-family: 'Geist', sans-serif;\n  font-size: 13px;\n  padding: 7px 12px;\n  border-radius: 6px;\n  border: 1px solid var(--geist-border);\n  background: #ffffff;\n  color: var(--geist-foreground);\n  width: 280px;\n  outline: none;\n  transition: border-color 0.15s, box-shadow 0.15s;\n}\n.vad-search-input:focus {\n  border-color: #0a72ef;\n  box-shadow: 0 0 0 2px rgba(10, 114, 239, 0.2);\n}\n\n/* 控制栏：搜索、视图、筛选 */\n.control-bar {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  gap: 16px;\n  margin-bottom: 24px;\n  flex-wrap: wrap;\n}\n.search-input-wrap {\n  position: relative;\n  flex: 1;\n  max-width: 480px;\n}\n.search-input {\n  width: 100%;\n  height: 40px;\n  padding: 0 38px 0 14px;\n  font-family: \"Geist\", sans-serif;\n  font-size: 14px;\n  color: var(--geist-foreground);\n  background: var(--geist-background);\n  box-shadow: var(--shadow-border);\n  border: none;\n  border-radius: var(--radius-md);\n  outline: none;\n  transition: box-shadow 0.15s;\n}\n.search-input:focus {\n  outline: 2px solid var(--ds-focus-color);\n  box-shadow: none;\n}\n.search-kbd {\n  position: absolute;\n  right: 12px;\n  top: 50%;\n  transform: translateY(-50%);\n  font-family: \"Geist Mono\", monospace;\n  font-size: 11px;\n  color: var(--geist-quaternary);\n  background: var(--geist-surface-tint);\n  box-shadow: var(--shadow-border);\n  padding: 2px 6px;\n  border-radius: var(--radius-sm);\n}\n\n.view-switcher {\n  display: flex;\n  box-shadow: var(--shadow-border);\n  border-radius: var(--radius-md);\n  background: var(--geist-background);\n  padding: 2px;\n}\n.view-btn {\n  background: transparent;\n  border: none;\n  font-size: 13px;\n  font-weight: 500;\n  color: var(--geist-tertiary);\n  padding: 6px 12px;\n  border-radius: var(--radius-sm);\n  cursor: pointer;\n  transition: color 0.15s, background 0.15s;\n}\n.view-btn.active {\n  background: var(--geist-surface-tint);\n  color: var(--geist-foreground);\n  font-weight: 600;\n}\n\n/* 筛选芯片行 (Filter Pill Strip) */\n.filter-group-strip {\n  display: flex;\n  flex-direction: column;\n  gap: 12px;\n  margin-bottom: 28px;\n  padding: 16px 20px;\n  background: var(--geist-surface-tint);\n  box-shadow: var(--shadow-border);\n  border-radius: var(--radius-lg);\n}\n.filter-row {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  flex-wrap: wrap;\n}\n.filter-label-mono {\n  font-family: \"Geist Mono\", monospace;\n  font-size: 11px;\n  font-weight: 500;\n  text-transform: uppercase;\n  color: var(--geist-quaternary);\n  min-width: 68px;\n}\n.pill-badge {\n  background: var(--geist-background);\n  color: var(--geist-secondary);\n  box-shadow: var(--shadow-border);\n  border: none;\n  padding: 3px 12px;\n  border-radius: var(--radius-pill);\n  font-size: 12px;\n  font-weight: 500;\n  cursor: pointer;\n  transition: all 0.15s;\n  display: inline-flex;\n  align-items: center;\n  gap: 6px;\n}\n.pill-badge:hover {\n  color: var(--geist-foreground);\n  box-shadow: var(--shadow-border-hover);\n}\n.pill-badge.active {\n  background: var(--geist-foreground);\n  color: var(--geist-background);\n  font-weight: 600;\n  box-shadow: none;\n}\n.pill-badge.active-blue {\n  background: var(--develop-blue);\n  color: #ffffff;\n  box-shadow: none;\n}\n.pill-badge.active-red {\n  background: var(--ship-red);\n  color: #ffffff;\n  box-shadow: none;\n}\n\n/* Bento Grid Cards (Section 4 & 6 Spec) */\n.card-grid-bento {\n  display: grid;\n  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));\n  gap: 16px;\n}\n.vercel-card {\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card);\n  border-radius: var(--radius-lg);\n  padding: 20px;\n  display: flex;\n  flex-direction: column;\n  justify-content: space-between;\n  transition: box-shadow 0.2s, transform 0.2s;\n  text-decoration: none;\n  color: inherit;\n  overflow: hidden;\n  min-width: 0;\n  word-break: break-word;\n}\n.vercel-card:hover {\n  box-shadow: var(--shadow-card-hover);\n  transform: translateY(-2px);\n}\n.card-top {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  margin-bottom: 12px;\n  gap: 8px;\n}\n.card-tag-mono {\n  font-family: \"Geist Mono\", monospace;\n  font-size: 11px;\n  font-weight: 500;\n  text-transform: uppercase;\n  color: var(--geist-quaternary);\n  letter-spacing: 0.5px;\n}\n.status-pill-badge {\n  padding: 2px 8px;\n  border-radius: var(--radius-pill);\n  font-size: 11px;\n  font-weight: 500;\n  flex-shrink: 0;\n}\n.pub-accepted { background: #ebfdf2; color: #027a48; }\n.pub-workshop { background: #eff8ff; color: #175cd3; }\n.pub-submitted { background: #fff8e6; color: #b54708; }\n.pub-preprint { background: #f2f4f7; color: #475467; }\n.pub-other { background: #f9f5ff; color: #6941c6; }\n\n[data-theme=\"dark\"] .pub-accepted { background: rgba(2, 122, 72, 0.2); color: #32d583; }\n[data-theme=\"dark\"] .pub-workshop { background: rgba(23, 92, 211, 0.2); color: #84caff; }\n[data-theme=\"dark\"] .pub-submitted { background: rgba(181, 71, 8, 0.2); color: #fec84b; }\n[data-theme=\"dark\"] .pub-preprint { background: rgba(71, 84, 103, 0.2); color: #98a2b3; }\n[data-theme=\"dark\"] .pub-other { background: rgba(105, 65, 198, 0.2); color: #d6bbfb; }\n\n/* 必读标杆徽章 (Vercel Amber Accent) */\n.milestone-badge {\n  display: inline-flex;\n  align-items: center;\n  gap: 3px;\n  padding: 2px 7px;\n  border-radius: var(--radius-pill);\n  font-size: 11px;\n  font-weight: 600;\n  white-space: nowrap;\n  flex-shrink: 0;\n  transition: all 0.15s ease;\n}\n.milestone-badge.ms-idea, .milestone-badge:not([class*=\"ms-\"]) {\n  color: #b54708;\n  background: #fff8e6;\n  border: 1px solid rgba(247, 144, 9, 0.35);\n  box-shadow: 0 1px 2px rgba(181, 71, 8, 0.05);\n}\n[data-theme=\"dark\"] .milestone-badge.ms-idea, [data-theme=\"dark\"] .milestone-badge:not([class*=\"ms-\"]) {\n  color: #fec84b;\n  background: rgba(181, 71, 8, 0.22);\n  border-color: rgba(254, 200, 75, 0.35);\n}\n.milestone-badge.ms-writing {\n  color: #6941c6;\n  background: #f9f5ff;\n  border: 1px solid rgba(105, 65, 198, 0.3);\n  box-shadow: 0 1px 2px rgba(105, 65, 198, 0.05);\n}\n[data-theme=\"dark\"] .milestone-badge.ms-writing {\n  color: #d6bbfb;\n  background: rgba(105, 65, 198, 0.22);\n  border-color: rgba(214, 187, 251, 0.35);\n}\n.milestone-badge.ms-value {\n  color: #027a48;\n  background: #ebfdf2;\n  border: 1px solid rgba(2, 122, 72, 0.3);\n  box-shadow: 0 1px 2px rgba(2, 122, 72, 0.05);\n}\n[data-theme=\"dark\"] .milestone-badge.ms-value {\n  color: #32d583;\n  background: rgba(2, 122, 72, 0.22);\n  border-color: rgba(50, 213, 131, 0.35);\n}\n\n/* 论文正文图表与插图卡片样式 (Geist Design) */\n.paper-figure, .article-body figure {\n  margin: 32px auto;\n  text-align: center;\n  max-width: 100%;\n}\n.paper-figure img, .article-body img {\n  max-width: 96%;\n  height: auto;\n  border-radius: var(--radius-md);\n  border: 1px solid var(--geist-border);\n  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);\n  background: #ffffff;\n  transition: transform 0.2s ease, box-shadow 0.2s ease;\n  display: block;\n  margin: 0 auto;\n}\n.paper-figure img:hover, .article-body img:hover {\n  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);\n}\n.paper-figure figcaption, .article-body figcaption {\n  font-size: 13px;\n  color: var(--geist-secondary);\n  margin-top: 10px;\n  line-height: 1.6;\n  font-style: italic;\n  max-width: 850px;\n  margin-left: auto;\n  margin-right: auto;\n}\n\n/* VAD 视图切换器 View Switcher */\n.vad-view-switcher {\n  display: inline-flex;\n  padding: 3px;\n  background: var(--geist-secondary-bg);\n  border: 1px solid var(--geist-border);\n  border-radius: 8px;\n  margin-bottom: 20px;\n  gap: 2px;\n}\n.view-switch-btn {\n  display: inline-flex;\n  align-items: center;\n  gap: 6px;\n  padding: 6px 14px;\n  font-size: 13px;\n  font-weight: 500;\n  color: var(--geist-secondary);\n  border-radius: 6px;\n  text-decoration: none;\n  transition: all 0.15s ease;\n}\n.view-switch-btn:hover {\n  color: var(--geist-foreground);\n  background: rgba(0, 0, 0, 0.04);\n}\n[data-theme=\"dark\"] .view-switch-btn:hover {\n  background: rgba(255, 255, 255, 0.06);\n}\n.view-switch-btn.active {\n  background: var(--geist-background);\n  color: var(--geist-foreground);\n  font-weight: 600;\n  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);\n}\n\n/* 关系图谱 Graph View Styles */\n.graph-container {\n  position: relative;\n  width: 100%;\n  height: 720px;\n  background: var(--geist-background);\n  border: 1px solid var(--geist-border);\n  border-radius: var(--radius-lg);\n  overflow: hidden;\n  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.04);\n  margin-bottom: 40px;\n}\n.graph-toolbar {\n  position: absolute;\n  top: 14px;\n  left: 14px;\n  right: 14px;\n  z-index: 10;\n  display: flex;\n  justify-content: space-between;\n  align-items: center;\n  background: var(--geist-background);\n  border: 1px solid var(--geist-border);\n  padding: 8px 14px;\n  border-radius: 8px;\n  box-shadow: 0 4px 16px rgba(0,0,0,0.06);\n  flex-wrap: wrap;\n  gap: 8px;\n}\n.graph-tool-title {\n  font-size: 13px;\n  font-weight: 700;\n  display: flex;\n  align-items: center;\n  gap: 6px;\n  color: var(--geist-foreground);\n}\n.graph-filter-group {\n  display: flex;\n  gap: 6px;\n  align-items: center;\n  flex-wrap: wrap;\n}\n.graph-chip {\n  font-size: 11px;\n  padding: 3px 8px;\n  border-radius: 4px;\n  border: 1px solid var(--geist-border);\n  background: var(--geist-background);\n  color: var(--geist-foreground);\n  cursor: pointer;\n  transition: all 0.15s ease;\n}\n.graph-chip:hover { background: var(--geist-secondary-bg); }\n.graph-chip.active {\n  background: var(--geist-foreground);\n  color: var(--geist-background);\n  border-color: var(--geist-foreground);\n}\n.graph-search-input {\n  padding: 3px 8px;\n  font-size: 11px;\n  border-radius: 4px;\n  border: 1px solid var(--geist-border);\n  background: var(--geist-background);\n  color: var(--geist-foreground);\n  outline: none;\n  width: 150px;\n}\n#vad-graph-svg {\n  width: 100%;\n  height: 100%;\n  cursor: grab;\n}\n#vad-graph-svg:active { cursor: grabbing; }\n.graph-legend {\n  position: absolute;\n  bottom: 14px;\n  left: 14px;\n  background: var(--geist-background);\n  border: 1px solid var(--geist-border);\n  border-radius: 8px;\n  padding: 10px 14px;\n  font-size: 11px;\n  box-shadow: 0 4px 16px rgba(0,0,0,0.06);\n  z-index: 10;\n  line-height: 1.6;\n  pointer-events: none;\n}\n.graph-legend-row { display: flex; align-items: center; gap: 8px; }\n.graph-legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }\n.graph-info-drawer {\n  position: absolute;\n  top: 66px;\n  right: 14px;\n  width: 310px;\n  max-height: 620px;\n  background: var(--geist-background);\n  border: 1px solid var(--geist-border);\n  border-radius: 8px;\n  box-shadow: 0 8px 30px rgba(0,0,0,0.12);\n  z-index: 10;\n  padding: 16px;\n  overflow-y: auto;\n  display: none;\n  backdrop-filter: blur(10px);\n  transition: transform 0.2s ease, opacity 0.2s ease;\n}\n.graph-drawer-close {\n  position: absolute;\n  top: 10px;\n  right: 12px;\n  cursor: pointer;\n  font-size: 16px;\n  color: var(--geist-tertiary);\n}\n.graph-drawer-badge {\n  display: inline-block;\n  padding: 2px 6px;\n  border-radius: 4px;\n  font-size: 10px;\n  font-weight: 600;\n  margin-bottom: 6px;\n}\n.graph-drawer-title {\n  font-size: 13px;\n  font-weight: 700;\n  line-height: 1.4;\n  margin-bottom: 8px;\n  color: var(--geist-foreground);\n}\n.graph-drawer-meta {\n  font-size: 11px;\n  color: var(--geist-secondary);\n  margin-bottom: 12px;\n}\n.graph-drawer-core {\n  font-size: 12px;\n  line-height: 1.6;\n  color: var(--geist-foreground);\n  background: var(--geist-secondary-bg);\n  padding: 8px 10px;\n  border-radius: 6px;\n  margin-bottom: 12px;\n  border: 1px solid var(--geist-border);\n}\n.graph-drawer-link {\n  display: block;\n  text-align: center;\n  padding: 7px 12px;\n  background: var(--geist-foreground);\n  color: var(--geist-background);\n  border-radius: 6px;\n  font-size: 12px;\n  font-weight: 600;\n  text-decoration: none;\n  transition: opacity 0.15s ease;\n  margin-bottom: 6px;\n}\n.graph-drawer-link:hover { opacity: 0.85; }\n.graph-drawer-pdf-link {\n  display: block;\n  text-align: center;\n  padding: 6px 12px;\n  background: var(--geist-secondary-bg);\n  color: var(--geist-foreground);\n  border: 1px solid var(--geist-border);\n  border-radius: 6px;\n  font-size: 11px;\n  font-weight: 500;\n  text-decoration: none;\n  transition: all 0.15s ease;\n}\n.graph-drawer-pdf-link:hover { background: var(--geist-border); }\n.node-circle {\n  cursor: pointer;\n  transition: r 0.2s, stroke-width 0.2s;\n}\n.node-label {\n  font-size: 10px;\n  font-weight: 600;\n  fill: var(--geist-foreground);\n  pointer-events: none;\n  text-shadow: 0 1px 2px var(--geist-background);\n}\n.link-line {\n  stroke: var(--geist-border);\n  stroke-opacity: 0.6;\n  stroke-width: 1.2;\n  transition: stroke 0.2s, stroke-width 0.2s, stroke-opacity 0.2s;\n}\n.link-label {\n  font-size: 9px;\n  fill: var(--geist-tertiary);\n  pointer-events: none;\n  text-anchor: middle;\n}\n\n/* 引用框与警示框 Alerts */\n.callout-alert {\n  margin: 20px 0;\n  padding: 14px 18px;\n  border-radius: var(--radius-md);\n  transition: all 0.15s ease;\n}\n.callout-important, .callout-idea {\n  border-left: 4px solid #b54708;\n  background: rgba(181, 71, 8, 0.06);\n  box-shadow: inset 0 0 0 1px rgba(247, 144, 9, 0.3);\n}\n[data-theme=\"dark\"] .callout-important, [data-theme=\"dark\"] .callout-idea {\n  border-left-color: #fec84b;\n  background: rgba(181, 71, 8, 0.18);\n  box-shadow: inset 0 0 0 1px rgba(254, 200, 75, 0.25);\n}\n.callout-writing {\n  border-left: 4px solid #6941c6;\n  background: rgba(105, 65, 198, 0.06);\n  box-shadow: inset 0 0 0 1px rgba(105, 65, 198, 0.3);\n}\n[data-theme=\"dark\"] .callout-writing {\n  border-left-color: #d6bbfb;\n  background: rgba(105, 65, 198, 0.18);\n  box-shadow: inset 0 0 0 1px rgba(214, 187, 251, 0.25);\n}\n.callout-value {\n  border-left: 4px solid #027a48;\n  background: rgba(2, 122, 72, 0.06);\n  box-shadow: inset 0 0 0 1px rgba(2, 122, 72, 0.3);\n}\n[data-theme=\"dark\"] .callout-value {\n  border-left-color: #32d583;\n  background: rgba(2, 122, 72, 0.18);\n  box-shadow: inset 0 0 0 1px rgba(50, 213, 131, 0.25);\n}\n\n.card-title {\n  font-size: 16.5px;\n  font-weight: 600;\n  line-height: 1.42;\n  letter-spacing: -0.4px;\n  color: var(--geist-foreground);\n  margin: 0 0 10px;\n  word-break: break-word;\n  overflow-wrap: anywhere;\n  hyphens: auto;\n}\n.card-title a {\n  color: var(--geist-foreground);\n  text-decoration: none;\n  display: inline;\n  transition: color 0.15s ease;\n}\n.card-title a:hover {\n  color: var(--develop-blue);\n  text-decoration: none;\n}\n.card-id-mono {\n  font-family: \"Geist Mono\", monospace;\n  font-size: 13px;\n  font-weight: 500;\n  color: var(--geist-quaternary);\n  margin-right: 5px;\n}\n.card-meta-row {\n  display: flex;\n  gap: 6px;\n  flex-wrap: wrap;\n  margin-bottom: 12px;\n}\n.meta-token {\n  font-size: 12px;\n  color: var(--geist-tertiary);\n  background: var(--geist-surface-tint);\n  box-shadow: var(--shadow-ring);\n  padding: 2px 7px;\n  border-radius: var(--radius-sm);\n  white-space: nowrap;\n}\n.card-body-text {\n  font-size: 13.5px;\n  color: var(--geist-secondary);\n  line-height: 1.6;\n  margin-bottom: 16px;\n  flex-grow: 1;\n  word-break: break-word;\n  overflow-wrap: anywhere;\n}\n.card-body-text strong {\n  color: var(--geist-foreground);\n  font-weight: 600;\n}\n\n.card-footer {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  border-top: 1px solid var(--geist-border);\n  padding-top: 14px;\n}\n.card-link-action {\n  font-size: 13.5px;\n  font-weight: 500;\n  color: var(--link-blue);\n  display: inline-flex;\n  align-items: center;\n  gap: 4px;\n  text-decoration: none;\n  transition: all 0.15s ease;\n}\n.card-link-action:hover {\n  opacity: 0.85;\n  transform: translateX(2px);\n}\na.meta-token {\n  transition: all 0.15s ease;\n  cursor: pointer;\n  text-decoration: none;\n}\na.meta-token:hover {\n  background: var(--geist-selection);\n  color: var(--geist-foreground);\n  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);\n}\n\n/* 紧凑列表视图 (List View) */\n.card-list-view {\n  display: flex;\n  flex-direction: column;\n  gap: 8px;\n}\n.list-row-item {\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card);\n  border-radius: var(--radius-md);\n  padding: 12px 18px;\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  gap: 16px;\n  transition: box-shadow 0.15s;\n}\n.list-row-item:hover {\n  box-shadow: var(--shadow-card-hover);\n}\n\n/* 阅读详情页 (Report Detail) */\n.reading-container {\n  display: grid;\n  grid-template-columns: minmax(0, 1fr) 260px;\n  gap: 40px;\n  align-items: start;\n}\n@media (max-width: 960px) {\n  .reading-container { grid-template-columns: 1fr; }\n  .reading-sidebar { display: none; }\n}\n\n.report-header-card {\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card);\n  border-radius: var(--radius-lg);\n  padding: 28px 32px;\n  margin-bottom: 28px;\n}\n.crumb-bar {\n  font-size: 13px;\n  color: var(--geist-tertiary);\n  margin-bottom: 10px;\n}\n.report-title {\n  font-size: 32px;\n  font-weight: 600;\n  letter-spacing: -1.28px;\n  margin: 0 0 16px;\n  color: var(--geist-foreground);\n}\n.report-action-buttons {\n  display: flex;\n  align-items: center;\n  gap: 10px;\n  flex-wrap: wrap;\n  border-top: 1px solid var(--geist-border);\n  padding-top: 16px;\n  margin-top: 16px;\n}\n\n.article-body {\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card-full);\n  border-radius: var(--radius-lg);\n  padding: 36px 42px 80px;\n  font-size: 16px;\n  line-height: 1.75;\n  color: var(--geist-foreground);\n}\n.article-body h1, .article-body h2, .article-body h3 {\n  color: var(--geist-foreground);\n  scroll-margin-top: 80px;\n}\n.article-body h1 { font-size: 28px; font-weight: 600; letter-spacing: -1.28px; border-bottom: 1px solid var(--geist-border); padding-bottom: 8px; margin-top: 32px; }\n.article-body h2 { font-size: 24px; font-weight: 600; letter-spacing: -0.96px; border-bottom: 1px solid var(--geist-border); padding-bottom: 6px; margin-top: 36px; }\n.article-body h3 { font-size: 18px; font-weight: 600; letter-spacing: -0.32px; margin-top: 26px; }\n.article-body table {\n  width: 100%;\n  border-collapse: collapse;\n  margin: 24px 0;\n  font-size: 14px;\n  box-shadow: var(--shadow-border);\n  border-radius: var(--radius-md);\n  overflow: hidden;\n}\n.article-body th, .article-body td {\n  padding: 10px 14px;\n  text-align: left;\n  border-bottom: 1px solid var(--geist-border);\n}\n.article-body th {\n  background: var(--geist-surface-tint);\n  font-weight: 600;\n  color: var(--geist-foreground);\n}\n.article-body blockquote {\n  border-left: 2px solid var(--geist-foreground);\n  margin: 20px 0;\n  padding: 8px 18px;\n  color: var(--geist-secondary);\n  font-style: normal;\n}\n.article-body code {\n  font-family: \"Geist Mono\", monospace;\n  font-size: 13.5px;\n  box-shadow: var(--shadow-ring);\n  background: var(--geist-surface-tint);\n  padding: 2px 6px;\n  border-radius: var(--radius-sm);\n}\n.article-body pre {\n  position: relative;\n  background: #000000;\n  color: #ededed;\n  box-shadow: var(--shadow-border);\n  border-radius: var(--radius-md);\n  padding: 18px;\n  margin: 24px 0;\n  overflow-x: auto;\n}\n.article-body pre code {\n  background: transparent;\n  box-shadow: none;\n  padding: 0;\n  color: inherit;\n  font-size: 13px;\n}\n.copy-code-btn {\n  position: absolute;\n  top: 8px;\n  right: 10px;\n  font-family: \"Geist Mono\", monospace;\n  font-size: 11px;\n  background: #171717;\n  color: #ffffff;\n  border: 1px solid #333333;\n  padding: 3px 8px;\n  border-radius: var(--radius-sm);\n  cursor: pointer;\n}\n\n/* 侧边大纲 (TOC) */\n.reading-sidebar {\n  position: sticky;\n  top: 80px;\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card);\n  border-radius: var(--radius-lg);\n  padding: 20px;\n  max-height: calc(100vh - 100px);\n  overflow-y: auto;\n}\n.sidebar-toc-title {\n  font-family: \"Geist Mono\", monospace;\n  font-size: 12px;\n  font-weight: 500;\n  text-transform: uppercase;\n  letter-spacing: 0.5px;\n  color: var(--geist-quaternary);\n  margin-bottom: 12px;\n}\n.reading-sidebar ul {\n  list-style: none;\n  padding-left: 0;\n  margin: 0;\n  font-size: 13px;\n}\n.reading-sidebar li {\n  margin: 6px 0;\n}\n.reading-sidebar ul ul {\n  padding-left: 14px;\n}\n.reading-sidebar a {\n  color: var(--geist-secondary);\n  text-decoration: none;\n  transition: color 0.15s;\n}\n.reading-sidebar a:hover, .reading-sidebar a.active {\n  color: var(--geist-foreground);\n  font-weight: 600;\n}\n\n/* 后台管理 (/admin) */\n.admin-card-container {\n  background: var(--geist-background);\n  box-shadow: var(--shadow-card-full);\n  border-radius: var(--radius-lg);\n  padding: 32px;\n  margin-bottom: 32px;\n}\n.form-row-2 {\n  display: grid;\n  grid-template-columns: 1fr 1fr;\n  gap: 16px;\n  margin-bottom: 16px;\n}\n@media (max-width: 600px) {\n  .form-row-2 { grid-template-columns: 1fr; }\n}\n.form-field {\n  display: flex;\n  flex-direction: column;\n  gap: 6px;\n  margin-bottom: 16px;\n}\n.form-field label {\n  font-size: 13px;\n  font-weight: 500;\n  color: var(--geist-foreground);\n}\n.form-field input, .form-field select, .form-field textarea {\n  font-family: \"Geist\", sans-serif;\n  font-size: 14px;\n  padding: 9px 12px;\n  background: var(--geist-background);\n  box-shadow: var(--shadow-border);\n  border: none;\n  border-radius: var(--radius-md);\n  color: var(--geist-foreground);\n  outline: none;\n}\n.form-field input:focus, .form-field select:focus, .form-field textarea:focus {\n  outline: 2px solid var(--ds-focus-color);\n  box-shadow: none;\n}\n\n/* 语法高亮 (Console Blue / Purple / Pink) */\n.codehilite .k, .codehilite .kd, .codehilite .kn { color: #eb367f; font-weight: 500; }\n.codehilite .s, .codehilite .s1, .codehilite .s2 { color: #0070f3; }\n.codehilite .nf, .codehilite .na { color: #7928ca; font-weight: 500; }\n.codehilite .c, .codehilite .c1 { color: #666666; font-style: italic; }\n.codehilite .mi, .codehilite .mf { color: #ff5b4f; }\n\n</style>\n\n</head>\n<body>\n\n    <nav class=\"vercel-nav\">\n      <div class=\"nav-brand\">\n        <a href=\"/\" style=\"display:flex;align-items:center;gap:10px;text-decoration:none\">\n          <svg class=\"vercel-triangle\" viewBox=\"0 0 76 65\" fill=\"none\">\n            <path d=\"M37.5274 0L75.0548 65H0L37.5274 0Z\" fill=\"currentColor\"/>\n          </svg>\n          <span class=\"nav-title\">Agent Harness KB</span>\n        </a>\n        <span class=\"nav-badge-pill\">Geist 2.0</span>\n      </div>\n\n      <div class=\"nav-links\">\n        <a class=\"nav-link \" href=\"/\">全景总览</a>\n        <a class=\"nav-link \" href=\"/vad\" style=\"color:var(--ship-red)\">🎯 VAD 专栏 (144)</a>\n        <a class=\"nav-link\" href=\"https://m0rtzz.github.io/paper-notes/\" target=\"_blank\" rel=\"noopener\">顶会 669 篇 ↗</a>\n        <a class=\"nav-link\" href=\"/download/all\">整库打包</a>\n        \n      </div>\n\n      <div class=\"nav-actions\">\n        \n        <button class=\"theme-toggle-btn\" id=\"theme-toggle-btn\" onclick=\"toggleTheme()\" title=\"切换亮暗主题\">🌙</button>\n      </div>\n    </nav>\n    \n<main class=\"vercel-container\">\n\n        <div class=\"report-header-card\">\n          <div class=\"crumb-bar\"><a href=\"/\">Home</a> / <b>fulltext.txt</b></div>\n          <h1 class=\"report-title\">fulltext.txt</h1>\n          <div class=\"report-action-buttons\">\n            <a class=\"btn-primary-dark\" href=\"?dl=1\">Download Text</a>\n          </div>\n        </div>\n        <article class=\"article-body\"><pre><code>ADPretrain: Advancing Industrial Anomaly Detection\nvia Anomaly Representation Pretraining\n\nXincheng Yao1 , Yan Luo3,4∗ , Zefeng Qian1 , Chongyang Zhang1,2∗\nSchool of Information Science and Electronic Engineering, Shanghai Jiao Tong University\n2\nMoE Key Lab of Artificial Intelligence, AI Institute, Shanghai Jiao Tong University\n3\nCollege of Artificial Intelligence, Nanjing Agricultural University\n4\nKey Laboratory of Livestock Farming Equipment, Ministry of Agriculture and Rural Affairs,\nNanjing Agricultural University\n{i-Dover, zefeng_qian, sunny_zhang}@sjtu.edu.cn1\nluoyan@njau.edu.cn3\n\narXiv:2511.05245v1 [cs.CV] 7 Nov 2025\n\n1\n\nAbstract\nThe current mainstream and state-of-the-art anomaly detection (AD) methods are\nsubstantially established on pretrained feature networks yielded by ImageNet pretraining. However, regardless of supervised or self-supervised pretraining, the\npretraining process on ImageNet does not match the goal of anomaly detection\n(i.e., pretraining in natural images doesn’t aim to distinguish between normal and\nabnormal). Moreover, natural images and industrial image data in AD scenarios\ntypically have the distribution shift. The two issues can cause ImageNet-pretrained\nfeatures to be suboptimal for AD tasks. To further promote the development of\nthe AD field, pretrained representations specially for AD tasks are eager and very\nvaluable. To this end, we propose a novel AD representation learning framework\nspecially designed for learning robust and discriminative pretrained representations for industrial anomaly detection. Specifically, closely surrounding the goal\nof anomaly detection (i.e., focus on discrepancies between normals and anomalies), we propose angle- and norm-oriented contrastive losses to maximize the\nangle size and norm difference between normal and abnormal features simultaneously. To avoid the distribution shift from natural images to AD images, our\npretraining is performed on a large-scale AD dataset, RealIAD. To further alleviate the potential shift between pretraining data and downstream AD datasets,\nwe learn the pretrained AD representations based on the class-generalizable representation, residual features. For evaluation, based on five embedding-based AD\nmethods, we simply replace their original features with our pretrained representations. Extensive experiments on five AD datasets and five backbones consistently show the superiority of our pretrained features. The code is available at\nhttps://github.com/xcyao00/ADPretrain.\n\n1\n\nIntroduction\n\nIn recent years, the anomaly detection (AD) field has undergone rapid evolution. Researchers\nhave proposed various deep AD methods, including reconstruction-based [5, 51, 50, 48, 16], featuredistance-based [8, 30, 33, 13], one-class-classification-based (OCC) [36, 24, 49, 23], distillation-based\n[3, 37, 9, 53], and generative-model-based AD methods [12, 20, 14, 52, 10], etc. Although different\ntaxonomies of methods have their distinctive insights and collaboratively address the challenging\nissues in anomaly detection from various perspectives, the essence of well-performed AD methods\n∗\n\nBoth Yan Luo and Chongyang Zhang are Corresponding Author.\n\n39th Conference on Neural Information Processing Systems (NeurIPS 2025).\n\n\fAnomaly Representation Pretraining\n\nAdvancing Downstream AD Methods\nPaDiM\n\nPatchCore\n\nPretrained\nRepresentations\n\nCFLOW\n\nGLASS\n\nUniAD\n\nLarge-scale AD Dataset\n\nMaximize Discrepancies Between Normals and Anomalies\n(a)\n\n(b)\n\nFigure 1: (a) Conceptual illustration of anomaly representation pretraining. (b) Performance comparison on MVTecAD (left) and VisA (right). “w/o” and “w/” refer to without and with our pretrained\nfeatures. Under multiple AD methods and backbones, our pretrained features are consistently superior\nto the original features (dashed lines are overall on top of solid lines).\n\ncan still be attributed to the representation ability of features, i.e., if normal and abnormal features are\nhighly discriminative (e.g., linearly separable), anomalies can be easily detected out as outliers.\nDue to the scarcity and uncertainty of anomalies, the main paradigm in AD is unsupervised (with\nonly normal samples for training). This paradigm makes it hard to learn highly discriminative\nrepresentations for two reasons: (1) With only normal samples, classical AD methods resort to\nself-supervised proxy tasks (e.g., auto-encoding reconstruction) to learn normal representations,\nassuming that models would fail in abnormal image regions. However, only learning normal samples\nmay easily lead to the phenomenon of “pattern collapse” [50, 36], where both normal and abnormal\nfeatures are similar. E.g., anomalies may be well reconstructed in reconstruction-based methods. (2)\nThe scale of conventional AD datasets is usually not too large, relying on limited normal training\ndata for representation learning would also restrict the quality of learned representations.\nTo overcome the weaknesses of self-supervised representation learning from scratch, previous works\n[1, 8, 33] (starting with [1]) have confirmed that utilizing pretrained features yielded by ImageNet\npretraining can significantly improve AD performance compared to features learned from scratch\non the AD datasets. Afterward, mainstream and state-of-the-art AD methods are almost based on\nImageNet-pretrained2 feature networks. However, ImageNet-pretrained features are still suboptimal\nfor AD tasks for two reasons: (1) The conventional pretraining ways (e.g., image classification,\nimage contrastive learning, masked image modeling) don’t meet the goal of anomaly detection, as\nthere is no concept of normal and abnormal during the ImageNet pretraining process. (2) Natural\nimages in ImageNet and image data in AD scenarios typically have the remarkable distribution shift,\nwithout further adaptation, the performance of pretrained features on AD data may be constrained\n[39]. Therefore, to further advance the development of anomaly detection, it’s necessary to construct\nand learn pretrained representations specially for anomaly detection tasks.\nIn this paper, we explore the problem of anomaly representation pretraining, where the objective is to\nlearn pretrained AD representations that are better than ImageNet-pretrained features when applied to\ndownstream AD methods (see Fig.1). Like conventional pretraining works, we expect that anomaly\nrepresentation pretraining would be performed on a large-scale AD dataset. Luckily, the proposal\nof the RealIAD dataset [44] provides us with such a prerequisite. RealIAD has a large enough data\nscale, containing a total of 151050 images, of which 99721 images are normal and 51329 images are\nabnormal. Based on RealIAD, we propose a novel AD representation learning framework specially\ndesigned for learning robust and discriminative pretrained representations for industrial anomaly\ndetection. By pretraining on RealIAD, we can avoid the distribution shift from natural images to\nindustrial AD images. As the main characteristic of AD tasks is to focus on the discrepancies between\nnormals and anomalies, contrastive learning should be the most suitable pretraining paradigm. For\nbetter representation learning, we propose angle- and norm-oriented contrastive losses to maximize\nthe angle size and norm difference between normal and abnormal features simultaneously. As from\nthe feature similarity perspective, differences between two features are reflected in angle and norm.\nFurther considering the potential distribution shift caused by different product categories between\nRealIAD and downstream AD datasets, we learn the pretrained AD representations based on the\n2\n\nThe “ImageNet-pretrained” is to refer to feature networks pretrained on all sorts of large-scale datasets (not\njust ImageNet). As ImageNet is the most well-known pretraining dataset, we still use “ImageNet-pretrained”.\n\n2\n\n\fgeneralizable representation in anomaly detection, residual features [46]. We find that when used\nas pretrained AD representations, residual features are better than vanilla features extracted by the\nfeature network. Our contributions are as follows:\n1. To the best of our knowledge, this is the first study dedicated to anomaly representation pretraining.\nWe construct an AD representation learning framework, which can learn robust and discriminative\npretrained features specially for anomaly detection tasks.\n2. To fully optimize the discrepancies between normal and abnormal features, we propose angle- and\nnorm-oriented contrastive losses, which can maximize the angle size and norm difference between\ntwo features simultaneously.\n3. In five embedding-based3 AD methods, we replace their original features with our pretrained\nfeatures. Extensive experiments show that our pretrained features can consistently surpass the original\nfeatures. Moreover, another merit of our pretrained features is that they are also good representations\nfor few-shot anomaly detection by simply using feature norms as anomaly scores.\n\n2\n\nRelated Work\n\nAnomaly Detection With Pretrained Features. The current mainstream and state-of-the-art AD\nmethods are mostly based on ImageNet-pretrained feature networks. Starting with [1], the authors\nfound that simply combining pretrained features with the KNN algorithm can significantly outperform\nprevious self-supervised methods. Afterward, ImageNet-pretrained features are widely adopted by\nAD methods (we call them embedding-based AD methods). Representative methods include: PaDiM\nand PatchCore. PaDiM [8] extracts pretrained features to model Multivariate Gaussian distribution\nand then utilizes the Mahalanobis distance to measure anomaly scores. PatchCore [33] proposes to\nutilize locally aggregated features and introduces a maximally representative memory bank of normal\nfeatures. However, images in AD scenarios generally have an obvious distribution shift with natural\nimages. To better account for the distribution shift, subsequent methods mainly follow a standard\nparadigm: fixing pretrained feature networks and designing learnable modules. Representative\nmethods include: embedding-based reconstruction methods [45, 50, 16], distillation-based methods\n[3, 37, 9, 41, 53], and normalizing-flow-based methods [34, 12, 35, 47].\nFeature Adaptation to AD Tasks. Due to the distribution shift, pretrained features are still suboptimal\nfor AD tasks. To better utilize pretrained features, this line of work aims to adapt pretrained features\nto the target distribution in AD datasets. However, this doesn’t mean simple fine-tuning is feasible,\nas naive fine-tuning in AD datasets often results in catastrophic collapse (feature deterioration) and\nreduced performance [27, 30]. To this end, PANDA [30] proposes techniques based on early stopping\nand EWC [22], a continual learning method, to mitigate the catastrophic collapse. In [31], Reiss, et\nal. propose a contrastive method, mean-shifted contrastive loss, which is more suitable for AD tasks\nby ensuring the compactness of normal features after fine-tuning. In FYD [54], the authors propose a\ndense non-contrastive learning method for self-supervised learning of compact normal features and\nutilize a stop-gradient strategy to alleviate the collapse. In [32], Rippel, et al. propose a Gaussian\nfine-tuning method, where the pretrained network is fine-tuned by minimizing the Mahalanobis\ndistance to the estimated Gaussian distribution. However, these methods are still not general, as their\nfine-tuned feature networks are applicable only to the trained dataset. By comparison, our work takes\na step forward beyond fine-tuning, which is dedicated to learning robust and discriminative pretrained\nfeatures for downstream AD tasks. More discussions are in Appendix B.1.\n\n3\n\nMethod\n\nOverview. Our proposed anomaly representation learning framework is illustrated in Fig.2. Our\npretrained AD representations are based on residual features. During pretraining, the residual\nfeatures are transformed into a latent space by the Feature Projector (Sec.3.3), and then optimized\nby the angle- and norm-oriented contrastive losses (Sec.3.2) to maximize the angle size and norm\ndifference between normal and abnormal features simultaneously. As our method aims to learn better\nrepresentations for AD tasks, its usage is the same as conventional feature extractors. We can simply\n3\n\nIn this paper, “embedding-based” is a broad concept. We use embedding-based AD methods to refer to all\nsorts of AD methods that utilize pretrained feature networks.\n\n3\n\n\fincorporate our pretrained features outputted by the Feature Projector into existing embedding-based\nAD methods to replace the original features.\nBackbone Network\n\nFeature Projector\nOutput Features\n\nBlock 1\nAbnormal\n\nBlock 2\n\nBlock L\n\nL×\n\nNormal\n\n𝐿\nℒ 𝑎𝑛𝑔𝑙𝑒\n𝐿\nℒ 𝑛𝑜𝑟𝑚\n\nResidual\nOps\n\nFeed Forward MLP\n\nFeature\nProjector\n\n2\nℒ𝑎𝑛𝑔𝑙𝑒\n2\nℒ𝑛𝑜𝑟𝑚\n\nFeature\nProjector\n\nContrastive Training\n\n1\nℒ𝑎𝑛𝑔𝑙𝑒\n1\nℒ 𝑛𝑜𝑟𝑚\n\nFeature\nProjector\n\nFrozen\nLearnable\n\nResidual\nOps\n\nResidual\nOps\n\nSubtract\n\nMulti-Head\nCross Attention\n\nQ\nBlock 1\nNormal Reference Samples\n\nBlock 2\n\nV\nLinear Layer\n\nBlock L\n\nBackbone Network\n\nK\n\nInput Features\n\nLearnable Reference\n\nFigure 2: Framework overview. We learn pretrained AD representations based on residual features,\nwhile not the features directly produced by the backbone network. Residual features are generated\nby subtracting normal reference features (Sec.3.1), which are extracted from the normal reference\nsamples. Features yielded by the Feature Projector are optimized by the angle- and norm-oriented\ncontrastive losses (Sec.3.2). The Feature Projector is based on the Transformer architecture, but we\nalter self-attention to our proposed learnable key/value attention (Sec.3.3).\n\n3.1\n\nConstruction of Fundamental Anomaly Detection Representations\n\nWe first consider what kind of representation features are suitable as pretrained AD representations.\nWe expect that pretrained features can serve as fundamental (general) features in anomaly detection\n(i.e., can perform well on various AD datasets). Therefore, we think that it’s best for pretrained\nrepresentations to be domain-invariant, namely, even if the data distributions in downstream AD\ndatasets differ from that in the pretraining AD dataset, the normal and abnormal representation\ndistributions are consistent (relatively invariant) with those during pretraining. To this end, we utilize\nthe recently proposed class-generalizable representations in anomaly detection, residual features [46],\nas the fundamental AD representations and learn pretrained features. As the authors explained and\nverified in [46] that residual features can be regarded as class-invariant representations compared to\nthe features directly produced by the feature extractor (please refer to [46] for more explanations),\nwe also feel that residual features are potential to be general representations in anomaly detection.\nSpecifically, residual features are obtained by matching and then subtracting. For an input image\nI ∈ RH×W ×3 , a backbone network is utilized to extract multi-level (i.e., L) features. For each\nfeature xlh,w ∈ RCl at level l and position (h, w), we will match it with the nearest normal reference\nfeature x∗n = argminx∈Rl ||xlh,w − x||2 from the corresponding reference feature bank. The Rl =\n{xl,i\nh,w |h/w/l/i ∈ {1, . . . , Hl /Wl /L/K}} is the feature bank for l-th level, where i denotes the i-th\nnormal sample and K is the number of normal reference samples. The residual representation of\nl\nxlh,w is defined as: rh,w\n= xlh,w − x∗n . During pretraining, for each training sample, we randomly\nselect reference samples from the normal set to increase the diversity of residual features.\nDiscussions with ResAD. Compared to ResAD, we mainly take advantage of the residual features\nproposed in ResAD. However, our work and ResAD are clearly two different works, with differences\nin motivations, concerned problems, and implementation methods. Due to page limitation, we provide\ndetailed difference discussions between our work and ResAD in Appendix B.4.\n3.2\n\nContrastive Losses for Anomaly Representation Pretraining\n\nWe know that one main characteristic of AD tasks is the focus on discrepancies between normals and\nanomalies. Thus, good representation features for anomaly detection should be able to ensure sufficient discrepancies between normal and abnormal features. Naturally, to learn such representations,\ncontrastive learning should be the most suitable pretraining paradigm (constructing normal-abnormal\n4\n\n\fcontrastive pairs). From the feature similarity perspective, the discrepancies between two features\nare embodied in two aspects: the angle size between two features and the feature norm difference\n(i.e, mathematically, a feature is a vector, differences between two vectors are reflected in angle and\nnorm). Therefore, we propose angle- and norm-oriented contrastive losses to maximize the angle size\nand norm difference between normal and abnormal features simultaneously. In the following losses,\nwe use x to represent residual features instead of r, as x is most commonly used to represent features.\nAngle-Oriented Contrastive Loss. This loss follows the classical contrastive loss, called InfoNCE\n[42] loss. Following common practice [15, 7], in each training step, we randomly sample a mini-batch\nof B images and randomly augment each image to obtain an augmented image, resulting in 2B data\nsamples (i.e., for i-th sample, the index of its augmented sample is denoted as i′ = i + B). In this\nwork, we sequentially apply three simple augmentations: random color jitters, random gray scale,\nand random Gaussian blur. Then, we employ the backbone network to extract features for the 2B\nsamples, with a total of 2N4 features. The i-th (i ∈ {1, 2, . . . , N }) feature xi and the feature from\nthe same position in the augmented image, denoted as xi′ , i′ = i + N , will be treated as a positive\npair. The other 2(N − 1) features within the mini-batch are treated as negative examples. Then, the\nInfoNCE loss for a positive pair (xi , xi′ ) is defined as:\n\u0013\n\u0012\nexp(sim(xi , xi′ )/τ )\n(1)\nLnce (xi , xi′ ) = − log P2N\nk=1 I[k̸=i] · exp(sim(xi , xk )/τ )\nwhere I[k̸=i] ∈ {0, 1} is an indicator function evaluating to 1 iff k ̸= i, τ denotes a temperature\nparameter, and sim(xi , xi′ ) = xTi xi′ /||xi ||2 ||xi′ ||2 is the cosine similarity between xi and xi′ .\nHowever, the conventional contrastive learning objective is not suitable for anomaly representation\npretraining, as negative examples contain both normal and abnormal features. When xi belongs\nto normal features, only abnormal features should be treated as negative examples to enlarge the\ndiscrepancies between normal and abnormal features. In addition, in mathematics, features can be\nviewed as vectors starting from the origin. Cosine similarity in fact measures the angle between\ntwo features with the origin as the center. However, previous work [31] indicated that the standard\ncontrastive loss prefers to optimize features uniformly distributed on the origin-centered sphere, but\nit is not conducive to making normal and abnormal features more discriminative. This is harmful for\nanomaly detection. Inspired by [31], we measure the angle between two features with respect to the\ncenter of the normal features rather than the origin. Let us denote the center of all normal features\nin the training set by c = Ex∈Xnormal [x]. Then, for each feature xi , we first subtract the center c to\nform a center-shifted feature x̄i = xi − c with the center c as origin and then calculate the cosine\nsimilarity sim(x̄i , x̄i′ ). In this way, the contrastive loss preserves features’ distances to the center c\nwhile maximizing the angles between normal and abnormal features. For a positive pair (xi , xi′ ), the\nangle-oriented contrastive loss is defined as:\n\u0012\n\u0013\nexp(sim(x̄i , x̄i′ )/τ )\nLangle (xi , xi′ ) = − log P2N\n(2)\nk=1 I[k̸=i] · I[mk ̸=mi ] · exp(sim(x̄i , x̄k )/τ )\nwhere mi ∈ {0, 1} is the feature label, mi = 0 denotes xi is a normal feature and mi = 1 denotes xi\nis abnormal (mk has the same meaning). In RealIAD, each sample has a ground-truth mask, we can\ndownsample the mask to get feature labels. Further, we can analyze that the loss in Eq.(2) only uses\nxi′ as the positive pair. Other features with different labels from xi are used as negative pairs. This\nensures that we only perform contrast between normal and abnormal. In addition, we only utilize xi\nas the anchor feature, without using xi′ as the anchor feature. That is to say, there will be no contrast\nbetween the augmented image and abnormal data in our angle-oriented contrastive loss.\nNorm-Oriented Contrastive Loss. Unlike the above angle-oriented contrastive loss, this loss aims\nto enlarge the feature norm difference between normal and abnormal features. The basic idea follows\none-class-classification (OCC) learning [40, 36], where normal features are optimized to be located\ninside the origin-centered hypersphere. In mathematics, feature norm can be viewed\npas the distance\nfrom the feature vector to the origin. Specifically, we use the pseudo-Huber distance ||xi ||22 + 1 − 1\nas the feature norm, which is a more robust distance measure that interpolates from quadratic to linear\npenalization [24]. Then, we denote the\npdistance from the feature xi to the hypersphere as di = ni − r,\nwhere ni refers to the feature norm ||xi ||22 + 1 − 1, and r is the radius of the hypersphere and is\n4\n\nFor symbol simplicity, we use N to represent the number of features in one feature level. Please note that\nwe extract multi-level features, with contrastive learning on each level.\n\n5\n\n\fp\nset to 0.4 (i.e., when ||xi ||22 = 1, ||xi ||22 + 1 − 1 ≈ 0.4. Setting r to 0.4 is equivalent to the unit\nhypersphere based on Euclidean distance). The ideal learning objective is to make all normal features\ncontracted inside the hypersphere, and for features that are already within the hypersphere, we don’t\nneed to excessively shrink towards the origin to avoid mode collapse. To this end, we propose the\nfollowing contraction loss:\nLcon (xi ) = −logsig(−di ) · edi\n(3)\nwhere logsig presents logarithmic sigmoid function. To better understand this loss, we further derive\nthe gradients with respect to the model weights (denoted as W) as follows:\n∂Lcon (xi )\n∂di\n∂di\n= (1 − σi )\n− logσi · edi ·\n(4)\n∂W\n∂W\n∂W\nwhere σi presents sigmoid(−di ) and can be explained as the probability that the feature inside the\nhypersphere. Thus, the features close to the origin have large probabilities (i.e., di → −r, σi → 1)\nand thus small 1 − σi and −logσi , while features outside the hypersphere have small σi → 0 and\nlarge −logσi (thus large gradient values). Thus, the loss in Eq.(3) can adaptively tune attention to\nassign larger gradients to the features outside the hypersphere for better contraction.\nFor abnormal features, we expect that they are located outside the hypersphere and are highly\ndiscriminative from normal features. Thus, unlike OCC learning, we contrastively optimize the norms\nof abnormal features to form a certain gap between them and normal features. We further introduce\na margin ∆r and define an abnormal radius r′ = r + ∆r. When an abnormal feature xj is inside\nthe hypersphere with a radius r′ , it will be pushed outside of the hypersphere. In addition, to avoid\noverfitting to anomalies during pretraining, we don’t further push away the abnormal features that are\nalready outside the hypersphere. Then the learning objective for xj is as follows:\n(\n′\n− logsig(−(r′ − nj )) · er −nj , nj ≤ r′ ,\n′\nLcon (xj ) =\n(5)\n0,\nnj &gt; r′ .\nEq.(5) is based on Eq.(3), but dj = r′ − nj is reversed (di = ni − r). We can analyze that the learning\nobjectives in Eq.(3) and Eq.(5) are encouraging to contract normal features inside the hypersphere\nwith radius r and push abnormal features outside the hypersphere with radius r′ . Thus, combining the\ntwo learning objectives, we call the final loss as norm-oriented contrastive loss, which is defined as:\nLnorm (xi ) = I[mi =0] · Lcon (xi ) + I[mi =1] · L′con (xi )\n(6)\nIn Eq.(6), we unify the symbols, xi can be either normal or abnormal, indicated by mi = 0 or 1.\nTotal Loss. By combining angle- and norm-oriented contrastive losses, the whole loss for training is\nas follows:\n2N\n1 X\nL=\nλ · I[i≤N ] · Langle (xi ) + Lnorm (xi )\n(7)\n2N i=1\nwhere λ is set to 1 by default (please see the results in Tab.10 in Appendix E).\n3.3\n\nFeature Projector\n\nAs illustrated in the right part of Fig.2, the architecture of the Feature Projector is based on the\npopular Transformer network [43]. Differently, we replace self-attention in vanilla Transformer with\nour proposed Learnable Key/Value Attention. As we find that directly using vanilla Transformer as\nthe Feature Projector has poor performance (see Tab.2(b)).\nLearnable Key/Value Attention. Specifically, we randomly initialize Nr learnable reference feature\nrepresentations and define them as R ∈ RNr ×C . Then we utilize a fully connected layer to project\nR to the hidden dimension in Transformer into Rh ∈ RNr ×Ch , and a single Rh is used for all\nlayers. Our idea for enhancing the vanilla self-attention is to treat input features as Query vectors and\nlearnable reference representations as Key and Value vectors, and then apply a cross-attention between\nthem. After cross-attention, different from the original addition operation in the residual connection,\nwe merge the input features and attention outputs through a subtraction operation. We can understand\nthe learnable key/value attention module in this way: the learnable reference representations can\nadaptively learn to represent normal patterns. As Value vectors, this makes attention outputs mainly\ncontain normal patterns. By subtraction, we aim to eliminate the normal representations in the\nresidual feature distribution adaptively learned by the network, further increasing the discrepancy\nbetween normal and abnormal residual features. In Sec.4.3, we provide more explanations to our\nLearnable Key/Value Attention based on the results in Tab.2(b).\n6\n\n\f4\n\nExperiments\n\n4.1\n\nExperimental Setup\n\nTable 1: Anomaly detection and localization results with the original features and our pretrained\nfeatures. ·/· means image-level AUROC and PRO. † means our pretrained features are utilized in\nthese AD models. For GLASS, we use the GLASS-h variant in [6].\nModel\n\nDatasets\n\nPaDiM\n[8]\n\nPaDiM†\n\nPatchCore\n[33]\n\nPatchCore†\n\nCFLOW\n[12]\n\nCFLOW†\n\nGLASS\n[6]\n\nGLASS†\n\nUniAD\n[50]\n\nUniAD†\n\nFeatureNorm\n\nFeatureNorm†\n\nDINOv2-Base [26]\n\nMVTecAD\nVisA\nBTAD\nMVTec3D\nMPDD\n\n95.6/93.1\n91.7/84.4\n96.6/74.4\n82.1/92.0\n80.9/87.8\n\n95.9+0.3/92.5-0.6\n93.1+1.4/85.7+1.3\n95.2-1.4/74.7+0.3\n81.5-0.6/92.4+0.4\n88.3+7.4/92.1+4.3\n\n95.5/82.7\n82.8/69.9\n90.2/61.7\n72.9/78.9\n89.4/72.2\n\n99.0+3.5/87.4+4.7\n92.9+10.1/81.3+11.4\n94.3+4.1/62.2+0.5\n82.8+9.9/87.5+8.6\n92.4+3.0/88.7+16.5\n\n97.7/92.3\n94.3/89.4\n93.2/70.4\n88.6/91.9\n91.3/93.2\n\n98.3+0.6/92.9+0.6\n95.2+0.9/88.6-0.8\n95.2+2.0/72.3+1.9\n88.5-0.1/92.5+0.6\n91.7+0.4/93.7+0.5\n\n98.3/93.5\n93.3/90.1\n92.3/78.2\n84.5/90.2\n91.1/90.6\n\n99.0+0.7/95.2+1.7\n93.5+0.2/87.7-2.4\n95.2+2.9/81.6+3.4\n87.3+2.8/90.7+0.5\n95.7+4.6/92.3+1.7\n\n71.1/81.5\n90.6/84.4\n78.0/67.9\n66.6/78.3\n76.9/53.4\n\n97.1+26.0/91.2+9.7\n94.4+3.8/87.3+2.9\n93.4+15.4/71.1+3.2\n85.3+18.7/91.8+13.5\n88.6+11.7/91.9+38.5\n\n48.4/28.9\n52.2/30.1\n54.9/15.3\n49.0/54.6\n44.0/36.3\n\n98.2/92.8\n94.8/87.2\n95.1/71.7\n84.8/91.2\n93.6/93.1\n\nDINOv2-Large [26]\n\nMVTecAD\nVisA\nBTAD\nMVTec3D\nMPDD\n\n98.7/91.0\n92.6/85.6\n94.0/75.2\n83.0/87.7\n87.5/86.8\n\n98.6-0.1/92.4+1.4\n95.1+2.5/86.7+1.1\n94.6+0.6/75.6+0.4\n86.6+3.6/88.8+1.1\n94.3+6.8/90.1+3.3\n\n97.6/83.8\n85.1/71.1\n93.6/63.2\n75.7/74.7\n93.6/79.5\n\n99.0+1.4/88.0+4.2\n91.5+6.4/82.5+11.4\n93.5-0.1/61.8-1.4\n82.5+6.8/85.3+10.6\n90.7-2.9/87.0+7.5\n\n98.8/92.7\n96.2/90.0\n94.8/74.7\n91.8/93.0\n95.3/94.0\n\n98.9+0.1/93.2+0.5\n96.9+0.7/90.6+0.6\n95.8+1.0/76.4+2.0\n91.1-0.7/93.3+0.3\n93.4-1.9/94.1+0.1\n\n98.4/95.3\n93.3/90.4\n93.8/80.9\n83.4/92.0\n91.6/95.7\n\n99.1+0.7/96.2+0.9\n94.0+0.7/91.8+1.4\n95.6+1.8/82.3+1.4\n87.8+4.4/93.3+1.3\n95.3+3.7/98.0+2.3\n\n79.6/83.0\n90.9/84.0\n85.1/71.9\n79.2/87.9\n76.0/62.9\n\n96.9+17.3/91.6+8.6\n94.8+3.9/88.7+4.7\n92.3+7.2/72.5+0.6\n83.0+3.8/91.8+3.9\n90.6+14.6/92.6+29.7\n\n48.4/31.4\n45.7/33.4\n46.1/18.7\n47.4/53.5\n39.1/45.8\n\n98.7/93.1\n96.2/88.3\n94.3/73.7\n86.0/91.9\n94.6/95.0\n\nCLIP-Base [29]\n\nMVTecAD\nVisA\nBTAD\nMVTec3D\nMPDD\n\n93.4/89.9\n87.7/75.6\n93.9/70.2\n71.7/80.8\n85.6/79.3\n\n98.1+4.7/91.8+1.9\n92.6+4.9/80.3+4.7\n95.4+1.5/73.2+3.0\n81.3+9.6/87.1+6.3\n92.0+6.4/89.5+10.2\n\n92.9/76.0\n81.2/63.3\n91.4/58.4\n65.0/62.7\n80.5/59.9\n\n98.3+5.4/85.7+9.7\n92.5+11.3/80.6+17.3\n91.6+0.2/63.6+5.2\n77.9+12.9/84.6+21.9\n90.6+10.1/88.6+28.7\n\n94.2/90.3\n89.5/83.4\n94.3/71.0\n82.1/90.1\n85.2/90.4\n\n96.7+2.5/91.2+0.9\n91.5+2.0/84.7+1.3\n93.9-0.4/72.7+1.7\n83.8+1.7/90.4+0.3\n90.1+4.9/92.7+2.3\n\n97.1/94.8\n92.1/85.0\n92.5/80.5\n79.2/90.8\n92.6/94.2\n\n98.0+0.9/93.8-1.0\n91.4-0.7/85.4+0.4\n94.3+1.8/81.3+0.8\n80.7+1.5/89.2-0.6\n94.3+1.7/94.3+0.1\n\n92.2/87.7\n83.5/79.8\n90.8/66.8\n65.3/81.6\n82.2/78.4\n\n93.1+0.9/88.8+1.1\n87.0+3.5/79.8+0.0\n94.2+3.4/72.5+5.7\n82.6+17.3/90.7+9.1\n86.8+4.6/91.5+13.1\n\n48.7/36.3\n48.9/31.9\n47.7/14.0\n50.9/10.4\n50.8/20.6\n\n96.9/91.4\n92.5/82.6\n94.1/72.0\n81.4/90.6\n93.6/91.7\n\nCLIP-Large [29]\n\nMVTecAD\nVisA\nBTAD\nMVTec3D\nMPDD\n\n89.4/91.7\n90.1/82.7\n90.8/73.4\n71.4/87.0\n82.9/88.8\n\n98.4+9.0/92.5+0.8\n95.2+5.1/87.6+4.9\n95.4+4.6/74.9+1.5\n84.7+13.3/92.2+5.2\n94.8+11.9/94.2+5.4\n\n97.0/87.0\n87.7/78.6\n91.8/64.1\n75.1/82.6\n87.7/83.4\n\n98.9+1.9/87.5+0.5\n94.5+6.8/85.2+6.6\n93.9+2.1/65.7+1.6\n83.3+8.2/87.4+4.8\n92.6+4.9/92.5+9.1\n\n97.3/91.4\n93.6/88.5\n93.7/74.4\n84.9/91.8\n92.2/93.5\n\n98.0+0.7/91.8+0.4\n94.9+1.3/89.7+1.2\n94.8+1.1/72.9-1.5\n85.1+0.2/92.6+0.8\n90.1-2.1/94.7+1.2\n\n93.8/87.3\n83.0/76.6\n94.0/76.4\n82.9/91.2\n91.6/95.7\n\n98.8+5.0/95.2+7.9\n93.4+10.4/88.9+12.3\n95.5+1.5/82.6+6.2\n86.2+3.3/89.9-1.3\n94.1+2.5/98.3+2.6\n\n92.6/88.9\n86.6/85.1\n83.8/71.5\n76.4/90.5\n73.0/76.2\n\n96.4+3.8/90.8+1.9\n91.3+4.7/86.7+1.6\n94.8+11.0/74.2+2.7\n81.4+5.0/92.4+1.9\n91.7+18.7/94.5+18.3\n\n51.6/70.0\n50.3/67.8\n54.8/15.0\n51.9/18.9\n50.3/26.4\n\n98.4/92.9\n94.8/89.8\n94.2/74.8\n84.4/93.0\n94.1/95.1\n\nImageBind [11]\n\nMVTecAD\nVisA\nBTAD\nMVTec3D\nMPDD\n\n97.9/92.6\n92.6/86.3\n94.6/75.9\n79.5/90.3\n91.0/92.0\n\n98.8+0.9/92.1-0.5\n95.6+3.0/88.6+2.3\n95.9+1.3/76.8+0.9\n84.4+4.9/92.0+1.7\n94.4+3.4/95.1+3.1\n\n98.5/88.9\n91.4/81.9\n94.6/66.7\n78.4/86.3\n92.6/89.1\n\n98.9+0.4/88.8-0.1\n94.8+3.4/86.3+4.4\n95.6+1.0/67.3+0.6\n82.6+4.2/87.0+0.7\n94.8+2.2/94.2+5.1\n\n97.8/90.7\n94.9/89.5\n94.9/72.6\n85.8/91.8\n92.6/94.0\n\n98.6+0.8/91.5+0.8\n95.3+0.4/90.2+0.7\n95.4+0.5/75.6+3.0\n83.5-2.3/91.8+0.0\n91.5-1.1/95.0+1.0\n\n98.7/95.6\n94.9/88.7\n94.9/84.8\n83.5/91.8\n96.4/99.0\n\n99.4+0.7/96.4+0.8\n95.9+1.0/91.0+2.3\n95.8+0.9/84.3-0.5\n86.2+2.7/91.8+0.0\n95.7-0.7/99.0+0.0\n\n96.0/91.2\n90.3/87.4\n67.1/59.2\n80.2/90.8\n60.7/52.3\n\n98.1+2.1/91.5+0.3\n93.2+2.9/88.2+0.8\n94.7+27.6/75.8+16.6\n80.8+0.6/92.0+1.2\n93.6+32.9/95.0+42.7\n\n83.5/80.3\n70.0/73.6\n37.5/19.3\n52.2/64.5\n44.9/40.7\n\n98.6/92.6\n95.3/90.0\n93.5/76.9\n83.3/92.2\n94.2/95.6\n\nDatasets. We conduct extensive experiments on five AD datasets, including MVTecAD [2], VisA\n[56], BTAD [25], MVTec3D [4], and MPDD [18], to evaluate the effectiveness of our pretrained AD\nrepresentations.\nMetrics. For image-level anomaly detection, the standard metric in anomaly detection, AUROC, is\nused [33, 3, 2]. Nonetheless, since abnormal areas are usually smaller than normal areas, this may\ncause overestimated pixel-level AUROCs. This means that for small anomalies, even if they are not\ncorrectly located, the pixel-level AUROC is still high. Thus, we adopt the Per-Region-Overlap (PRO)\nmetric proposed in [3] for anomaly localization evaluation.\nImplementation Details. Like most pretraining works, we employ multiple backbones for anomaly\nrepresentation pretraining. In this way, we can more comprehensively validate our method and\nprovide more pretrained AD network options. Specifically, we select strong modern pretrained\nbackbones, including CLIP [29] series, DINOv2 [26] series and ImageBind [11]. Due to different\nnetwork depths, the intermediate layers to output features are different among these selected models.\nThe details are provided in Appendix D. Then, for each layer, we construct a Feature Projector (the\nnumber of layers is 1) for learning pretrained AD representations. We fix the parameters of the\nbackbone networks, as preserving their basic visual representation capabilities is beneficial (see\nTab.2(a)). We use Adam [28] optimizer with 1e−4 learning rate to train. The batch size is set as 32\nand the total training epochs are 10. The temperature hyperparameter τ and margin ∆r are set as\n0.15 and 0.75. The Nr is set to 2048. We use 42 as the random seed during pretraining. All training\nand test images are resized and cropped to 224 × 224.\nSetup. Our work is to learn proprietary pretrained features for AD tasks. Thus, we validate the\neffectiveness of our pretrained features by applying them into embedding-based AD methods to\nreplace the original features. We mainly select representative methods as the baselines, including\nPaDiM [8] and PatchCore [33] (they are based on feature comparison without learnable parameters,\nthus can intuitively reflect the quality of pretrained features). Other methods include the influential\nCFLOW [12] and UniAD [50], and the latest state-of-the-art method GLASS [6]. When generating\nresidual features, we match each input image with 8 reference samples. In addition, with the normoriented contrastive loss, a valuable advantage of our pretrained features is that normals and anomalies\ncan be well distinguished based on feature norm. Then, we further propose a simple AD baseline\n(denoted by FeatureNorm), where we directly utilize feature norms as anomaly scores.\n4.2\n\nMain Results\n\nWe report the dataset-level average results across their respective data subsets in Tab.1. To guarantee\nthe rationality of result comparison, with the five backbones, we reproduce these methods based on\ntheir official open-source code and default hyperparameters and don’t perform any hyperparameter\ntuning. By comparison, we can see that with our pretrained features, the performance of these\n7\n\n\fmethods can be consistently improved on multiple datasets with various backbone networks. This\ndemonstrates the superiority of our pretrained features and also confirms that learning proprietary\npretrained features for AD tasks is effective and valuable. Especially, in some cases (e.g., CLIPBase with PatchCore, DINOv2-Base with UniAD), the original features perform poorly, while our\npretrained features can bring more significant improvements. Finally, as shown in the last column\n(FeatureNorm† ), another superiority of our pretrained features lies in their capacity to achieve good\nAD performance based on simple feature norms even without any downstream AD modeling, while\nthe ImageNet-pretrained features don’t have such an advantage.\nExplanations on Result Comparison. Our work\ndoesn’t directly propose an AD model, but aims to\nprovide better pretrained representations for AD tasks.\nThus, applying our pretrained features in existing AD\nmodels to demonstrate performance improvement is\nthe most reasonable way to validate the effectiveness\nof our work. Therefore, unlike previous AD papers\nthat compare their proposed models with other models, we focus on the performance improvement of the\nsame model with and without our pretrained features. Figure 3: Feature t-SNE visualization. “w/o”\nand “w/” refer to without and with our preQualitative Results. Due to page limitation, the trained features. These features are from\nqualitative results are shown in Fig.4 in Appendix F. the “capsules” class of the VisA dataset. We\nIntuitive Visualization. To intuitively illustrate the show more visualization results in Fig.5 in\neffectiveness of our method, we show the t-SNE visu- Appendix F.\nalization of original features and our pretrained features in Fig.3. It can be found that with our anomaly\nrepresentation pretraining, normal features are more compact, normal and abnormal features are\nmore separated from each other. This intuitively demonstrates that our pretrained features are more\ndiscriminative AD representations.\n4.3\n\nAblation Studies\n\nIn ablation studies, we utilize ImageBind [11] as the backbone network, followed by PaDiM and\nPatchCore as the baseline AD methods. Moreover, we also measure anomaly scores by feature norms\n(see the Setup part in Sec.4.1). We perform ablation experiments on the VisA dataset.\nAre pretrained features effective? As shown in Tab.2(a), all three AD baselines can achieve better\nresults based on our pretrained features (ExpID 2.2 and 2.7 vs. 2.1). This demonstrates that our\nanomaly representation pretraining method is effective.\nAre residual features better pretrained AD representations? In Tab.2(a), the results show that\nresidual features can bring further gains (ExpID 2.7 vs. 2.2), especially under FeatureNorm. In ResAD\n[46], the authors explained and verified that residual features are class-generalizable representations.\nOur studies also confirm the authors’ statements and show that residual features are better pretrained\nAD representations compared to the vanilla features extracted by the backbone network.\nContrastive Losses. The ablation studies on contrastive losses are also in Tab.2(a). Only learning\nwith the angle-oriented or norm-oriented contrastive loss can achieve good performance (ExpID 2.5,\n2.6 vs. 2.1), while combining the two contrastive losses can further outperform each single loss\nconsistently (ExpID 2.7 vs. 2.5, 2.6). This indicates that the two proposed contrastive losses are\ncomplementary and simultaneously optimizing the angle size and norm difference between features\nis more conducive to obtain good representations for anomaly detection.\nDoes the backbone network need to remain fixed? In our method, we opt to keep the backbone\nnetwork fixed and only optimize the Feature Projector. Because we think that the basic visual\nrepresentation capabilities possessed in the pretrained backbone are still valuable and important,\nand training the whole feature network on AD datasets may cause impairment to the basic visual\nrepresentation capabilities. The results in Tab.2(a) verify our confirmation that the learnable backbone\nnetwork will lead to performance degradation (ExpID 2.2 vs. 2.3 and ExpID 2.7 vs. 2.8). This also\nindicates that the AD field still needs larger-scale and better-quality datasets to support full-backbonebased anomaly representation pretraining.\n8\n\n\fTable 2: Ablation study results. (a) Residual represents residual features. Non-residual means the\nvanilla features extracted by the backbone network. Angle and Norm mean angle- and normal-oriented\ncontrastive losses, respectively. Fixed and Non-fixed represent whether the backbone network remains\nfixed during pretraining. Note that when the backbone network is fixed, the Feature Projector is\nrequired. Otherwise, there are no learnable parameters. (b) All Attentions actually represent the\nTransformer structure (Attention + MLP).\n(b) Architecture ablation studies for the Feature Projector.\n\n(a) Framework ablation studies.\nExpID\n2.1\n2.2\n\nPretrained\nRepresentations\n\nContrastive\nLosses\n\nFeature\nProjector\n\nBackbone\nNetwork\n\nPaDiM\n\nPatchCore\n\nFeatureNorm\n\nNon-residual\n\n/\nAngle&amp;Norm\n\n/\nw/\n\nFixed\nFixed\n\n92.6/86.3\n93.5/86.1\n\n91.6/81.3\n93.6/85.1\n\n49.2/44.5\n82.9/83.9\n\nAngle&amp;Norm\n\n/\n\nNon-fixed\n\n89.3/83.4\n\n91.9/84.8\n\n81.0/83.2\n\n/\nAngle\nNorm\nAngle&amp;Norm\n\n/\nw/\nw/\nw/\n\nFixed\nFixed\nFixed\nFixed\n\n93.9/85.6\n93.9/85.2\n93.7/85.3\n95.4/88.7\n\n92.9/86.5\n93.2/83.8\n90.9/84.5\n94.6/87.0\n\n91.3/86.8\n83.9/83.0\n92.4/85.1\n94.2/89.0\n\nAngle&amp;Norm\n\n/\n\nNon-fixed\n\n81.3/56.0\n\n78.4/32.1\n\n51.9/20.7\n\n2.3\n2.4\n2.5\n2.6\n2.7\n\nResidual\n\n2.8\n\nArchitecture\n\nPaDiM\n\nPatchCore\n\nFeatureNorm\n\nLinear Projector\nMLP Projector\nSelf Attention\nCross Attention\nSelf + Cross Attention\nLearnable Key/Value Attention (ours)\n\n93.8/87.4\n93.4/88.1\n93.7/88.8\n94.8/88.9\n94.8/88.7\n95.5/88.8\n\n94.0/86.8\n94.2/79.1\n92.9/84.3\n94.6/82.9\n94.0/80.9\n94.7/87.6\n\n87.9/82.1\n94.2/90.2\n92.9/84.9\n93.1/86.5\n92.9/84.4\n94.5/89.3\n\nFeature Projector Architecture. The results are shown in Tab.2(b). Our Learnable Key/Value\nAttention (LKV-Attn) can outperform other network architectures. In Cross Attention, we convert\nnormal reference features into residual features and then utilize them as Key and Value. Compared\nto Self Attention, Cross Attention can perform better. This indicates that only embodying normal\npatterns in Key and Value should be effective. In our LKV-Attn, we further adopt learnable Key and\nValue. Compared to limited normal patterns in Cross Attention, the learnable reference (Sec.3.3) in\nour LKV-Attn can adaptively learn to represent normal patterns and better cover key normal feature\npatterns in the residual feature distribution during pretraining.\nFor hyperparameter ablation studies, please see Appendix E.\n4.4\n\nFurther Analysis\n\nSample Efficiency. We further conduct experiments about sample efficiency, where we utilize only\n10% normal samples from each downstream AD dataset for training. The results are in Tab.3(a).\nCompared to the results in Tab.1, with less training data, our pretrained features can bring more\nsignificant performance improvement, indicating that our pretrained features are beneficial for\nimproving the sample efficiency of downstream AD models.\nTable 3: Sample efficiency and robustness analysis. † means our pretrained features are utilized in\nthese AD models.\n(b) Robustness experiment results.\n\n(a) Sample efficiency experiment results.\nDatasets\n\nPaDiM\n\nPaDiM†\n\nPatchCore\n\nPatchCore†\n\nDatasets\n\nPaDiM\n\nPaDiM†\n\nPatchCore\n\nPatchCore†\n\nMVTecAD\nVisA\nBTAD\nMVTec3D\nMPDD\n\n81.4/88.6\n82.8/79.3\n89.2/75.2\n66.3/85.8\n63.1/75.6\n\n96.8+15.4/90.3+1.7\n93.0+10.2/83.3+4.0\n94.8+5.6/76.3+1.1\n82.1+15.8/91.9+6.1\n91.4+28.3/94.8+19.2\n\n96.5/86.2\n88.9/78.7\n93.1/65.5\n74.3/84.7\n79.1/84.4\n\n98.2+1.7/87.7+1.5\n93.9+5.0/85.7+7.0\n94.0+0.9/68.9+3.4\n80.8+6.5/87.1+2.4\n90.8+11.7/93.3+8.9\n\nMVTecAD\nVisA\nBTAD\nMVTec3D\nMPDD\n\n86.6/82.7\n82.8/75.6\n85.4/70.9\n72.0/83.1\n79.8/83.8\n\n88.2+1.6/84.6+1.9\n87.4+4.6/79.9+4.3\n90.5+5.1/73.4+2.5\n76.2+4.2/84.9+1.8\n84.0+4.2/86.4+2.6\n\n87.7/80.6\n83.4/71.5\n85.1/62.4\n71.5/78.6\n83.4/79.1\n\n89.2+0.8/81.4+1.5\n86.9+3.5/78.7+7.2\n86.3+1.2/65.6+3.2\n73.8+2.3/80.5+1.9\n84.5+1.1/85.8+6.7\n\nRobustness to Noise. We further conduct experiments with noisy data to investigate the robustness.\nSpecifically, we add abnormal data from the test set to the training set with a noise ratio of 0.1. We\nadopt the “overlap” setting from SoftPatch [19]. The results are in Tab.3(b). It can be found that the\nperformance of AD models significantly decreases when there is noisy data. However, our pretrained\nfeatures still bring performance improvement, and the magnitude is even greater compared to the\nresults in Tab.1. This indicates that our pretrained features are more robust to noisy data than the\noriginal features. For the robustness, we think that a possible explanation may be: Although some\nnoises are added to the training set, it is still dominated by normal features. For PatchCore as an\nexample, the training process is to subsample a coreset. With better representation, abnormal features\nare more likely to be sparse outliers, making them more likely not to be sampled into the coreset.\nThus, the results show better robustness.\nReference Set Sensitivity.\nSince residual features depend on few-shot normal reference samples, different normal reference samples may result in performance variations.\nThus, we further investigate the sensitivity of our pretrained features to the reference set.\n9\n\n\fWe randomly sample three reference sets (with\n8 shot), conduct experiments respectively. We\nDatasets\nPaDiM\nPaDiM\nPatchCore\nPatchCore\nreport variance bars in Tab.4. Overall, our preMVTecAD 97.9/92.6 98.6±0.14/92.1±0.05 98.5/88.9 98.8±0.09/88.4±0.37\ntrained features are not very sensitive to the refer92.6/86.3 95.4±0.21/88.7±0.09 91.4/81.9 94.4±0.24/86.8±0.37\nVisA\nBTAD\n94.6/75.9 95.9±0.29/76.6±0.17 94.6/66.7 95.6±0.05/68.0±1.06\nence set, and the performance is not significantly\nMVTec3D 79.5/90.3 84.1±0.31/92.0±0.05 78.4/86.3 82.1±0.37/87.3±0.22\nMPDD\n91.0/92.0 93.8±0.46/95.0±0.14 92.6/89.1 93.8±1.03/93.7±0.34\naffected by reference variations. However, we\nfurther point out that if the reference set is not\nrepresentative enough (lacking some normal patterns), the results would be more affected. We provide\nmore discussions in Appendix C and introduce a feasible method for tackling this issue.\nTable 4: Reference set sensitivity experiments.\n†\n\n†\n\nComparison to Fine-tuning Baselines. In Appendix B.1, we further discuss and compare with\nprevious per-dataset fine-tuning methods, such as FYD [54], MSC [31], and PANDA [30].\nPretraining-test Data Leakage. A non-negligible concern about our work is whether there may be\nanomaly data leakage between the pretraining dataset and the test datasets. We discuss this issue in\nAppendix B.2.\n4.5\n\nFew Shot Anomaly Detection\n\nAs stated in the Setup part in Sec.4.1 and shown\nTable 5: Performance comparison with FSAD in Tab.1, one valuable advantage of our premethods on the MVTecAD and VisA datasets. “∗” trained features is that the feature norms can\nindicates results of these methods are from Win- be directly used as anomaly scores. This means\nCLIP [17]. “#” indicates results of these methods that when only few-shot normal samples are\nare from KAG-Prompt [38]. “‡” indicates these accessible, we can easily construct a few-shot\nmethods employ ImageBind [11] as the feature ex- AD (FSAD) method (denoted by FeatureNorm).\nSpecifically, for an input sample, we extract pretractor.\ntrained residual features. Then, for a pretrained\nMVTecAD\nVisA\nSetup\nMethod\nVenue\nfeature xi , the L2 norm ||xi ||2 is used as the\nI-AUROC P-AUROC PRO I-AUROC P-AUROC PRO\nSPADE\narXiv2020\n82.9\n92.0\n85.7\n80.7\n96.2\n85.7\nanomaly score. To demonstrate the potential of\nPatchCore\nCVPR2022\n86.3\n93.3\n82.3\n81.6\n96.1\n82.6\nWinCLIP\nCVPR2023\n94.4\n96.0\n88.4\n84.6\n96.8\n86.2\nour pretrained features for FSAD, we compare\nAnomalyGPT\nAAAI2024\n95.5\n95.6\n90.0\n88.6\n96.4\n83.4\n2-shot\nPromptAD\nCVPR2024\n95.7\n96.2\n88.5\n88.3\n97.1\n85.8\nInCTRL\nCVPR2024\n94.0\n/\n/\n85.8\n/\n/\nour FeatureNorm with mainstream FSAD methResAD\nNeurIPS2024\n94.4\n95.6\n/\n84.5\n95.1\n/\nKAG-Prompt\nAAAI2025\n96.6\n96.5\n91.1\n92.7\n97.4\n86.7\nods. We follow the 2-shot and 4-shot settings in\nFeatureNorm (ours)\n95.3\n95.6\n90.9\n92.4\n97.6\n87.5\nKAG-Prompt [38], the results are in Tab.5. ComSPADE\narXiv2020\n84.8\n92.7\n87.0\n81.7\n96.6\n87.3\nPatchCore\nCVPR2022\n88.8\n94.3\n84.3\n85.3\n96.8\n84.9\nWinCLIP\nCVPR2023\n95.2\n96.2\n89.0\n87.3\n97.2\n87.6\npared with these competing methods, our simple\nAnomalyGPT\nAAAI2024\n96.3\n96.2\n90.7\n90.6\n96.7\n84.6\n4-shot\nPromptAD\nCVPR2024\n96.6\n96.5\n90.5\n89.1\n97.4\n86.2\nFeatureNorm is comparable and even superior\nInCTRL\nCVPR2024\n94.5\n/\n/\n87.7\n/\n/\nResAD\nNeurIPS2024\n94.2\n96.9\n/\n90.8\n97.5\n/\n(on VisA). This demonstrates that the essence of\nKAG-Prompt\nAAAI2025\n97.1\n96.7\n91.4\n93.3\n97.7\n87.6\nFeatureNorm (ours)\n96.2\n95.9\n91.3\n94.5\n98.1\n89.3\nFSAD still lies in the representation ability of\nfeatures. With better AD representation features,\nwe can achieve good FSAD results without the need to design elaborate methods (e.g., the KernelAware Hierarchical Graph in KAG-Prompt). Compared to the most relevant work, ResAD, our simple\nFeatureNorm can outperform it, especially on the VisA dataset. Moreover, a major advantage of our\nwork is that we can provide better representation features for downstream AD methods, while ResAD\ncannot empower other AD models.\n∗\n\n∗\n\n∗\n\n#,‡\n\n#\n\n‡\n\n#,‡\n\n‡\n\n∗\n\n∗\n\n∗\n\n#,‡\n\n#\n\n‡\n\n#,‡\n\n‡\n\n5\n\nConclusion\n\nIn this paper, we explore the problem of anomaly presentation pretraining, which is important for the\nanomaly detection field but has been inadvertently overlooked. We propose a novel AD representation\nlearning framework, which learns pretrained AD representations based on residual features and\nconsists of angle- and norm-oriented contrastive losses to fully optimize feature discrepancies.\nExperiments comprehensively demonstrate that our proprietary pretrained features consistently\nsurpass the original ImageNet-pretrained features. As we all know, pretraining on ImageNet has\nprompted the prosperity of computer vision. Analogously, in the AD field, a valuable question\nis what kind of representations can serve as the fundamental (general) representation for anomaly\ndetection. Furthermore, more attention could be paid to anomaly representation pretraining in future\nwork, rather than constantly focusing on designing more sophisticated AD models dependent on\nImageNet-pretrained networks. The limitations of our method are discussed in Appendix B.5.\n10\n\n\fAcknowledgments\nThis work was supported in part by the National Natural Science Fund of China (62371295) and the\nScience and Technology Commission of Shanghai Municipality (22DZ2229005).\n\nReferences\n[1] Liron Bergman, Niv Cohen, and Yedid Hoshen. Deep nearest neighbor anomaly detection.\narXiv preprint arXiv: 2002.10445, 2020.\n[2] Paul Bergmann, Michael Fauser, David Sattlegger, and Carsten Steger. Mvtec ad - a comprehensive real-world dataset for unsupervised anomaly detection. In CVPR, 2019.\n[3] Paul Bergmann, Michael Fauser, David Sattlegger, and Carsten Steger. Uninformed students:\nStudent-teacher anomaly detection with discriminative latent embeddings. In CVPR, 2020.\n[4] Paul Bergmann, Xin Jin, David Sattlegger, and Carsten Steger. The mvtec 3d-ad dataset for\nunsupervised 3d anomaly detection and localization. arXiv preprint arXiv:2112.09045, 2021.\n[5] Paul Bergmann, Sindy Lowe, Michael Fauser, David Sattlegger, and Carsten Steger. Improving unsupervised defect segmentation by applying structural similarity to autoencoders. In\nInternational Conference on Computational Vision Technologies and Applications, 2019.\n[6] Qiyu Chen, Huiyuan Luo, Chengkan LV, and Zhengtao Zhang. A unified anomaly synthesis\nstrategy with gradint ascent for industrial anomaly detection and localization. In ECCV, 2024.\n[7] Ting Chen, Simon Kornblith, Mohammad Norouzi, and Geoffrey Hinton. A simple framework\nfor contrastive learning of visual representations. In International Conference on Machine\nLearning, 2020.\n[8] Thomas Defard, Aleksandr Setkov, Angelique Loesch, and Romaric Audigier. Padim: a patch\ndistribution modeling framework for anomaly detection and localization. In 1st International\nWorkshop on Industrial Machine Learning, 2021.\n[9] Hanqiu Deng and Xingyu Li. Anomaly detection via reverse distillation from one-class embedding. In CVPR, 2022.\n[10] Matic Fučka, Vitjan Zavrtanik, and Danijel Skočaj. Transfusion - a transparency-based diffusion\nmodel for anomaly detection. In ECCV, 2024.\n[11] Rohit Girdhar, Alaaeldin El-Nouby, Zhuang Liu, Mannat Singh, Kalyan Vasudev Alwala,\nArmand Joulin, and Ishan Misra. Imagebind: One embedding space to bind them all. In CVPR,\n2023.\n[12] Denis Gudovskiy, Shun Ishizaka, and Kazuki Kozuka. Cflow-ad: Real-time unsupervised\nanomaly detection with localization via conditional normalizing flows. In IEEE Winter Conference on Application of Computer Vision, 2022.\n[13] Jianfei Hu Hanxi Li, Bo Li, Hao Chen, Yongbin Zheng, and Chunhua Shen. Target before\nshooting: Accurate anomaly detection and localization under one millisecond via cascade patch\nretrieval. arXiv preprint arXiv: 2308.06748, 2023.\n[14] Haoyang He, Jiangning Zhang, Hongxu Chen, Xuhai Chen, Zhishan Li, Xu Chen, Yabiao Wang,\nChengjie Wang, and Lei Xie. Diad: A diffusion-based framework for multi-class anomaly\ndetection. In AAAI, 2024.\n[15] Kaiming He, Haoqi Fan, Yuxin Wu, Saining Xie, and Ross Girshick. Momentum contrast for\nunsupervised visual representation learning. In CVPR, 2020.\n[16] Liren He, Zhengkai Jiang, Jinlong Peng, Wenbing Zhu, Liang Liu, Qiangang Du, Xiaohib Hu,\nMingmin Chi, Yabiao Wang, and Chengjie Wang. Learning unified reference representation for\nunsupervised multi-class anomaly detection. In ECCV, 2024.\n11\n\n\f[17] Jongheon Jeong, Yang Zou, Taewan Kim, Dongqing Zhang, Avinash Ravichandran, and Onkar\nDabeer. Winclip: Zero-/few-shot anomaly classification and segmentation. In CVPR, 2023.\n[18] Stepan Jezek, Martin Jonak, Radim Burget, Pavel Dvorak, and Milos Skotak. Deep learningbased defect detection of metal parts: evaluating current methods in complex conditions. In\n13th International Congress on Ultra Modern Telecommunications and Control Systems and\nWorkshops, 2021.\n[19] Xi Jiang, Jianlin Liu JinbaoWang, Qian Nie, Kai Wu, Yong Liu, Chengjie Wang, and Feng\nZheng. Softpatch: Unsupervised anomaly detection with noisy data. In NeurIPS, 2022.\n[20] Daehyun Kim, Sungyong Baik, and Tae Hyun Kim. Sanflow: Semantic-aware normalizing flow\nfor anomaly detection and localization. In NeurIPS, 2023.\n[21] Diederik P. Kingma and Prafulla Dhariwal. Glow: Generative flow with invertible 1x1 convolutions. In Conference and Workshop on Neural Information Processing Systems, 2019.\n[22] James Kirkpatrick, Razvan Pascanu, Neil C. Rabinowitz, Joel Veness, Guillaume Desjardins, Andrei A. Rusu, Kieran Milan, John Quan, Tiago Ramalho, Agnieszka Grabska-Barwinska, Demis\nHassabis, Claudia Clopath, Dharshan Kumaran, and Raia Hadsell. Overcoming catastrophic\nforgetting in neural networks. Proceedings of the national academy of sciences, 2017.\n[23] Zhikang Liu, Yiming Zhou, Yuansheng Xu, and Zilei Wang. Simplenet: A simple network for\nimage anomaly detection and localization. In CVPR, 2023.\n[24] Philipp Liznerski, Lukas Ruff, Robert A. Vandermeulen, Billy Joe Franks, Marius Kloft, and\nKlaus-Robert Muller. Explainable deep one-class classification. In International Conference on\nLearning Representations, 2021.\n[25] Pankaj Mishra, Riccardo Verk, Daniele Fornasier, Claudio Piciarelli, and Gian Luca Foresti.\nVt-adl: A vision transformer network for image anomaly detection and localization. arXiv\npreprint arXiv:2104.10036, 2021.\n[26] Maxime Oquab, Timothee Darcet, Theo Moutakanni, Huy V. Vo, Marc Szafraniec, Vasil\nKhalidov, Pierre Fernandez, Daniel Haziza, Francisco Massa, Alaaeldin El-Nouby, Mido\nAssran, Nicolas Ballas, Wojciech Galuba, Russell Howes, Po-Yao Huang, Shang-Wen Li, Ishan\nMisra, Michael Rabbat, Vasu Sharma, Gabriel Synnaeve, Hu Xu, Herve Jegou, Julien Mairal,\nPatrick Labatut, Armand Joulin, and Piotr Bojanowski. Dinov2: Learning robust visual features\nwithout supervision. In Trans. Mach. Learn. Res., 2024.\n[27] Pramuditha Perera and Vishal M. Patel. Learning deep features for one-class classification.\nIEEE Transactions on Image Processing, 2019.\n[28] Diederik P.Kingma and Jimmy Lei Ba. Adam: A method for stochastic optimization. In ICLR,\n2015.\n[29] Alec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh, Gabriel Goh, Sandhini Agarwal, Girish Sastry, Amanda Askell, Pamela Mishkin, Jack Clark, Gretchen Krueger, and Ilya\nSutskever. Learning transferable visual models from natural language supervision. In ICML,\n2021.\n[30] Tal Reiss, Niv Cohen, Liron Bergman, and Yedid Hoshen. Panda: Adapting pretrained features\nfor anomaly detection and segmentation. In CVPR, 2021.\n[31] Tal Reiss and Yedid Hoshen. Mean-shifted contrastive loss for anomaly detection. arXiv\npreprint arXiv:2106.03844, 2021.\n[32] Oliver Rippel, Arnav Chavan, Chucai Lei, and Dorit Merhof. Transfer learning gaussian\nanomaly detection by fine-tuning representations. In Proceedings of the 2nd International\nConference on Image Processing and Vision Engineering, 2022.\n[33] Karsten Roth, Latha Pemula, Joaquin Zepeda, Bernhard Scholkopf, Thomas Brox, and Peter\nGehler. Towards total recall in industrial anomaly detection. In CVPR, 2022.\n12\n\n\f[34] Marco Rudolph, Bastian Wandt, and Bodo Rosenhahn. Same same but differnet: Semisupervised defect detection with normalizing flows. In IEEE Winter Conference on Application\nof Computer Vision, 2021.\n[35] Marco Rudolph, Tom Wehrbein, Bodo Rosenhahn, and Bastian Wandt. Fully convolutional\ncross-scale-flows for image-based defect detection. In IEEE Winter Conference on Application\nof Computer Vision, 2022.\n[36] Lukas Ruff, Robert A. Vandermeulen, Nico Gornitz, Lucas Deecke, and Shoaib A. Siddiqui.\nDeep one-class classification. In International Conference on Machine Learning, 2021.\n[37] Mohammadreza Salehi, Niousha Sadjadi, Soroos Hossein Rohban, and Hamid R.Rabiee. Multiresolution knowledge distillation for anomaly detection. In CVPR, 2021.\n[38] Fenfang Tao, Guo-Sen Xie, Fang Zhao, and Xiangbo Shu. Kernal-aware graph prompt learning\nfor few-shot anomaly detection. In AAAI, 2025.\n[39] Xina Tao, Xinyi Gong, Xin Zhang, Shaohua Yan, and Chandranath Adak. Deep learning\nfor unsupervised anomaly localization in industrial images: A survey. IEEE Transactions on\nInstrumentation and Measurement, 2022.\n[40] David M.J. Tax and Robert P.W. Duin. Support vector data description. In Machine Learning,\npages 45–66, 2004.\n[41] Tran Dinh Tien, Anh Tuan Nguyen, Nguyen Hoang Tran, Ta Duc Huy, Soan T.M Duong, Chanh\nD. Tr. Nguyen, and Steven Q.H. Truong. Revisting reverse distillation for anomaly detection.\nIn CVPR, 2023.\n[42] Aaron van den Oord, Yazhe Li, and Oriol Vinyals. Representation learning with contrastive\npredictive coding. arXiv preprint arXiv:1807.03748, 2018.\n[43] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez,\nŁukasz Kaiser, and Illia Polosukhin. Attention is all you need. In NeurIPS, 2017.\n[44] Chengjie Wang, Wenbing Zhu, Bin-Bin Gao, Zhenye Gan, Jiangning Zhang, Zhihao Gu,\nShuguang Qian, Mingang Chen, and Lizhuang Ma. Real-iad: A real-world multi-view dataset\nfor benchmarking versatile industrial anomaly detection. In CVPR, 2024.\n[45] Jie Yang, Yong Shi, and Zhiquan Qi. Dfr: Deep feature reconstruction for unsupervised anomaly\nsegmentation. arXiv preprint arXiv: 2012.07122, 2020.\n[46] Xincheng Yao, Zixin Chen, Guangtao Zhai, and Chongyang Zhang. Resad: A simple framework\nfor class generalizable anomaly detection. In neurIPS, 2024.\n[47] Xincheng Yao, Ruoqi Li, Jing Zhang, Jun Sun, and Chongyang Zhang. Explicit boundary\nguided semi-push-pull contrastive learning for supervised anomaly detection. In CVPR, 2023.\n[48] Xincheng Yao, Chongyang Zhang, Ruoqi Li, Jun Sun, and Zhenyu Liu. One-for-all: Proposal\nmasked cross-class anomaly detection. In AAAI, 2023.\n[49] Jihun Yi and Sungroh Yoon. Patch svdd: Patch-level svdd for anomaly detection and segmentation. In Asian Conference on Computer Vision, 2021.\n[50] Zhiyuan You, Lei Cui, Yujun Shen, Kai Yang, Xin Lu, Yu Zheng, and Xinyi Le. A unified\nmodel for multi-class anomaly detection. arXiv preprint arXiv:2206.03687, 2022.\n[51] Vitjan Zavrtanik, Matej Kristan, and Danijel Skocaj. Draem: A discriminatively trained\nreconstruction embedding for surface anomaly detection. In ICCV, 2021.\n[52] Xinyi Zhang, Naiqi Li, Jiawei Li, Tao Dai, Yong Jiang, and Shutao Xia. Unsupervised surface\nanomaly detection with diffusion probabilities model. In ICCV, 2023.\n[53] Xuan Zhang, Shiyu Li, Xi Li, Ping Huang, Jiulong Shan, and Ting Chen. Destseg: Segmentation\nguided denoising student-teacher for anomaly detection. In CVPR, 2023.\n13\n\n\f[54] Ye Zheng, Xiang Wang, Rui Deng, Tianpeng Bao, Rui Zhao, and Liwei Wu. Focus your\ndistribution: Coarse-to-fine non-contrastive learning for anomaly detection and localization. In\nICME, 2022.\n[55] JiaWen Zhu and Guansong Pang. Toward generalist anomaly detection via in-context residual\nlearning with few-shot sample prompts. In CVPR, 2024.\n[56] Yang Zou, Jongheon Jeong, Latha Pemula, Dongqing Zhang, and Onkar Dabeer. Spot-thedifference self-supervised pre-training for anomaly detection and segmentation. In ECCV,\n2022.\n\n14\n\n\fAppendix\nA\n\nSignificance of Anomaly Representation Pretraining\n\nStrictly speaking, from the implementation perspective, our method is not true “pretraining” as it\ndidn’t achieve pretraining the whole backbone network. However, the usage of “pretraining” has\ntwo reasons: 1) We are indeed following the basic paradigm of pretraining: learning on a large-scale\ndataset, and the learned features can be transferred to downstream datasets and models. 2) More\nimportantly, we want to emphasize that in the current development stage of anomaly detection,\nfundamental representations specifically learned for anomaly detection are of great significance.\nCurrent mainstream AD models mostly use pretrained networks to extract features. However,\nregardless of supervised or self-supervised pretraining on natural images, the pretraining process\ndoes not match the goal of anomaly detection. From the perspective of the development prospects of\nAD, it’s necessary for AD tasks to have specialized pretrained features instead of continuously using\nbasic pretrained features. Our work is only an early exploration, and we hope to inspire more future\nworks to focus on anomaly representation pretraining.\n\nB\n\nMore Discussions\n\nB.1\n\nDiscussions with Fine-tuning Baselines\n\nWe further provide a discussion with the previous finetune-based baseline methods, such as FYD [54],\nMSC [31], and PANDA [30]. These methods aim to finetune pretrained features to adapt to the target\ndistribution in specific AD datasets. As the FYD paper does not provide open-source code, we can\nonly compare with the results provided in the paper. In FYD, anomaly detection is achieved based on\nPaDiM. The paper provides the results on MVTecAD, which are 97.7/98.2 (image-level/pixel-level\nAUROCs). Based on PaDiM, the results of our method are 98.1/98.5. In PANDA and mean-shift\ncontrastive loss (MSC), feature adaptation is based on global features, so only image-level anomaly\ndetection is performed. The two papers provide image-level AUROC on MVTecAD, with values\nof 86.5 and 87.2. For a more reasonable comparison, we utilized the open-source code of MSC\nand trained an adapted network (based on WideResNet50) on MVTecAD. Then, we utilized PaDiM\nfor AD modeling, and the obtained results are 96.8/97.0. Thus, compared with PANDA, MSC, and\nFYD, our method has advantages in providing better features for AD models. Moreover, adaptive\nfeature fine-tuning requires specialized fine-tuning on each dataset. By comparison, a more important\nadvantage of anomaly representation pretraining is that pretrained features can be used on multiple\ndownstream AD datasets without the need for fine-tuning on each dataset.\nIt is crucial to point out that FYD does not utilize large-scale AD datasets for pretraining when\nimproving feature representations. Thus, what impact does the dataset scale have on feature finetuning? To answer this, we further perform pretraining on the MVTecAD dataset. The results are in\nTab.6.\nTable 6: Experimental analysis of the impact of pretraining dataset scale.\nDatasets\n\nPaDiM (RealIAD)\n\nPaDiM ( MVTecAD)\n\nPatchCore (RealIAD)\n\nPatchCore (MVTecAD)\n\nMVTecAD\nVisA\nBTAD\nMVTec3D\nMPDD\n\n98.9/92.1\n95.6/88.6\n95.9/76.8\n84.4/92.0\n94.4/95.1\n\n97.7/92.1\n93.0/85.6\n95.6/76.6\n82.8/91.2\n92.9/93.5\n\n98.9/88.8\n94.8/86.3\n95.6/67.3\n82.6/87.0\n94.8/94.2\n\n98.8/88.0\n93.4/86.0\n94.7/66.5\n80.6/87.3\n93.1/93.4\n\nImpact of Pretraining Dataset Scale. It can be seen that with pretraining on MVTecAD, the results\nare overall lower than the results obtained based on RealIAD pretraining. Thus, we think that the\nscale of the dataset will have an impact, a larger scale is more advantageous for pretraining (better\ntransferability of the learned features). This also reflects that the AD field still needs larger and\nhigher-quality datasets in the future to better support anomaly representation pretraining.\nHowever, in FYD, the transferability of the fine-tuned features is not discussed. In FYD, after\nfine-tuning on MVTecAD, the fine-tuned model is effective on MVTecAD, but it has not been verified\nwhether it is still effective on other datasets. We think that FYD requires specialized fine-tuning\non each dataset. The reason is that the fine-tuning process in FYD is mainly to accomplish spatial\n15\n\n\falignment (beneficial to the PaDiM method) on feature maps. As the spatial distributions of objects\nin different datasets are different, the learned affine transformation parameters in one dataset should\nbe hard to apply to other datasets. Therefore, even if we employ FYD to fine-tune on RealIAD,\nthe adapted network cannot be directly applied to other downstream datasets. Nevertheless, in our\npaper, the results in Tab.1 have comprehensively verified that the pretrained features have good\ntransferability in downstream AD datasets.\nB.2\n\nDiscussions on Data Leakage\n\nA concern about our work is whether there may be anomaly data leakage between the pretraining\ndataset and the test datasets. We think that the data leakage issue does not need to be concerned.\nBecause the product categories in RealIAD are completely different from those in the test AD datasets,\nand the anomaly types are also quite different. Even if there are some similar types of anomalies\n(e.g., broken), the visual appearance displayed on different products will also be different. For data\nleakage, it’s hard to calculate a numerical indicator. Due to different products, the similarities between\npretraining images and test images are all low, making it hard to distinguish what constitutes anomaly\ndata leakage. In Tab.6, we report results of both pretraining and testing on the MVTecAD dataset.\nThis is a serious data leakage, but compared to RealIAD pretraining, it doesn’t bring significant\nperformance improvement. This indicates that data leakage is not a critical issue for the performance\ngains in our work.\nB.3\n\nDiscussions with SPD\n\nWe further provide a discussion with a previous pretraining-related method, SPD [56]. In the paper\nspot-the-difference (SPD), the authors propose a data augmentation strategy called SmoothBlend\nto create slight local differences (or called pseudo-anomalies). Then, the authors create pseudoanomalies on natural images from ImageNet to use as negative samples in contrastive learning. The\nmodel is pretrained on ImageNet, while our model is pretrained on a real AD dataset, RealIAD. (1)\nCompared to pseudo-anomalies, the negative samples used in our method are more realistic and more\nin line with the abnormal characteristics in real-world scenarios. (2) In SPD, similar to classical\nSSL methods (SimCLR, MoCo), contrastive loss is constructed based on global features, while we\nconstruct contrastive loss based on more fine-grained local features. Although SPD mentioned that\nit can promote local sensitivity compared to SimCLR, MoCo, etc., it still may lead to the loss of\ninformation about local pseudo-anomalies in the global features, as the local augmentation is slight.\nFor fine-grained task like anomaly detection, contrastive learning based on fine-grained local features\nshould be more suitable. (3) SPD was evaluated only on the ResNet-50, PaDiM, and VisA and\nMVTecAD datasets, while we evaluate our method on more backbones, AD models, and AD datasets.\nB.4\n\nMore Discussions with ResAD\n\nWe think that we should further discuss some similarities and differences between our work and\nResAD [46]. Compared to ResAD, we mainly employ the wonderful residual features proposed\nin ResAD as our pretrained AD representations. Because we expect that pretrained features can\nserve as general features in anomaly detection, namely, it’s best for pretrained representations to be\ndomain-invariant. As the authors explained in [46], the residual features can be regarded as classgeneralizable representations, which satisfy our expectations just right. The results in Tab.2(a) also\ndemonstrate that residual features are better pretrained AD representations compared to the vanilla\nfeatures extracted by the backbone network. Our studies also further confirm the authors’ opinions\nin [46] that residual features have the potential to be general representations in anomaly detection.\nHowever, our work and ResAD are clearly two different works, with differences in motivations,\nconcerned problems, and implementation methods.\n(1) Different Motivations and Concerned Problems. ResAD explores the problem of classgeneralizable anomaly detection. The authors mainly aim to learn a generalizable AD model that can\nbe directly applied to new classes to accomplish anomaly detection. By comparison, our work focuses\non a very valuable but inadvertently overlooked problem: anomaly representation pretraining. We\naim to learn better and proprietary representation features for AD tasks through contrastive learning\npretraining on large-scale AD datasets.\n16\n\n\f(2) Class-generalizable Anomaly Detection vs. Anomaly Representation Pretraining. Although\nclass-generalization anomaly detection can also be seen as pretraining an AD model on a dataset and\nthen applying it to new datasets. However, it’s still significantly different from anomaly representation\npretraining, as anomaly representation pretraining aims to provide better AD representation features\nfor downstream AD methods, while class-generalizable anomaly detection (ResAD, InCTRL [55])\ncannot empower other AD models. This is why in the experiments, we didn’t perform reverse setting\n(train on the combination of MVTecAD, VisA and other datasets and eval on RealIAD). We need to\nvalidate the effectiveness of our pretrained features in existing AD methods, rather than verifying the\ncross-class generalization ability of AD models. The models in Tab.1 are also first trained on normal\nsamples with our pretrained features, and then evaluated.\n(3) Different Implementation Methods. Our work doesn’t construct a model that can be directly\nused for anomaly detection, while providing pretrained representation features for AD tasks. Our\npretraining framework is based on contrastive learning. To fully optimize discrepancies between\nnormal and abnormal features, we propose angle- and norm-oriented contrastive losses from the\nfeature similarity perspective. ResAD constructs a class-generalizable AD model that accomplishes\nanomaly detection based on normalizing flow model [21] to learn residual feature distribution. In\naddition, ResAD uses fixed normal samples as reference to generate residual features, without\nconsidering the semantic misalignment issue. We realize this issue and provide an improvement (the\nsemantic-aligned reference matching module, Appendix C) for generating semantic-aligned residual\nfeatures.\n(4) As for performance, we compare the FSAD performance with ResAD. As shown in Tab.5, our\nsimple FeatureNorm is better than ResAD, especially on the VisA dataset. Moreover, compared\nto the more sophisticated normalizing flow modeling in ResAD, calculating feature norms in our\nmethod is quite simple. This also demonstrates the value of our pretrained features.\n\nB.5\n\nLimitations\n\nIn this work, unlike conventional AD research works, we explore a very valuable but inadvertently\noverlooked problem: anomaly representation pretraining. We propose a novel AD representation\nlearning framework to learn proprietary pretrained features for AD tasks. Even if incorporating our\npretrained features into embedding-based AD methods can manifest good performance improvement\non five AD datasets and five backbones (Tab.1), there are still some limitations of our work.\nOne limitation of our work is that we fix the backbone network and only optimize the Feature\nProjector during training. However, we think that for an ideal feature extraction network in AD tasks,\nthe backbone part should be specially designed based on the characteristics of anomaly detection\nand effectively learned during pretraining. For example, when encoding one image, the backbone\nnetwork can simultaneously consider multiple normal reference samples to increase the normal\ncontext patterns. Then, the contrast between normal and abnormal can be implicitly embodied in\nthe network encoding process. Thus, the encoded normal and abnormal features would be more\ndiscriminative.\nAnother limitation is that our pretrained features can only be incorporated into embedding-based AD\nmethods. Other AD methods that are not based on pretrained feature extractors (e.g., diffusion-based)\ncannot benefit from our method. Therefore, future work should also focus on exploring pretraining\nframeworks for more AD methods.\n\nB.6\n\nComputational Cost\n\nIn this work, we accomplish anomaly detection based on some embedding-based AD methods.\nThe computational cost of a complete AD model is determined by both the feature extractor and\nthe subsequent AD method. Compared to using ImageNet-pretrained features, our method mainly\nintroduces extra cost in the Feature Projector. For different backbones, the computational costs of the\nFeature Projector are different. With the image size fixed as 224 × 224, we calculate the number of\nparameters and computation FLOPs in the Feature Projector. The results are shown in Tab.7.\n17\n\n\fTable 7: Computational cost of the Feature Projector with different backbone networks.\nparameters\nFLOPs\n\nB.7\n\nDINOv2-Base\n\nDINOv2-Large\n\nCLIP-Base\n\nCLIP-Large\n\nImageBind\n\n21.3M\n137.7G\n\n37.8M\n309.2G\n\n21.3M\n137.7G\n\n37.8M\n309.2G\n\n59M\n483.2G\n\nSocial Impacts and Ethics\n\nAs a work for learning robust and discriminative pretrained representations for anomaly detection,\nthe proposed method does not suffer from particular ethical concerns or negative social impacts. All\ndatasets used are public. All qualitative visualizations are based on industrial product images, which\ndon’t infringe personal privacy.\n\nC\n\nSemantic-Aligned Reference Matching\n\nDiscussions on Reference-Set Sensitivity. Residual features are mainly relied on mutually eliminating class-related normal patterns in features through subtraction (please see the ResAD paper [46]\nfor more explanations), for being class-generalizable. However, if normal images have significant\nvariability, it may cause the few-shot reference samples to be not representative enough (lacking\nsome class-related normal patterns). This may lead to certain class-related normal patterns in the\ninput feature can’t be effectively eliminated. Then, the discriminability of residual features under\nfew-shot settings will be compromised.\nFor practical applications, this issue should be particularly focused and reasonably addressed. Of\ncourse, the simplest solution is to increase the number of reference samples. This is feasible, as in\npractical applications, the number of reference samples is usually not as strict as the 8-shot. However,\nin practical applications, we expect that the reference samples can fully represent their class, so it’s\nbest to have sufficient differences between the reference samples. Thus, the sample selection strategy\ncannot be random. A feasible method is to first cluster all available normal samples into different\nclusters based on a clustering algorithm (e.g., KMeans). Then, based on the number of reference\nsamples, we evenly distribute it to each cluster. When selecting from a cluster, we can prioritize\nselecting samples closer to the center. Another feasible strategy is to match spatially aligned samples\nas reference samples for each input sample. Below, we provide a corresponding approach.\nResidual Features with Semantic-Aligned Reference Matching. When constructing residual\nfeatures, it’s required to first match the nearest feature from the reference feature bank. To maintain\nthe efficiency of residual feature generation, the reference feature bank cannot be too large. Thus, in\n[46], the authors use fixed few-shot normal samples to construct the reference feature bank. Although\nefficiency is guaranteed, it may sacrifice the representation ability of residual features. In real-world\nscenarios, different normal samples of the same class may have semantic differences (e.g., variable\nobject components or shapes, misaligned objects). When the semantic differences among normal\nsamples are too large, it can cause fixed few-shot normal samples can’t cover all normal patterns,\nthereby the reference feature bank may not be representative enough. To address this, we can select\nproper semantic-aligned (i.e., the components, shape, and orientation of the object in two images are\nrelatively consistent) reference samples for each input image. In specific, we propose a lightweight\nsemantic-aligned reference matching method, which calculates statistical histograms (distances from\nlocal features to clustering centers) for the image and then measures the global distance between two\nimages by the KL divergence between histograms. Two aligned images usually have close spatial\nfeature distribution, so the histograms are similar, namely, smaller KL divergence. As histograms are\nlow-dimensional, the calculation of KL divergences has a very low cost. Thus, the matching module\nwill not introduce too much cost. Finally, we indicate that this module is not used during pretraining,\nwhile it can be used when we apply pretrained features to downstream AD datasets.\nSemantic-Aligned Reference Matching. We describe our semantic-aligned reference matching\nmethod that can retrieve semantic-aligned samples from the normal sample set for the input image I.\nGiven total N normal images, we extract first layer features with a pretrained lightweight network\n(e.g., ResNet-18), the corresponding features are denoted as {Fi ∈ RH1 ×W1 ×C1 |i = 1, 2, . . . , N }.\nThen, for each image, the feature map Fi is evenly divided into S × S grids as:\nH1\n\nW1\n\nFiu,v ∈ R S × S ×C1 , u, v = 1, 2, . . . , S\n18\n\n(8)\n\n\fFor each grid, we collect all raw patch features of different normal images together into the feature set\nP u,v = {Flatten(Fiu,v )k ∈ RC1 |k = 1, 2, . . . , N H1 W1 /S 2 }. The K-means clustering algorithm is\nperformed on P u,v to obtain Nc clustering centers C u,v = {ck ∈ RC1 |k = 1, 2, . . . , Nc }. For each\ngrid, we can obtain Nc clustering centers, and then the total number of centers is S 2 Nc .\nThe feature map Fi and clustering centers {C u,v ∈ RNc ×C1 |u, v = 1, 2, . . . , S} are further utilized\nto calculate the block-wise statistics for each normal image Ii . Specifically, in the (u, v)-th grid, we\nH1\nW1\ncalculate the cosine similarity between the grid feature map Fiu,v ∈ R S × S ×C1 and all centers\n2\n2\nC ∈ RS Nc ×C1 . Then we obtain H1 W1 /S 2 histograms denoted by Hiu,v = {hk ∈ RS Nc |k =\n2\n1, 2, . . . , H1 W1 /S }, where hk denotes the cosine distance histogram of k-th feature in the grid with\nrespect to the codebook C. The histograms are then normalized so that ||hk ||1 = 1, ∀k. Then, for\nthe input image I and the i-th normal image Ii , we can calculate the KL divergence between their\nhistograms to measure the spatial alignment degree between them. Specifically, the calculation of KL\ndivergence is based on grid, we calculate the block-wise KL divergence Diu,v = KL(Hiu,v , H u,v )\nfor each block (u, v), where H u,v means the histograms in (u, v)-th grid of the input image. As in\n2\none grid, there are H1 W1 /S 2 histograms, the shape of Diu,v should be RH1 W1 /S . If the two grids\nare semantically similar, the maximum KL divergence needs to be small enough. Therefore, we only\nselect the maximum KL divergence du,v\nfrom Diu,v as semantic alignment degree between two grids,\ni\nu,v\nu,v\ndi = max(Di ). The global semantic alignment degree between I and Ii is estimated as:\nS\n\nDialign ≜\n\nS\n\n1 X X u,v\nd\nS 2 u=1 v=1 i\n\n(9)\n\nBased on the global semantic alignment degree, we can sort the global distances between the input\nimage and N normal images and then retrieve the top-K neighbor normal images (we denote the set\nof indices as ι) as few-shot normal reference images Nref = {Iι1 , Iι1 , . . . , IιK }. In implementation,\nthe hyperparamters S, Nc , and K are set as 5, 5, and 8, respectively.\nFurther Discussion. Employing the semantic-aligned reference matching approach is to provide\nproper semantic-aligned reference samples for each input image. Generally speaking, such reference\nsamples should be more reference-informative, especially when the test images are highly non-aligned.\nMoreover, in practical usage, when inputting a test image, the semantic-aligned reference matching\napproach will not introduce too much extra cost for the inference process. We can employ it as\na preprocessing step by calculating histograms for all collected normal samples and storing these\nhistograms. Then, the input image only needs to calculate its own histograms and calculate the\nblock-wise KL divergences with the stored histograms, and the calculation of KL divergences has a\nvery low cost. When using ResNet-18 as the lightweight network, the cost of calculating the global\nsemantic alignment degree between I and Ii is only about 0.1 GFLOPs.\n\nD\n\nImplementation Details\n\nLike most pretraining works, we employ multiple backbones with different architectures and parameter scales for anomaly representation pretraining. Specifically, we select DINOv2-B [26], DINOv2-L\n[26], CLIP-B [29], CLIP-L [29], and ImageBind [11] as the backbone network. Due to different network depths, the intermediate layers to output features are different among these models. DINOv2-B\nand CLIP-B have a total of 12 layers, and we use the [3, 6, 9, 12] layers to output features. Network\nlayers in DINOv2-L and CLIP-L are 24, and features from the [6, 12, 18, 24] layers are used for\ntraining. For ImageBind, the outputs from the [8, 16, 24, 32] layers are used for training.\nImplementation Details About the Results in Tab.1. In Tab.1, to guarantee the rationality of result\ncomparison, with the five backbones, we reproduce these methods based on their official open-source\ncode. For each method, we use the default hyperparameters and don’t perform any hyperparameter\ntuning. When applying our pretrained features in these methods, we make sure that we only replace\nthe original features without any additional modifications.\n\nE\n\nHyperparameter Sensitivity\n\nIn this section, we conduct more ablation experiments on the main hyperparameters in our method to\nillustrate their sensitivity. Following the main text, in hyperparameter ablation studies, we also utilize\n19\n\n\fImageBind as the backbone network and produce results with PaDiM, PatchCore, and FeatureNorm\nas the baseline AD methods.\nTemperature Hyperparamter τ . In Tab.8, we ablate the temperature hyperparameter τ in the\nangle-oriented contrastive loss (see Eq.(2)). The results show that larger τ (i.e., &gt; 0.3) will lead to\ndegraded results. When τ is set to 0.3, the results produced by FeatureNorm are the best, but the\nPRO result under PatchCore is poor. When τ is set to 0.1, the results produced by Patchcore are the\nbest, but the results under FeatureNorm are poor. Therefore, by overall consideration, setting the\ntemperature hyperparameter τ to 0.15 is the most suitable choice.\nTable 8: Ablation studies about the temperature hyperparameter τ in the angle-oriented contrastive\nloss (see Eq.(2)). ·/· means image-level AUROC and PRO.\nτ\nMethod\nPaDiM\nPatchCore\nFeatureNorm\n\n0.1\n\n0.15\n\n0.2\n\n0.25\n\n0.3\n\n0.5\n\n95.4/87.8\n94.4/87.5\n93.3/87.7\n\n95.5/88.2\n94.6/87.0\n93.9/88.1\n\n95.4/87.9\n94.3/87.4\n93.9/87.9\n\n95.3/87.8\n94.5/86.5\n94.1/87.9\n\n95.1/87.5\n94.5/86.5\n94.1/88.1\n\n94.9/87.3\n94.6/85.5\n93.8/87.5\n\nMargin Hyperparamter ∆r. In Tab.9, we ablate the margin hyperparameter ∆r in the norm-oriented\ncontrastive loss (see Eq.(5)). The results show that our method is not very sensitive to the margin\n∆r. We think the reason should be that in the norm-oriented contrastive loss, we only need to set a\ncertain margin to ensure that the norm of normal and abnormal features can be distinguished, rather\nthan having to set a large enough margin. When ∆r is set to 0.75, the results under three baseline\nmethods are overall better compared to other ∆r values. Therefore, we decide to set the margin\nhyperparameter ∆r to 0.75 in our method.\nTable 9: Ablation studies about the margin hyperparameter ∆r in the norm-oriented contrastive loss\n(see Eq.(5), r′ = r + ∆r).\n∆r\nMethod\nPaDiM\nPatchCore\nFeatureNorm\n\n0.1\n\n0.2\n\n0.3\n\n0.5\n\n0.75\n\n1.0\n\n95.5/88.2\n94.6/87.0\n93.9/88.1\n\n95.5/88.3\n94.6/87.2\n93.9/88.0\n\n95.5/88.1\n94.6/86.6\n93.9/88.0\n\n95.5/88.1\n94.6/87.4\n93.9/88.0\n\n95.5/88.1\n94.6/87.5\n94.0/88.2\n\n95.5/88.0\n94.3/87.2\n94.0/88.4\n\nLoss Weighting Coefficient λ. The results are shown in Tab.10. It can be found that with λ set to 1,\nthe best results can be achieved.\nTable 10: Ablation studies about the loss weight λ in the total loss (see Eq.(7)).\nλ\nMethod\nPaDiM\nPatchCore\nFeatureNorm\n\n0.5\n\n1\n\n1.5\n\n2\n\n3\n\n5\n\n95.4/88.0\n94.3/87.8\n93.5/88.0\n\n95.5/88.1\n94.6/87.5\n94.0/88.2\n\n95.5/88.0\n94.5/87.0\n93.9/88.1\n\n95.4/87.7\n94.6/87.3\n93.9/87.9\n\n95.3/87.5\n94.6/87.6\n93.9/88.1\n\n95.2/87.2\n94.5/87.2\n94.1/88.0\n\nNumber of Layers in the Feature Projector L. The results are shown in Tab.11. The results indicate\nthat more network layers don’t bring obvious performance improvement, instead, the PRO results\nunder PatchCore are lower than the counterpart (87.5) when L is 1. Considering that more network\nlayers require more computational cost, we only construct one attention layer in the Feature Projector.\nNumber of Learnable Reference Representations Nr . The results are shown in Tab.12. It can\nbe found that with Nr set to 2048, the PRO result under PatchCore is better than others, and the\nresults under PaDiM and FeatureNorm are also good. Thus, the number of learnable reference\nrepresentations is set to 2048 by default.\nNumber of Reference Samples during Training K. The results are shown in Tab.13. Compared to\na fixed number of reference samples, combining multiple reference sample numbers and randomly\nselecting (Rand (1, 4, 8)) each time can achieve significant performance improvement. To vary the\n20\n\n\fTable 11: Ablation studies about the number of attention layers in the Feature Projector.\nL\nMethod\nPaDiM\nPatchCore\nFeatureNorm\n\n1\n\n2\n\n3\n\n95.5/88.1\n94.6/87.5\n94.0/88.2\n\n95.7/88.2\n94.9/86.4\n94.0/88.1\n\n95.7/88.4\n95.0/86.7\n93.9/88.2\n\nTable 12: Ablation studies about the number of learnable reference representations in the Feature\nProjector.\nNr\nMethod\nPaDiM\nPatchCore\nFeatureNorm\n\n256\n\n512\n\n1024\n\n1536\n\n1792\n\n2048\n\n2560\n\n95.4/88.1\n94.8/87.3\n94.0/88.1\n\n95.6/88.3\n94.8/86.7\n94.2/88.3\n\n95.5/88.1\n94.6/87.5\n94.0/88.2\n\n95.6/88.3\n94.5/86.5\n93.8/88.0\n\n95.6/88.1\n94.6/87.4\n93.6/87.9\n\n95.5/88.0\n94.7/88.0\n93.8/88.1\n\n95.5/87.9\n94.6/87.3\n93.7/88.1\n\nnumber of reference samples during training, we think that it is beneficial for increasing residual\nfeature diversity.\nTable 13: Ablation studies about the number of reference samples used during training. Rand(1, 4, 8)\nmeans that we randomly select 1, 4, or 8 reference samples for each input sample.\n\nK\nMethod\nPaDiM\nPatchCore\nFeatureNorm\n\nF\n\n1\n\n2\n\n4\n\n8\n\nRand(1, 4, 8)\n\n95.5/88.0\n94.7/88.0\n93.8/88.1\n\n95.3/88.0\n94.4/87.5\n94.3/89.0\n\n95.3/88.1\n94.6/87.7\n94.5/89.3\n\n95.2/88.7\n94.3/87.5\n94.2/89.2\n\n95.5/88.8\n94.7/87.6\n94.5/89.3\n\nQualitative Results\n\nIn this section, we show some qualitative results. To avoid redundant qualitative figures, we select to\ngenerate anomaly score maps based on PatchCore as it is representative enough. PatchCore is based\non feature comparison without learnable parameters, and thus can intuitively reflect the quality of\npretrained features. In addition, we utilize CLIP-L as the backbone network. The qualitative results\nare shown in Fig.4. It can be seen that by employing our pretrained features, the PatchCore method\ncan generate better anomaly localization maps compared to using the original ImageNet-pretrained\nfeatures. “PatchCore w/o pretrained” may generate many false positives in normal regions (e.g., line\n1, right part of lines 4 and 5). By comparison, “PatchCore w/ pretrained” can effectively avoid false\npositives in normal regions and locate anomalies more accurately (e.g., left part of lines 3, 4, and 5).\nIn Fig.5, we show more feature t-SNE visualization results.\n\n21\n\n\fw/o pretrained\n\nw/ pretrained\n\nGround Truth\n\nw/o pretrained\n\nw/ pretrained\n\nMPDD\n\nMVTec3D\n\nVisA\n\nBTAD\n\nMVTecAD\n\nGround Truth\n\nFigure 4: Qualitative results. The anomaly score maps are generated by PatchCore with CLIP-L as\nthe backbone network. “w/o pretrained” and “w/ pretrained” refer to without and with our pretrained\nfeatures.\n\n（a) Candle\n\n（b) Chewinggum\n\n（c) Pcb1\n\n（d) Fryum\n\nFigure 5: Feature t-SNE visualization. For (a), (b), (c), and (d), the features are from the “candle”,\n“chewinggum”, “pcb1”, and “fryum” classes from the VisA dataset.\n\n22\n\n\f</code></pre></article>\n        \n</main>\n\n<script src=\"https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.js\"></script>\n<script src=\"https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/contrib/auto-render.min.js\"></script>\n<script>\n\nfunction initTheme() {\n  const saved = localStorage.getItem('kb-theme') || 'light';\n  document.documentElement.setAttribute('data-theme', saved);\n  updateThemeIcon(saved);\n}\nfunction toggleTheme() {\n  const cur = document.documentElement.getAttribute('data-theme') || 'light';\n  const next = cur === 'light' ? 'dark' : 'light';\n  document.documentElement.setAttribute('data-theme', next);\n  localStorage.setItem('kb-theme', next);\n  updateThemeIcon(next);\n}\nfunction updateThemeIcon(t) {\n  const btn = document.getElementById('theme-toggle-btn');\n  if (btn) btn.innerHTML = t === 'dark' ? '☀️' : '🌙';\n}\ndocument.addEventListener('DOMContentLoaded', initTheme);\n\nfunction setViewMode(m) {\n  const grid = document.getElementById('bento-grid-view');\n  const list = document.getElementById('list-table-view');\n  const bGrid = document.getElementById('view-grid-btn');\n  const bList = document.getElementById('view-list-btn');\n  if (m === 'list') {\n    if (grid) grid.style.display = 'none';\n    if (list) list.style.display = 'flex';\n    if (bGrid) bGrid.classList.remove('active');\n    if (bList) bList.classList.add('active');\n  } else {\n    if (grid) grid.style.display = 'grid';\n    if (list) list.style.display = 'none';\n    if (bGrid) bGrid.classList.add('active');\n    if (bList) bList.classList.remove('active');\n  }\n  localStorage.setItem('kb-view', m);\n}\ndocument.addEventListener('DOMContentLoaded', () => {\n  const s = localStorage.getItem('kb-view') || 'grid';\n  setViewMode(s);\n});\n\ndocument.addEventListener('DOMContentLoaded', () => {\n  document.querySelectorAll('pre').forEach(pre => {\n    const b = document.createElement('button');\n    b.className = 'copy-code-btn';\n    b.innerText = 'Copy';\n    b.onclick = () => {\n      const c = pre.querySelector('code') ? pre.querySelector('code').innerText : pre.innerText;\n      navigator.clipboard.writeText(c).then(() => {\n        b.innerText = 'Copied!';\n        setTimeout(() => { b.innerText = 'Copy'; }, 2000);\n      });\n    };\n    pre.appendChild(b);\n  });\n});\n\nwindow.addEventListener('keydown', (e) => {\n  if ((e.key === '/' || (e.metaKey && e.key === 'k')) && document.activeElement.tagName !== 'INPUT' && document.activeElement.tagName !== 'TEXTAREA') {\n    e.preventDefault();\n    const q = document.getElementById('global-search-input');\n    if (q) q.focus();\n  }\n});\n\n// Scrollspy for TOC\nwindow.addEventListener('scroll', () => {\n  const headers = document.querySelectorAll('.article-body h1, .article-body h2, .article-body h3');\n  const scrollPos = window.scrollY + 100;\n  headers.forEach(h => {\n    if (h.offsetTop <= scrollPos) {\n      const id = h.getAttribute('id');\n      if (id) {\n        document.querySelectorAll('.reading-sidebar a').forEach(a => {\n          a.classList.toggle('active', a.getAttribute('href') === '#' + id);\n        });\n      }\n    }\n  });\n});\n\ndocument.addEventListener(\"DOMContentLoaded\", function() {\n  if (window.renderMathInElement) {\n    renderMathInElement(document.body, {\n      delimiters: [\n        {left: '$$', right: '$$', display: true},\n        {left: '$', right: '$', display: false},\n      ],\n      throwOnError : false\n    });\n  }\n});\n</script>\n\n</body>\n</html>\n"