Skip to content

SimoneCff/coralreef-risk-FCM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

coral-reef-risk-fcm

A Hybrid Framework for Automated Coral Reef Risk Assessment by Zero-Shot Visual Perception and Fuzzy Cognitive Map Inference

Fabio Porcelli · Simone Cioffi · Emanuel Di Nardo · Angelo Ciaramella Department of Science and Technologies — University of Naples Parthenope


Overview

This repository contains the full reproducible pipeline described in the paper "A Hybrid Framework for Automated Coral Reef Risk Assessment by Zero-Shot Visual Perception and Fuzzy Cognitive Map Inference".

The system performs automated ecological risk assessment of coral reef ecosystems in two sequential stages:

  1. Stage 1 — Zero-Shot Feature Extraction: Gemma 4-E4B (Google DeepMind, April 2026) is used as a multimodal perception layer. Given a raw underwater survey image, the model is prompted as an expert marine biologist and returns 25 quantitative ecological features in JSON format — no fine-tuning required.

  2. Stage 2 — Fuzzy Cognitive Map Inference: The feature vector is fed as clamped input activations into a Fuzzy Cognitive Map (FCM) with an expert-initialised causal weight matrix. Iterative sigmoid dynamics propagate causal influence through 31 concept nodes until convergence, producing a six-dimensional ecological risk profile.

The entire pipeline runs in a zero-shot regime on a single NVIDIA T4 GPU (Kaggle platform) using exclusively open-weight models and public datasets.


Pipeline

Coralscapes Image (1024×2048 px)
        │
        ▼
┌─────────────────────────────┐
│  Stage 1 · Gemma 4-E4B      │  ← zero-shot, JSON output, no fine-tuning
│  25 ecological features     │
│  normalised to [0, 1]       │
└────────────┬────────────────┘
             │  feature vector x ∈ [0,1]²⁵
             ▼
┌─────────────────────────────┐
│  Stage 2 · Fuzzy Cognitive  │  ← expert weight matrix, sigmoid dynamics
│  Map (31 nodes, 94 edges)   │
│  clamped input activations  │
└────────────┬────────────────┘
             │
             ▼
     Risk Profile r ∈ [0,1]⁶
  ┌─────────────────────────┐
  │ ecosystem_health        │
  │ pollution_risk          │
  │ thermal_stress_risk     │
  │ habitat_degradation_risk│
  │ recovery_potential      │
  │ heritage_integrity_risk │
  └─────────────────────────┘

Ecological Features

The 25 features extracted by Gemma 4-E4B are grouped into three thematic categories:

Group Features
Coral-specific (12) coral_cover_alive, coral_bleaching, coral_morphology_diversity, dead_coral_algae, juvenile_coral_recruitment, coralline_algae, substrate_rugosity, rubble_cover, sediment_stress, water_turbidity, algae_coverage, sand_cover
General marine (7) fish_abundance, seagrass_coverage, macro_invertebrate_diversity, sponge_coverage, coral_disease_signs, crown_of_thorns_starfish, soft_coral_abundance
Anthropogenic (6) anchoring_mechanical_damage, ghost_fishing_gear, blast_fishing_damage, image_assessability, sea_urchin_density, marine_debris

FCM Dynamics

Risk concept activations are governed by:

$$c_j^{(t+1)} = \sigma!\left(\sum_{i \in C_{\mathrm{in}}} w_{ij}, x_i + \sum_{k \in C_{\mathrm{risk}}} w_{kj}, c_k^{(t)}\right), \quad j \in C_{\mathrm{risk}}$$

where $\sigma(z) = (1 + e^{-z})^{-1}$ is the sigmoid activation function. Input concepts are clamped throughout inference. Convergence is defined as $|c^{(t+1)} - c^{(t)}|_\infty < 10^{-5}$, with a maximum of 50 iterations. In practice, all risk concepts converge within 4–5 iterations.


