AGENT SKILL

cnn

Find duplicate images with CNN encodings, pretrained backbones, or custom PyTorch models in imagededup.

License 许可
Apache-2.0
最近更新
2026-09-03
Stars
★ 351
Forks
27

01 前言 Front Matter

name
cnn
license
Apache 2.0
metadata
{ "disco-role": "operating" }
description
Find duplicate images with CNN encodings, pretrained backbones, or custom PyTorch models in imagededup.
disable-model-invocation
true

02 资源文件 4

03 SKILL.md 正文

cnn

Use this sub-skill when the user wants CNN-based encodings, cosine-similarity duplicate search, pretrained backbones, or custom PyTorch models.

Best-fit tasks

  • Encode one image or a directory with CNN.
  • Find duplicates from CNN feature vectors.
  • Use a pretrained MobilenetV3, ViT, or EfficientNet wrapper.
  • Build a CustomModel around a user-defined PyTorch module.
  • Understand CUDA-versus-CPU behavior for the CNN workflow.

Read this sub-skill first when the request mentions

  • CNN
  • CustomModel
  • MobilenetV3, ViT, or EfficientNet
  • torch or torchvision
  • cosine similarity
  • min_similarity_threshold
  • pretrained weights or model configuration
  • custom feature extractors

Workflow overview

  1. Decide whether the user wants the default pretrained model or a custom model.
  2. Make sure the model returns a feature tensor with shape (batch, features).
  3. Encode either a single image or a directory.
  4. Search duplicates from the encoding map or directly from the directory.
  5. If the user wants a removal list, convert the duplicate map to filenames to remove.

Common decisions

  • Use CNN() when the user wants the default MobileNetV3-based workflow.
  • Use CustomModel when the user wants to plug in a different PyTorch model.
  • Use encode_image for one file or numpy array.
  • Use encode_images for a directory.
  • Use find_duplicates when the user needs the full duplicate map.
  • Use find_duplicates_to_remove when the user wants a heuristic removal list.

Helpful facts

  • CNN uses CUDA automatically when available and otherwise uses CPU.
  • The default backbone is MobilenetV3.
  • Pretrained wrappers for ViT and EfficientNet are also bundled.
  • scores=True returns cosine similarities.
  • min_similarity_threshold is a float in [-1.0, 1.0].
  • num_enc_workers only parallelizes encoding on Linux.
  • find_duplicates can accept either image_dir or encoding_map.

Model contract

A custom model should:

  • be a PyTorch module or call-compatible object
  • accept the transform output
  • return a tensor whose last dimension is the feature dimension
  • be paired with a transform that matches the model's preprocessing needs

The bundled pretrained wrappers already provide matching transforms and names.

GPU and CPU notes

  • The CNN path is the only part of this repo that can benefit from CUDA.
  • CPU fallback is supported, so CUDA is optional rather than required.
  • If a GPU is available, CNN() should report cuda as its device.
  • First use of the default pretrained backbone may download weights if they are not cached.

Troubleshooting pointer

Read references/troubleshooting.md for model-config validation, threshold errors, worker-count warnings, CUDA selection, and weight-download issues.

Script helper

Run scripts/cnn_smoke.py to exercise a synthetic CNN workflow with either a lightweight custom model or the pretrained default path.

When to escalate elsewhere

  • If the task is only about hash methods, switch to the hashing sub-skill.
  • If the task is about scoring or plotting a retrieved duplicate map, switch to the evaluation sub-skill.

Good output expectations

A good CNN-oriented answer should usually include:

  • the model choice
  • whether the workflow is pretrained or custom
  • the expected feature shape or score behavior
  • the device behavior on the current host
  • any weight-download or worker-count caveat that applies

04 同仓库更多 Skills

VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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).

★ 351