post-training-tools
Use after DeepDanbooru training to convert a saved Keras model to TensorFlow Lite or generate experimental Grad-CAM visualizations, with explicit artifact, dependency, and CPU-backend checks.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- post-training-tools
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Use after DeepDanbooru training to convert a saved Keras model to TensorFlow Lite or generate experimental Grad-CAM visualizations, with explicit artifact, dependency, and CPU-backend checks.
- disable-model-invocation
- true
02 资源文件 5
- 参考文档references/grad-cam-workflow.md4.1 KB
- 参考文档references/tflite-conversion.md4.9 KB
- 参考文档references/troubleshooting.md4.9 KB
- 脚本scripts/post_training_preflight.py5.2 KB
- 脚本scripts/tflite_conversion_smoke.py4.6 KB
03 SKILL.md 正文
Post-training tools
Use this sub-skill after a DeepDanbooru project has a loadable trained Keras model. It routes two post-training workflows:
- TFLite conversion: emit and inspect a non-empty
.tfliteartifact. - Grad-CAM: generate experimental, qualitative maps for tags selected by a prediction threshold.
Do not use this skill to train, repair a dataset, or judge model quality. Route ordinary predictions, thresholds, and tag alignment to Inference and evaluation. Route missing or stale models and retraining to Model training. For exact details, read the focused references before running a command.
Choose the route
| Goal | Entry point | Read first |
|---|---|---|
| Convert a saved Keras model | deepdanbooru conv2tflite |
TFLite conversion |
| Visualize input gradients | deepdanbooru grad-cam |
Grad-CAM workflow |
| Check paths without loading a model | post_training_preflight.py |
Troubleshooting |
| Verify conversion in isolation | tflite_conversion_smoke.py |
TFLite conversion |
Shared preflight
- Use the verified CPU TensorFlow backend first. GPU may be faster, but GPU support and speed are optional and unverified; a GPU option is not proof of GPU readiness.
- Keep the model/project and output paths explicit. For TFLite output,
--allow-existing-outputonly permits replacing an existing regular file; an existing directory at--save-pathis always rejected. Use a disposable output directory for Grad-CAM because files can be overwritten. - A project-based operation expects
project.json,tags.txt, and the model selected byproject.json. The project loader searchesmodel-{model}.keras, thenmodel-{model}.h5. - Check that the model has an NHWC image input and that the tag count matches
the output width before interpreting results. DeepDanbooru preprocessing
resizes with aspect-ratio preservation, edge-pads, and normalizes to
[0,1]. - Run the bundled preflight before an expensive conversion or visualization. It performs no downloads, network access, credential use, or model loading.
TFLite decision rules
The CLI requires --save-path, a project or direct model path, and at least one
optimization method. The exact flags are --project-path, --model-path,
--save-path, --optimize-default, --optimize-experimental-sparsity, and
--verbose; do not substitute similarly named flags. A direct --model-path
takes precedence over a project. The converter API and artifact checks are in
references/tflite-conversion.md.
After conversion, require test -s OUTPUT.tflite; then, when possible, load it
with a CPU TFLite interpreter and call allocate_tensors(). A non-empty file
alone does not prove compatible preprocessing, tag metadata, delegates, or
model quality. If sparsity or a layer is incompatible, retry without sparsity
before changing the original model.
Grad-CAM decision rules
grad-cam is explicitly experimental. It requires a project and target path,
accepts an optional output directory (default .), and uses --threshold
default 0.5; selection is inclusive (score >= threshold). It creates an
input image and per-selected-tag maps under a folder named for each input
basename. No selected tags means no result maps, not necessarily a failed
inference. Read the output contract and limitations in
references/grad-cam-workflow.md.
Failure handling and handoff
Use references/troubleshooting.md for missing
model/save/optimization inputs, incompatible conversion operators, absent
SciPy or Pillow imports, malformed projects, and threshold cases with no maps.
Do not import the old deepdanbooru.gradcam module as a generic helper: its
source-level experimental test runs at import time. After any artifact or map
run, compare predictions and prerequisites through
Inference and evaluation; if the model is
missing, use Model training.
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).