--- license: apache-2.0 datasets: - kostaspic/amfitrite-inland-waters-hab-sentinel2 - kostaspic/amfitrite-open-waters-hab-sentinel2 metrics: - f1 - accuracy base_model: - BIFOLD-BigEarthNetv2-0/resnet18-s2-v0.2.0 pipeline_tag: image-classification tags: - earth-observation - remote-sensing - sentinel-2 - water-quality - harmful-algal-blooms - environmental - edge-ai --- # Model Card for AMFITRITE-Sentinel2-HAB-Universal-ResNet18 This model is a lightweight deep learning classifier designed for the detection of **Harmful Algal Blooms (HABs)** across diverse aquatic environments (both inland and open waters) using **Sentinel-2 Level-2A** satellite imagery. It operates as a binary classifier, determining whether a water surface patch contains a HAB. The model is built on the **ResNet-18** architecture, to comply with the strict Size, Weight, and Power (SWaP) constraints of Low Earth Orbit edge devices, such as the Intel Myriad X VPU onboard the CogniSAT-6 satellite. It was initialized with weights pretrained on [**BigEarthNet v2.0**](https://huggingface.co/BIFOLD-BigEarthNetv2-0/resnet18-s2-v0.2.0) and fine-tuned as a **Universal Foundation Model** utilizing both the [Inland Water Dataset (IWD)](https://huggingface.co/datasets/kostaspic/amfitrite-inland-waters-hab-sentinel2) and the [Open Water Dataset (OWD)](https://huggingface.co/datasets/kostaspic/amfitrite-open-waters-hab-sentinel2). ## Dataset & Training Details The universal foundation model was trained on the combined datasets to eliminate the necessity for domain-specific deployments. Additionally, extended tests with domain-specific models tuned for inland and open waters showed that this foundation model performs equally good, or better than each domain-specific tuned model. * **Original Classes:** The IW dataset contains indicative severity classes ("High", "Moderate" and "Low") whie the OW contains binary classes ("HAB" and "non-HAB") * **Preprocessing for Detection:** To create a robust, generalized binary detector, the IWD classes were merged, matching the OWD classes: * **HAB (Class 1):** Merged `High` and `Moderate` samples. * **Non-HAB (Class 0):** Mapped from `Low` samples, along with purely clear water, land, and cloud tiles. ## Spectral Awareness Utilizes 10 spectral bands from Sentinel-2 in the following order: `B02, B03, B04, B05, B06, B07, B08, B8A, B11, B12`, matching the configuration of the BigEarthNet v2.0 pretrained weights for Sentinel-2 data. ## Performance The model was evaluated on a strictly stratified validation and test set to ensure reliability. | Metric | Validation Set | Test Set | | :--- | :--- | :--- | | **F1 Score** | 0.880 | 0.880 | | **Accuracy** | 0.886 | 0.893 | | **Balanced Acc** | 0.880 | 0.892 | | **HAB Accuracy** | 0.904 | 0.896 | | **non-HAB Accuracy** | 0.857 | 0.889 | | **IW F1 Score** | 0.848 | 0.869 | | **IW Accuracy** | 0.873 | 0.889 | | **IW Balanced Acc** | 0.845 | 0.873 | | **IW HAB Accuracy** | 0.895 | 0.893 | | **IW non-HAB Accuracy** | 0.776 | 0.832 | | **OW F1 Score** | 0.906 | 0.899 | | **OW Accuracy** | 0.906 | 0.900 | | **OW Balanced Acc** | 0.905 | 0.898 | | **OW HAB Accuracy** | 0.882 | 0.857 | | **OW non-HAB Accuracy** | 0.930 | 0.939 | HAB accuracy is the Sensitivity (Recall): (True Positives) / (True Positives + False Negatives) non-HAB accuracy is the Specificity: (True Negatives) / (True Negatives + False Positives) ## Limitations * The model expects standard L2A Sentinel-2 surface reflectance values (scaled 0-10000). ## Preprocessing Requirements To successfully run inference with this model, the input data must meet the following criteria: 1. **Dimensions:** The input image must be resized or cropped to exactly **256 x 256 pixels**. 2. **Channel Order:** The tensor must contain 10 bands in the exact following order: `B02, B03, B04, B05, B06, B07, B08, B8A, B11, B12`. 3. **Normalization:** The raw Sentinel-2 L2A pixel values (typically ranging from 0 to ~10000) must be divided by `10000.0`. 4. **Shape:** The final tensor passed to the model must have the shape `(Batch_Size, 10, 256, 256)`. ## How to Use This model requires the `timm` library. ### 1. Installation ```bash pip install torch timm rasterio ``` ### 2. Inference Code ```python import rasterio import torch import timm import numpy as np import torch.nn.functional as F # 1. Load Model (Configured for ResNet-18 with 10 input channels) model = timm.create_model('resnet18', pretrained=False, num_classes=2, in_chans=10) # Load weights (assuming the file is downloaded locally as 'amfitrite_universal_model.pth'), use huggingface_hub to download directly state_dict = torch.load("amfitrite_universal_model.pth", map_location='cpu') model.load_state_dict(state_dict) model.eval() def predict_patch(img_tensor): """ Args: img_tensor (torch.Tensor): A tensor of shape (10, Height, Width) containing Sentinel-2 bands. """ # 1. Add batch dimension -> Shape: (1, 10, H, W) img_tensor = img_tensor.unsqueeze(0) # 2. Force resize to the required 256x256 if img_tensor.shape[-2:] != (256, 256): img_tensor = F.interpolate(img_tensor, size=(256, 256), mode='bilinear', align_corners=False) # 3. Normalize Sentinel-2 DN values (0-10000) img_tensor = img_tensor / 10000.0 # 4. Predict with torch.no_grad(): output = model(img_tensor) score = torch.softmax(output, dim=1)[0, 1].item() # Network's score pred_class = torch.argmax(output, dim=1) return score, pred_class # --- Example Usage --- # Dummy tensor representing a 10-band image that is 256x256 pixels sample_image = torch.rand(10, 256, 256) * 5000 score, pred_class = predict_patch(sample_image) print(f"Score: {score:.2}, so class is: {pred_class}") ``` ## Citations & References If you use this model in your research, please cite the following papers for the underlying architecture and pre-training: **1. This Model:** Pikounis, K. (2026). *Sentinel-2 HAB Detector (RDNet Base)*. Amfitrite Project. ```bibtex @misc{pikounis2026hab, author = {Pikounis, Kostas}, title = {Sentinel-2 HAB Detector (RDNet Base)}, year = {2026}, publisher = {Hugging Face}, howpublished = {\url{https://huggingface.co/kostaspic/AMFITRITE-Sentinel2-HAB-RDNet}}, organization = {Amfitrite Project} } ``` **2. Amfitrite Datasets:** * IWD [kostaspic/amfitrite-inland-waters-hab-sentinel2](https://huggingface.co/datasets/kostaspic/amfitrite-inland-waters-hab-sentinel2) * OWD [kostaspic/amfitrite-open-waters-hab-sentinel2](https://huggingface.co/datasets/kostaspic/amfitrite-open-waters-hab-sentinel2) **3. BigEarthNet v2.0 (Pretraining Source):** K. Clasen, L. Hackel, T. Burgert, G. Sumbul, B. Demir, V. Markl, "reBEN: Refined BigEarthNet Dataset for Remote Sensing Image Analysis", IEEE International Geoscience and Remote Sensing Symposium (IGARSS), 2025. ```bibtex @inproceedings{clasen2025refinedbigearthnet, title={{reBEN}: Refined BigEarthNet Dataset for Remote Sensing Image Analysis}, author={Clasen, Kai Norman and Hackel, Leonard and Burgert, Tom and Sumbul, Gencer and Demir, Beg{\"u}m and Markl, Volker}, year={2025}, booktitle={IEEE International Geoscience and Remote Sensing Symposium (IGARSS)}, } ```