Dataset

The pipeline is evaluated on the Coralscapes dataset (Sauder et al., ICCVW 2025):

  • 2,075 high-resolution images (1024×2048 px)
  • 35 dive sites across 5 Red Sea countries
  • 174k expert-labelled polygons, 39 benthic classes
  • Experiments reported here use the test split (N = 50 images)

Results

Scenario Analysis

FCM risk profiles for four synthetic ecological scenarios, validating the ecological consistency of the expert weight matrix:

Scenario EH PR TSR HDR RP HIR
Healthy reef 0.986 0.451 0.511 0.068 0.959 0.476
Post-bleaching 0.339 0.616 0.556 0.819 0.144 0.697
COTS + blast fishing 0.081 0.692 0.500 0.962 0.034 0.855
Urchin barren 0.674 0.500 0.500 0.540 0.459 0.568

EH = ecosystem health · PR = pollution risk · TSR = thermal stress risk · HDR = habitat degradation risk · RP = recovery potential · HIR = heritage integrity risk. Higher EH and RP indicate healthier conditions; higher PR, TSR, HDR, and HIR indicate greater risk.

Sample Result — test_0

ecosystem_health       = 0.69
pollution_risk         = 0.59
thermal_stress_risk    = 0.52
habitat_degradation_risk = 0.48
recovery_potential     = 0.51
heritage_integrity_risk = 0.50

Consistent with a moderately degraded reef exhibiting residual structural complexity (substrate_rugosity = 0.70, coral_morphology_diversity = 0.60) alongside early-stage stressors.


Repository Structure

coral-reef-risk-fcm/
│
├── gemma4-fcm.ipynb       # Main notebook (Kaggle T4, Python 3.12)
├── README.md
└── outputs/
    └── results.jsonl      # Per-image feature vectors and risk scores

Requirements

The notebook is designed to run on Kaggle with a T4 GPU. The required Kaggle datasets and model sources are declared in the notebook metadata:

  • google/gemma/keras/gemma4-e4b (Gemma 4-E4B model weights)
  • Coralscapes dataset (dataset version ID 15929973)

Main Python dependencies:

torch
transformers
Pillow
numpy
pandas
networkx
matplotlib
tqdm

For larger Gemma 4 variants (26B-A4B, 31B), 4-bit NF4 quantisation via bitsandbytes is supported.


Data

The Coralscapes dataset is not included in this repository. Download it via one of the following:

Quickstart

# Clone the repo and open the notebook on Kaggle
# Make sure the T4 GPU accelerator is enabled

# Stage 1: extract features from a single image
features = extract_features_gemma4(image_path)  # returns dict with 25 features in [0,1]

# Stage 2: run FCM inference
risk_profile, history = simulate_fcm(features, n_iter=50)
print(risk_profile)  # {'ecosystem_health': ..., 'pollution_risk': ..., ...}

Results are written to /kaggle/working/results.jsonl (one JSON record per image) and a summary CSV is exported via summary.csv.


Citation

If you use this code or the framework in your research, please cite:

@inproceedings{porcelli2026coral,
  title     = {A Hybrid Framework for Automated Coral Reef Risk Assessment
               by Zero-Shot Visual Perception and Fuzzy Cognitive Map Inference},
  author    = {Porcelli, Fabio and Cioffi, Simone and
               Di Nardo, Emanuel and Ciaramella, Angelo},
  booktitle = {Proceedings of the ...},
  year      = {2026},
  institution = {University of Naples Parthenope}
}

License

The code in this repository is released under the Apache 2.0 License, consistent with the Gemma 4 model license.

The Coralscapes dataset is subject to its own terms — see the original dataset page for details.


Acknowledgements

This work uses Gemma 4 by Google DeepMind (Apache 2.0) and the Coralscapes dataset by Sauder et al. Experiments were conducted on the Kaggle platform with free T4 GPU access.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors