inference-and-deployment
Use DLTK's TensorFlow 1.x prediction, full-volume sliding-window assembly, crop averaging, metrics, and metadata-preserving medical-image deployment workflows.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- inference-and-deployment
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Use DLTK's TensorFlow 1.x prediction, full-volume sliding-window assembly, crop averaging, metrics, and metadata-preserving medical-image deployment workflows.
- disable-model-invocation
- true
02 资源文件 5
- 参考文档references/api-reference.md8.3 KB
- 参考文档references/deployment-workflows.md7.0 KB
- 参考文档references/troubleshooting.md6.1 KB
- 脚本scripts/sliding_window_plan.py7.0 KB
- 脚本scripts/sliding_window_smoke.py10.1 KB
03 SKILL.md 正文
DLTK inference and deployment
Use this route when the task is to run prediction with an exported DLTK model, assemble patch predictions into a full volume, average stochastic crops, calculate segmentation metrics, or write a NIfTI result. This is an operating guide for DLTK 0.2.1's TensorFlow 1.x graph-execution deployment path.
Compatibility gate
- Expect Python 3.7 and TensorFlow 1.15-era graph execution. The documented deployment path is
tensorflow.contrib.predictor.from_saved_model; do not claim that a modern TF2 installation provides this predictor or that these recipes are TF2-compatible. - Confirm the model input and fetched output static shapes before running a volume. The sliding-window utility expects rank-compatible static shapes and a channels-last tensor. The input sample normally has
[batch, spatial..., channels]; a full-volume application adds a dummy batch dimension. - Keep model construction and output-key details in model-building, input/file/reader assumptions in data-pipelines, and export/training setup in training-and-estimators.
Choose the workflow
- From the directory containing this file (
inference-and-deployment/), runpython scripts/sliding_window_plan.py --help, then provide spatial--input-shape,--window-shape, and--output-shape. The helper performs validation without importing TensorFlow, reading data, or contacting a network. - From that same sub-skill directory, run
python scripts/sliding_window_smoke.py. It exercises the native test shape plus output-smaller, overlapping, and batched assembly using constant synthetic predictions; it does not load a model or dataset. - For a real export, read deployment-workflows.md and api-reference.md first. Discover a numeric export directory, load the TF1 predictor, inspect its tensors, assemble a volume, convert probabilities/logits to the required result, calculate metrics if labels exist, and write output only to an explicitly chosen directory.
Inference checklist
- Validate all spatial dimensions, the predictor's input/output keys, channel count,
batch_size, and explicit stride before session execution. A malformed output/window combination can fail in padding or produce empty slices and a zero division counter. - Treat
sliding_window_segmentation_inferenceas an averaging assembler: it runs each patch, adds each output to the corresponding output slice, increments a separate coverage counter, and returnssum / counterfor each requested op. It returns a list inops_listorder, not class labels. - For segmentation, convert a
[batch, spatial..., classes]probability or logit result withnp.argmax(result, axis=-1). For probabilities, averaging overlapping patches before argmax is the DLTK MRBrainS pattern. For logits, a numerically stable softmax is useful when probabilities are needed, but argmax is unchanged. - Exclude or report background explicitly when aggregating Dice. DLTK's
dicereturnsNaNfor a class with no predicted and no reference voxels;np.nanmean(dice[1:])is an application policy, not a universal score. - For SimpleITK output, create the array image with the correct spatial order, call
CopyInformationfrom the source image, and only then write the requested.nii/.nii.gz. A shape or direction/spacing mismatch must be diagnosed rather than silently discarded. - Random-crop regression/classification deployment is stochastic. Record the crop count, shape, seed policy (if any), and aggregation axis; the original IXI examples average four random crops and explicitly warn that results vary between runs.
See troubleshooting.md before changing geometry, predictor access, export discovery, or metric handling.
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).