wenmin-wu/ds-skills/arcface-metric-learning

Claude Code and agent skill by wenmin-wu/ds-skills

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

ArcFace angular margin loss layer for learning discriminative embeddings — used in image retrieval, product matching, and face recognition

Install

npx vskill@latest install wenmin-wu/ds-skills/arcface-metric-learning

SKILL.md

The same SKILL.md was published earlier as majiayu000/claude-skill-registry-data/arcface-metric-learning.

ArcFace Metric Learning

Overview

ArcFace adds an angular margin penalty to the softmax loss, pushing embeddings of the same class closer and different classes further apart in hyperspherical space. Train a CNN with an ArcMarginProduct head, then discard the head and use the penultimate layer as your embedding extractor. Produces highly discriminative features for retrieval tasks.

Quick Start

python
import tensorflow as tf
import math
class ArcMarginProduct(tf.keras.layers.Layer):
def __init__(self, n_classes, s=30, m=0.50, **kwargs):
super().__init__(**kwargs)
self.n_classes = n_classes
self.s = s
self.cos_m = tf.math.cos(m)
self.sin_m = tf.math.sin(m)
self.th = tf.math.cos(math.pi - m)
self.mm = tf.math.sin(math.pi - m) * m
def build(self, input_shape):
self.W = self.add_weight(shape=(input_shape[0][-1], self.n_classes),
initializer='glorot_uniform', trainable=True)
def call(self, inputs):
X, y = inputs
cosine = tf.matmul(tf.math.l2_normalize(X, axis=1),
tf.math.l2_normalize(self.W, axis=0))
sine = tf.math.sqrt(1.0 - tf.math.pow(cosine, 2))
phi = cosine * self.cos_m - sine * self.sin_m
one_hot = tf.cast(tf.one_hot(y, depth=self.n_classes), dtype=phi.dtype)
output = (one_hot * phi) + ((1.0 - one_hot) * cosine)
return output * self.s
# Training
backbone = tf.keras.applications.EfficientNetB3(include_top=False, pooling='avg')
x = backbone.output
margin = ArcMarginProduct(n_classes=num_products, s=30, m=0.5)
output = margin([x, label_input])
model.fit(...)
# Inference: extract embeddings (discard ArcFace head)
embedder = tf.keras.Model(inputs=model.input[0], outputs=model.layers[-4].output)
embeddings = embedder.predict(test_data)

Key Decisions

  • s (scale): 30 is standard; higher values sharpen the distribution
  • m (margin): 0.5 radians; increase for harder separation, decrease if training diverges
  • L2 normalize: both features and weights must be normalized for angular margin to work
  • Discard head at inference: the classification head is only needed during training

References

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/wenmin-wu/ds-skills/arcface-metric-learning/badge)](https://verified-skill.com/skills/wenmin-wu/ds-skills/arcface-metric-learning)

Something wrong with this skill or its page? Tell us.