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
- 参考文档references/api-reference.md3.0 KB
- 参考文档references/troubleshooting.md2.4 KB
- 参考文档references/workflows.md2.4 KB
- 脚本scripts/cnn_smoke.py4.0 KB
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, orEfficientNetwrapper. - Build a
CustomModelaround a user-defined PyTorch module. - Understand CUDA-versus-CPU behavior for the CNN workflow.
Read this sub-skill first when the request mentions
CNNCustomModelMobilenetV3,ViT, orEfficientNet- torch or torchvision
- cosine similarity
min_similarity_threshold- pretrained weights or model configuration
- custom feature extractors
Workflow overview
- Decide whether the user wants the default pretrained model or a custom model.
- Make sure the model returns a feature tensor with shape
(batch, features). - Encode either a single image or a directory.
- Search duplicates from the encoding map or directly from the directory.
- 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
CustomModelwhen the user wants to plug in a different PyTorch model. - Use
encode_imagefor one file or numpy array. - Use
encode_imagesfor a directory. - Use
find_duplicateswhen the user needs the full duplicate map. - Use
find_duplicates_to_removewhen the user wants a heuristic removal list.
Helpful facts
CNNuses CUDA automatically when available and otherwise uses CPU.- The default backbone is
MobilenetV3. - Pretrained wrappers for
ViTandEfficientNetare also bundled. scores=Truereturns cosine similarities.min_similarity_thresholdis a float in[-1.0, 1.0].num_enc_workersonly parallelizes encoding on Linux.find_duplicatescan accept eitherimage_dirorencoding_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 reportcudaas 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
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).