The inference code was broken because:
- AMG mode: Was using
get_amg()which doesn't load your trained checkpoint - it used pretrained SAM weights only - Decoder mode: Wasn't calling
segmenter.initialize(image)beforesegmenter.generate(), which is required forInstanceSegmentationWithDecoder - Missing parameters: No decoder thresholds (
center_distance_threshold, etc.) were being passed
Reverted to the working pattern from commit 41f1708:
- Use
get_predictor_and_segmenter()withamg=True/Falseparameter - For decoder mode: call
initialize()thengenerate()with threshold parameters - For AMG mode: use
automatic_instance_segmentation()
load_model_with_decoder(): Now usesget_predictor_and_segmenter()instead of manual model loadingsegment_image(): Added decoder mode handling withinitialize()+generate()pattern- Added
generate_kwargsparameter for decoder thresholds
Both inference scripts updated with:
- Added CLI parameters for decoder thresholds:
--center-dist-thresh(default: 0.5)--boundary-dist-thresh(default: 0.5)--foreground-thresh(default: 0.5)
- Pass these through the entire processing chain
- Both use the same refactored
inference_utils.py
Both updated to pass extra arguments through:
scripts/submit_inference_hcs.sh- for HCS platesscripts/submit_inference.sh- for TIFF/single zarr
HCS Plates: See test_inference_commands.sh for HCS zarr plates
TIFF/Single Zarr: See test_inference_tiff_commands.sh for TIFF directories
Both test:
- AIS with default thresholds - baseline decoder segmentation
- AIS with relaxed thresholds (0.6, 0.6, 0.4) - may find more instances
- AIS with strict thresholds (0.4, 0.4, 0.6) - fewer false positives
- AMG mode - automatic mask generation with your trained model
# HCS plates
bash test_inference_commands.sh
# TIFF/single zarr
bash test_inference_tiff_commands.shHCS results will be saved as separate label layers in your zarr files:
ais_default/ais_relaxed/ais_strict/amg_default/
TIFF results will be saved as separate directories:
inference_test/tiff_comparison/ais_default/inference_test/tiff_comparison/ais_relaxed/inference_test/tiff_comparison/ais_strict/inference_test/tiff_comparison/amg_default/
- Run the test commands on the cluster
- View results in napari side-by-side to compare modes
- Adjust thresholds based on which works best
- Use best mode for production runs
- The decoder thresholds are CRITICAL - they control how instances are identified from the predicted distance maps
- Lower thresholds = more permissive (more instances, possible false positives)
- Higher thresholds = more strict (fewer instances, possible false negatives)
- AMG mode doesn't use these thresholds - it uses different internal parameters