How it works
One image goes in. A frozen ResNet-50 turns it into features, and two small heads read them: one for cell shape, one for Gram status.
The five stages
- Original. The image exactly as it was uploaded.
- Resized 224. Resized to 224 by 224 pixels for the model.
- ImageNet normalization. Colors scaled with ImageNet statistics.
- Segmentation mask. Cells grouped from the background.
- Object boundary. Touching groups separated with watershed.
Segmentation runs on the original image, not on the 224 pixel copy. A 1 micron cell is about 21 pixels wide at full size but only about 2 pixels at 224, so the cleanup steps would erase it.
The model
- Backbone: ResNet-50 with ImageNet V2 weights, frozen. torchvision downloads these weights on the first start of the API.
- Heads: two linear layers with 2048 inputs and 2 outputs each. One predicts shape (cocci or bacilli), the other Gram status (positive or negative).
- Checkpoint: apps/api/checkpoints/heads.pt holds the two heads only.
Confidence levels
- High: confidence 0.8 or above.
- Medium: 0.6 to 0.79.
- Low: below 0.6. Check with a standard stain.
Data and test result
- Trained on DIBaS (Zielinski et al., 2017): 669 images from 32 bacterial species, split into 467 for training, 136 for validation and 66 for testing. Candida albicans is left out because it is a fungus.
- On the 66 test images, macro F1 and accuracy are 1.00 for both heads. The test images come from the same public dataset as the training images, so this says little about other microscopes, stains or laboratories.
What comes back
Both predictions with a confidence level, the five stage images, and notes about any stage that could not be produced.
This result is an aid, not a diagnosis. Segmentation groups cells, it does not isolate individual cells.