# R4 River Menne diatom model

Status: archive inspected, inference pending. The [public model archive](https://zenodo.org/records/7079072) is 38,314,661,790 bytes and contains 36 .pth or .h5 checkpoints. Individual Mask R-CNN checkpoints in the inspected sample are about 856 MB uncompressed and 800 MB compressed. The archive server honored a 64 KiB range request. The reproducible [archive inspection script](r4_archive.py) reads its directory with HTTP range requests. It requires network access.

The [accompanying paper](https://doi.org/10.1371/journal.pone.0272103) reports models trained on freshwater diatom slide scans and explains its object-centered tiling. The separate [training data archive](https://zenodo.org/records/7079005) is 8.8 GB and contains images, masks and COCO annotations. Model and data transfer to Academy optics and preparations remains unmeasured.

Next identify the best relevant trained run from the paper and archive metadata, retrieve that member with bounded range requests, verify archive CRC and checksum, and reconstruct the matching inference environment. Determine the version and compatibility of Detectron2 before attempting inference. Compare it on the same practice fields with the YOLO baseline, keeping the provisional points separate from expert evaluation.

## Checkpoint and scope

The archive contains a small U-Net checkpoint from the full-data `objectcentred_with_cropped` run, epoch 66. It was extracted with [bounded range requests](r4_retrieve.py); Python's ZIP reader verified the member CRC. The 19,912,288-byte checkpoint has SHA-256 `0e484808b6a953f4b1bc516b7d2a0db5b06f3e7b9da1720e6c79edab1764ad63` and is temporarily stored as `/tmp/menne-unet-e66.h5`. HDF5 metadata reports TensorFlow backend, Keras 2.4.0 and one-channel 512 × 512 input. An isolated Keras 3.15.1 environment with the PyTorch backend can load a copy after removing the legacy `groups: 1` configuration argument from Conv2DTranspose. Matching predictions with the original Keras 2/TensorFlow implementation remains unverified. The training run's exact tiling mapping and normalization still need confirmation from the notebook.

The paper describes an important fit issue: the authors annotated mostly intact valves, labeled smaller fragments as background, and combined overlapping instance masks into a semantic result. This U-Net produces a semantic image, so it is a useful transfer baseline but cannot directly count crossing specimens independently. The paper's reported metrics are pixel metrics and should not be interpreted as instance detection performance. Source imagery was focus-stacked at approximately 0.09 µm/pixel, whereas these scans have individual focal planes at approximately 0.114 µm/pixel. [Original methods and limitations](https://doi.org/10.1371/journal.pone.0272103)

## First transfer preview

The source testing notebook was selectively retrieved from the data archive. It normalizes grayscale pixels by 255 before prediction. The checkpoint was run with that normalization on four central 512 × 512 crops at the initial practice focal planes. [View the 0.95-threshold overlay](../results/r4/). At that threshold the output marks 31–85% of each crop, including extensive visible background and debris. At 0.5 the marked fractions change little, so the outputs are highly saturated in this run. These selected images and provisional user clicks do not establish precision or recall. One crop excludes the very edge of its original practice field.

This result uses the compatible Keras 3 model on the PyTorch backend, not the paper's TensorFlow/Keras runtime. Original-runtime parity has not been verified, so the background response could reflect compatibility, input domain, or both. Differences include scale, focus stacking, illumination and preprocessing beyond division by 255. The source notebook describes tile stitching and reflection padding; the preview uses individual central crops. Do not treat this as a validated failure of the original model. Run an archived source tile with both runtimes and compare numerical output before testing resampling and fine-tuning.

Reproduce the preview with `KERAS_BACKEND=torch MPLCONFIGDIR=/tmp/mpl-diatom PYTHONDONTWRITEBYTECODE=1 /tmp/diatom-research-venv/bin/python research/r4_unet.py`. The script reads the temporary checkpoint, adjusts a copied configuration and preserves the original.
