Repository navigation
Derive the default tiling from the model's training patch shape - #188
Conversation
The default tiling was chosen from the VRAM alone. It now starts from the training patch shape of the model and grows by at most 20% if the VRAM allows. - Add get_model_training_patch_shape to the model registry; uncertain values are marked. - Read the patch shape from torch_em checkpoints; UNETRs use exactly their patch shape (#186). - Raise an error for an in-memory UNETR without a tiling. - Use the model-dependent tiling in run_segmentation, the CLI and the segmentation widget. - Fix the y/x swap of the block shape in get_prediction_torch_em. - Fix the widget ignoring tiling changes after the first prediction. Closes #187, closes #186. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The mitochondria and cristae models were trained on 32x256x256, so they are no longer marked as uncertain. On the CPU the default halo is capped at 4x16x16, because a large halo makes the prediction slow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… tiling test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hi @stmartineau99 , |
|
It works, but I have a few thoughts.
|
|
Cool thanks, once this merges, I'll make a PR for the bf16 change. |
…dent-on-the-models-training-patch-shape # Conflicts: # test/test_inference.py
The float mitochondria channel in segment_cristae comes from the second input channel, which has the dtype of the tomogram; regionprops only accepts integer labels. evaluate_test_set.py: since #188 the default tiling depends on the model's training patch shape and on the hardware, not only on the GPU memory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Closes #187, closes #186.
What changes
The default tiling used to depend only on the VRAM. It now starts from the model's training patch shape and grows by at most 20% when the VRAM allows. Growth is rounded down to multiples of 8 in z and 16 in y/x.
get_model_training_patch_shape(model_type). Each entry names its source script, and guessed values are markedUNCERTAIN:mitochondria,mitochondria2,cristae–cristae5,vesicles_2d_maus. Please check these.get_predictionreads the patch shape frombest.pt(init["train_dataset"]). A UNETR uses exactly its training patch, with no growth. This fixesget_default_tilingis designed to suit UNET models, but not UNETR models. #186: a UNETR resizes each tile to its encoder input, so larger tiles change the scale and can OOM.ValueErrorthat explains how to pass the tiling.run_segmentation, the CLI and the segmentation widget use the new default. The CLI uses the checkpoint's patch shape when-cis a torch_em checkpoint. The widget resets the tile/halo boxes when the model changes.get_prediction_torch_emhad y/x swapped inblock_shapeandhalo.Default tiles now
The halo is derived from the patch (
min(size // 4, 64)), so it is the same on all devices. Large GPUs now use smaller tiles than before, so inference there will be slower.Testing
TestTilingcovers the growth rule with mocked VRAM, 2D and UNETR handling, and reading the patch shape from a checkpoint. A widget test checks that the tiling follows the selected model.test/trainingbecause the local torch_em lackstorch_em.model.cryozoo; they are unrelated to this PR.best.pt) and a mean-teacher checkpoint use exactly their training patch.torch.savemodel falls back to the VRAM tiling.Known limitations
torch.savefile in the CLI, uses the selected model's patch shape.update-backbonesaddsdtypeto the sameget_predictionsignatures, so a small conflict is expected.🤖 Generated with Claude Code