embeddings-and-classification
Use Facenet embeddings for face comparison, SVM classifiers, embedding export, clustering, and contributed recognition examples.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- embeddings-and-classification
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Use Facenet embeddings for face comparison, SVM classifiers, embedding export, clustering, and contributed recognition examples.
- disable-model-invocation
- true
02 资源文件 8
- 参考文档references/cli-reference.md1.5 KB
- 参考文档references/contributed-workflows.md2.1 KB
- 参考文档references/troubleshooting.md1.7 KB
- 参考文档references/workflows.md3.3 KB
- 脚本scripts/build_classifier_command.py1.3 KB
- 脚本scripts/build_cluster_command.py1.3 KB
- 脚本scripts/build_compare_command.py860 B
- 脚本scripts/build_export_embeddings_command.py1.5 KB
03 SKILL.md 正文
Facenet Embeddings and Classification
Use this sub-skill when a task starts from a trained Facenet model and asks for embeddings, face comparison, classifier training/classification, batch export, clustering, or contributed high-level recognition examples.
When to read
- The user asks to compare faces or print a distance matrix.
- The user wants to train a classifier on identity folders or classify held-out images.
- The task needs exported
embeddings.npy,labels.npy, or label strings. - The user asks to cluster similar faces from a folder.
- The request mentions
compare,classifier,export_embeddings,batch_represent,cluster,predict, or real-time face recognition.
Prerequisites
- A Facenet TF1 environment that imports
facenet,align.detect_face, TensorFlow, NumPy, SciPy, scikit-learn, and OpenCV. - A model path accepted by Facenet: checkpoint directory or frozen
.pb. Read../model-export-and-checkpoints/SKILL.mdfor model formats. - Aligned class-folder data for classifier/export workflows. If input images are raw photos, read
../data-and-alignment/SKILL.mdfirst. - Enough images per identity for classifier splitting; defaults in
classifierrequire at least 20 images per class when--use_split_datasetis enabled.
Workflow map
- Compare images: use
scripts/build_compare_command.py, then readreferences/workflows.md. - Train or use an SVM classifier: use
scripts/build_classifier_command.py, then readreferences/workflows.md. - Export embeddings as NumPy arrays: use
scripts/build_export_embeddings_command.py, then readreferences/workflows.md. - Cluster faces: use
scripts/build_cluster_command.py, then readreferences/workflows.md. - Contributed examples: read
references/contributed-workflows.mdbefore using contributed webcam, prediction, or Chinese-whispers code.
Key runtime facts
- The embedding tensor is
embeddings:0; image input isinput:0; inference usesphase_train:0set toFalse. facenet.load_data(paths, False, False, image_size)loads already-aligned images and prewhitens by default.comparealigns each input image using MTCNN before model inference.classifiertrains a linearsklearn.svm.SVC(kernel='linear', probability=True)over embeddings and stores(model, class_names)in a pickle.- Contributed export and clustering scripts overlap with core workflows but have additional assumptions and older APIs.
Output contract
- Compare emits a human-readable distance matrix; save stdout with the model/preprocessing settings if it will be used as evidence.
- Classifier training writes a pickle containing the fitted SVM and class names; keep it paired with the exact identity-folder mapping used for training.
- Export writes embeddings and labels with matching row order; preserve the label-string array when handing outputs to another model.
- Clustering writes images under the requested output directory; use a temporary directory and record the threshold/minimum cluster size.
Validation
Use command builders with --help first. Run full model-backed commands only after model/data paths are available. For automation, treat model downloads, raw webcam capture, and large folder clustering as user-approved operations, not default smoke tests.
Troubleshooting
Read references/troubleshooting.md for classifier pickle mismatches, no detected face, empty embedding arrays, old SciPy image I/O, sklearn label issues, and contributed script hazards.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).