Map vegetation functional states
FVC Function uses drone multispectral and hyperspectral imagery to map bare earth (BE), non-photosynthetic vegetation (NPV), and photosynthetic vegetation (PV). The workflow aligns imagery and reference labels, trains sensor-specific U-Net models, and produces prediction maps.
Browse the study’s tables and figures in the interactive manuscript viewer.
Framework architecture
The paper evaluates an NPV-aware U-Net for multispectral and imaging spectroscopy data. The spectral front end feeds the same spatial encoder–decoder across all five ablation variants.
Core research modules
Reweight input bands and project them into a 32-channel learned spectral embedding before the U-Net encoder. Each channel is a learned spectral feature.
Use global spatial summaries to estimate interactions between the learned channels in M4 and M5.
Use a U-Net to map photosynthetic vegetation (PV), non-photosynthetic vegetation (NPV), and bare earth (BE).
Use three spatial folds at the source site and frozen models for zero-shot evaluation on five external-site tiles.
Use fvc3d to project growth-form labels onto LiDAR and check label consistency.
Export trained models to ONNX and benchmark TensorRT inference on the Jetson platform.
Optional external integrations
Package adapters can connect compatible third-party PyTorch encoders and segmentation models. Check their input channels and output format before integration.
Next. Set up the environment to reproduce the paper, or install the hyperFVC package to use the models in your own code.
Set up the workflow environment
Where to start
Start with Image processing for raw orthomosaics or Quick start to try the Python model.
1. Prerequisites
Use Git and micromamba for the research environment. See the environment guide for GPU and Docker options.
2. Create the environment
git clone https://github.com/LNSOTOM/fvc_function.git
cd fvc_function
micromamba env create -n fvc_function -f environment.yml
micromamba activate fvc_function3. Configure data paths
Set the roots in configs/paths.yaml or pass environment overrides such as FVC_DATA_ROOT.
python utils/fvc_paths.py --checkPrepare aligned imagery tiles
Start with georeferenced drone orthomosaics. Use a common footprint and tile IDs for the imagery and labels.
1. Set the reference grid
Reproject the inputs to a common CRS and construct the site grid.
2. Clip the orthomosaics
Export tiles with consistent extents across the available sensors.
Reference grid and clipping module
Install the imagery extra from the repository root with python -m pip install -e '.[imagery]'. Replace the example paths with your files. Import the existing reference tiles to keep their IDs and footprints. For a new row-major grid, use reference-grid --raster INPUT --tile-size 307 --output grid.json.
hyperfvc reference-grid \
--reference-tile 65 reference/tile-65.tif \
--reference-tile 96 reference/tile-96.tif \
--reference-tile 113 reference/tile-113.tif \
--output grid.json
hyperfvc plot-grid --grid grid.json --input mica.dat \
--bands 10 6 2 --output mica-grid.png
hyperfvc plot-grid --grid grid.json --input fx10-fx17.dat \
--bands 87 50 19 --output hyspec-grid.pnghyperfvc clip-orthomosaic --grid grid.json --input mica.dat \
--output-dir clips --prefix mica --resolution 0.10
hyperfvc clip-orthomosaic --grid grid.json --input fx10-fx17.dat \
--output-dir clips --prefix hyspec --resolution 0.10Change --resolution to set the output pixel size in grid CRS units. Use --tile-ids 65 113 to process a subset, or --bands to export selected source bands. Omitting --bands from the clipping command exports every band. To preview a single clip, run plot-grid on its GeoTIFF with the same --tile-ids value and display bands. The Python equivalents are build_reference_grid(), reference_grid_from_tiles(), plot_reference_grid(), and clip_orthomosaic() in hyperFVC.imagery.
3. Prepare predictor cubes
Compute normalization statistics and stack the selected bands. Follow the Phase 1 guide for the commands.
The percentile envelopes show the reflectance spread of these example clips. Use the model profile’s expected normalization when preparing inputs for a trained checkpoint.
Predictor preparation module code
Use band_statistics() on tiles from one sensor profile. A scale factor of 10,000 converts the integer values in these examples to reflectance. Use stack_predictor_bands() on aligned inputs. Band numbers are one-based, and the order in the input list becomes the output band order.
from hyperFVC.imagery import band_statistics, stack_predictor_bands
tile_ids = (65, 96, 113)
mica_stats = band_statistics(
[f"clips/mica-{tile}.tif" for tile in tile_ids],
scale_factor=10_000, percentiles=(2, 98),
)
hyspec_stats = band_statistics(
[f"clips/hyspec-{tile}.tif" for tile in tile_ids],
scale_factor=10_000, percentiles=(2, 98),
)
stack_predictor_bands(
[("fx10-aligned.dat", range(10, 216)),
("fx17-aligned.dat", range(7, 97))],
"fx10-fx17-predictors.tif",
)Next. Use the grid and tile IDs to align reference labels.
Prepare FVC reference labels
1. Prepare annotations
Convert LabelMe annotations to polygons and prepare the bare-earth class.
2. Rasterize and mask
Create class rasters and handle shadow and water according to the site’s label scheme.
3. Match the predictor grid
Downsample labels with majority voting and check the tile ID, CRS and grid. See the Phase 2 guide.
Next. Pair predictor tiles and reference rasters for modelling.
Train and apply FVC models
1. Select a sensor profile
Choose MICA multispectral, FX10, FX17 or the combined FX10–FX17 input. Match the bands, class codes and normalization to the profile; see the training and inference runbook.
2. Prepare training and evaluation splits
Use spatial blocks and keep evaluation tiles apart from training and augmentation.
The hyperFVC experiments use 8 training, 3 validation, and 4 held-out test tiles per fold. All patches from a parent tile stay together. With nine patches per tile, that gives 72 training, 27 validation, and 36 test patches.
Patch extraction module code
Use hyperFVC.imagery.iter_paired_patches() on a 304 × 304 predictor and its aligned reference mask. Set the patch size and stride in pixels. The same window is read from both rasters, with the original tile ID attached for the spatial split.
from hyperFVC.imagery import iter_paired_patches
# Size and stride in pixels. A 304 × 304 tile yields 9, 4, and 1 patches.
for size, stride in ((152, 76), (224, 80), (304, 304)):
patches = list(iter_paired_patches(
"tiles_hyperspectral_113.dat",
"mask_tile113_fulltile.tif",
tile_id=113, patch_size=size, stride=stride,
))
print(size, len(patches))Use min_valid_fraction to exclude patches with insufficient valid imagery or labels. For prediction comparisons, use the checkpoint trained for each patch size. The original patch export script and training runbook are also available.
Build loaders for a spatial fold
Use hyperFVC.evaluation.data_loader to build PyTorch loaders for the recorded tile assignments. Supply an image–mask dataset and one parent tile ID per sample, in dataset order. Pass an optional augmented version of the same dataset as train_dataset to apply augmentation during training.
from hyperFVC.evaluation.data_loader import build_fold_loaders
# patch_tile_ids repeats the parent ID for every patch in dataset.
train_loader, validation_loader, test_loader = build_fold_loaders(
dataset,
patch_tile_ids,
validation_tiles={34, 182, 205},
test_tiles={22, 25, 26, 55},
batch_size=8,
)3. Train with data augmentation
Augmentation is applied during training only. The manuscript’s core protocol was used for FX10, FX17, and combined FX10–FX17 hyperspectral inputs. The MICA multispectral configuration used the same core protocol plus a shadow-robust add-on.
| Operation | Protocol | Augmentation type | Probability |
|---|---|---|---|
| Horizontal flip | Core | Geometric | 0.5 |
| Vertical flip | Core | Geometric | 0.5 |
| Random rotation in 90° increments | Core | Geometric | 0.5 |
| Mild coherent brightness–contrast jitter | Core | Radiometric | 0.5 |
| Global gain jitter | MICA add-on | Radiometric | 0.5 |
| Per-band gain jitter | MICA add-on | Radiometric | 0.5 |
| Gamma adjustment | MICA add-on | Radiometric | 0.35 |
| Mild Gaussian noise | MICA add-on | Radiometric | 0.2 |
| Synthetic shadow patches | MICA add-on | Shadow simulation | 0.35 |
Apply each geometric transform identically to the predictor patch and its PV, NPV, and BE mask. Apply radiometric and shadow changes only to reflectance. Preserve invalid and unlabelled pixels as ignore regions.
Build an augmentation pipeline by sensor
Install the augmentation extra from the repository root with python -m pip install -e '.[augmentation]'. Select "mica" for the core protocol and shadow-robust additions, or "hyspec" for the four core operations. Pass in the full reflectance cube and its aligned class mask.
import numpy as np
from hyperFVC.augmentation import build_augmentation
augment = build_augmentation("hyspec") # Use "mica" for multispectral inputs.
# image has shape (height, width, bands); mask has shape (height, width).
ignore = (~np.isfinite(mask) | (mask == -1)).astype(np.uint8)
result = augment(image=image, mask=mask, ignore_mask=ignore)
augmented_image = result["image"]
augmented_mask = result["mask"].astype(np.float32)
augmented_mask[result["ignore_mask"] != 0] = np.nan4. Run inference and evaluate
Use a matching checkpoint on the held-out test tiles. Metrics come from deterministic inference: hard class predictions, with softmax outputs for probability maps.
Original orthomosaic inference script
Run the streaming inference script from the repository root. Set the sensor profile, input path, checkpoint, and window size to match the model you trained.
SENSOR_PROFILE=fx10_fx17_215_trim_aug_spec_transformer_weights_s152 \
python phase_3_models/unet_site_models/inference_FVCmapping_streaming.py \
--input-raster fx10-fx17.dat --checkpoint-path m5-hyspec-152.pth \
--tile-size 152 --output-mask fvc-predictions.tifDeterministic inference module code
Use hyperFVC.evaluation.zero_shot.predict_classes() for an already prepared batch with the trained model’s band order and normalization. The module uses evaluation mode and returns one class ID per pixel.
from hyperFVC.evaluation.zero_shot import predict_classes
# model: loaded checkpoint; image: (batch, bands, height, width).
# valid_mask: Boolean tensor (batch, height, width) on the same device.
class_ids = predict_classes(model, image)
class_ids = class_ids.masked_fill(~valid_mask, 255)See the package quick start to write class IDs to a GeoTIFF with the predictor’s CRS and transform.
Monte Carlo dropout uncertainty. As a separate post-inference diagnostic, keep the network’s dropout layers (p = 0.3) active with the weights fixed and run T = 50 stochastic forward passes per patch. The pixel-wise epistemic uncertainty is the mean class-wise standard deviation of the logits across the passes; map it alongside the FVC classes.
Monte Carlo dropout module code
from hyperFVC.evaluation.uncertainty import mc_dropout_uncertainty
# image: (batch, bands, height, width), prepared for the trained model.
# valid_mask: (batch, height, width), True where the image contains valid data.
uncertainty = mc_dropout_uncertainty(
model,
image,
num_passes=50,
valid_mask=valid_mask,
) # (batch, height, width); invalid pixels are NaN.Edge deployment. Export a trained model to ONNX and build a TensorRT engine for an NVIDIA Jetson AGX Orin. In the paper, the FX10–FX17 model ran 1.70× faster as an FP16 TensorRT engine than as an FP32 one (9.62 vs 16.31 ms per tile), with 99.96% of pixel labels matching the PyTorch model. See the Jetson guide; this was benchmarked on the device, not flown.
Next. Compare the trained models in the benchmark.
Model benchmark design
Compare M1–M5 to assess the spectral adapter, transformer and NPV weighting within the U-Net family.
M1–M5 variantsCompare the M5 pipeline with five baselines on the combined 296-band FX10–FX17 input.
Benchmark baselinesCompare map detail and within-site scores at 152, 224, and 304 pixels.
Compare patch sizesCompare M5 with and without the 15 interpolated channels in the water-absorption interval.
Compare band inputsInternal ablation | M1–M5
| Variant | Spectral features | Class weights (BE, NPV, PV) |
|---|---|---|
| M1 | Baseline U-Net | Unweighted |
| M2 | Spectral adapter | Unweighted |
| M3 | Spectral adapter | 1, 2, 1 |
| M4 | Spectral adapter and transformer | Unweighted |
| M5 | Spectral adapter and transformer | 1, 2, 1 |
See the ablation notes for the sensor profiles and patch scales.
Comparison with baseline methods
The 296-band benchmark used identical spatial folds and held-out tiles for M5, a per-pixel Random Forest, plain U-Net M1, PCA-3 and PCA-10 U-Nets, and a published spectral–spatial CNN. The comparison measures complete training pipelines, including M5’s NPV-weighted loss. See the external comparison notebook for the saved figures and tables.
How patch size affects predictions
At the same 10 cm pixel resolution, larger FX10–FX17 patches cover more ground. On Calperum tile 65, 152 px patches retained smaller NPV fragments and local boundaries. Maps from 224 and 304 px patches showed smoother, more continuous regions.
| Patch size | Ground width | NPV F1 | mIoU |
|---|---|---|---|
| 152 × 152 px | 15.2 m | 0.461 | 0.573 |
| 224 × 224 px | 22.4 m | 0.479 | 0.621 |
| 304 × 304 px | 30.4 m | 0.500 | 0.637 |
For M5, 304 px scored highest within site. On the five external tiles, the selected 152 px model achieved mIoU of 0.455 and the selected 304 px model achieved 0.107. See the geographic evaluation for context.
Water-absorption band exclusion
The FX10–FX17 sensitivity experiment removed the 15 interpolated channels within the atmospheric water-absorption interval of 1320.9–1419.62 nm. Both runs used the same spatial folds, patch generation, M5 configuration, and evaluation metrics.
| Interpolated water-absorption channels | Input bands | NPV F1 |
|---|---|---|
| With the 15 channels | 296 bands | 0.461 |
| Without the 15 channels | 281 bands | 0.409 |
Excluding the channels lowered NPV F1 by 0.052 under the tested conditions.
Geographic evaluation
Frozen source-site models were evaluated on five manually reviewed tiles from SASMDD0013. The highest zero-shot NPV F1 was 0.120 across the evaluated models. These results describe the five evaluated tiles. Read the preprint.
Next. That completes the reproduction workflow. To use the models in your own code, install the hyperFVC package.
Install hyperFVC
From the repository root, install with Python 3.10 or newer.
python -m pip install -e .
hyperfvc variant M5Development version
The editable install uses your local checkout. Install .[imagery] for raster preparation, .[augmentation] for training transforms, .[onnx] for ONNX export, or .[labels3d] for LiDAR label transfer.
Next. Build your first model in the quick start.
Build a spectral U-Net
Create a five-band, three-class M5 model. Load matching trained weights before inference. If you haven’t installed the package yet, see Install hyperFVC.
from hyperFVC.configs import load_variant
from hyperFVC.segmentation.unet import UNetModel
preset = load_variant("M5")
model = UNetModel(in_channels=5, out_channels=3, **preset["model"])Clip orthomosaics with hyperFVC
Install the imagery extra with python -m pip install -e '.[imagery]'. Run clip_orthomosaic() for each sensor with the same grid manifest to produce aligned MICA and Hyspec GeoTIFFs.
from hyperFVC.imagery import clip_orthomosaic
tiles = clip_orthomosaic(
"mica.dat", "grid.json", "clips",
resolution=0.10, tile_ids=[65, 96, 113], prefix="mica",
)See Phase 1 orthomosaic clipping for the CLI commands and the paired MICA and Hyspec examples.
Export a vegetation map and a labelled point cloud
For the raster example, install rasterio and use one predictor tile already normalized and ordered for your checkpoint. Match the model variant, band count and architecture to the saved weights. The example uses M5 and a plain PyTorch state dict.
import numpy as np
import rasterio
import torch
from hyperFVC.configs import load_variant
from hyperFVC.evaluation.zero_shot import predict_classes
from hyperFVC.segmentation.unet import UNetModel
vegetation_map = "vegetation_map.tif"
with rasterio.open("hyperspectral.tif") as src:
tile = src.read(masked=True, out_dtype="float32")
profile = src.profile.copy()
model = UNetModel(tile.shape[0], 3, **load_variant("M5")["model"])
model.load_state_dict(torch.load("spectral_unet.pth", map_location="cpu", weights_only=True))
values = tile.filled(0)
valid = ~np.ma.getmaskarray(tile).any(axis=0) & np.isfinite(values).all(axis=0)
values[:, ~valid] = 0
classes = predict_classes(model, torch.from_numpy(values[None]))[0].numpy().astype("uint8")
classes[~valid] = 255
profile.update(driver="GTiff", count=1, dtype="uint8", nodata=255)
with rasterio.open(vegetation_map, "w", **profile) as dst:
dst.write(classes, 1)The GeoTIFF uses BE = 0, NPV = 1, PV = 2 and NoData = 255. For 3D structure, install .[labels3d] and use a separate growth-form GeoTIFF aligned to the LiDAR. This example uses the published growth-form raster codes 0–4.
from hyperFVC.labels3d.projection import transfer_labels
labelled_cloud = transfer_labels(
labels="growth_forms.tif",
point_cloud="lidar.laz",
output="labelled_cloud.laz",
class_map="paper",
)
print(labelled_cloud.summary())See the 3D label-transfer input requirements for coordinate systems and height above ground.
Next. Check tensor shapes and class codes in Prepare inputs.
Prepare inputs for segmentation
Image tensors
Pass normalized tensors in (batch, bands, height, width) order. Use the checkpoint’s band order and normalization.
Class codes
The three-class presets use BE = 0, NPV = 1 and PV = 2. M3 and M5 provide weights [1, 2, 1] for the loss.
Next. Look up signatures and arguments in the API reference.
hyperFVC Python API
The main entry points, grouped by task. For a complete example, start with the quick start; for tensor shapes and class codes, see Prepare inputs.
Segmentation and presets
hyperFVC.configs.load_variant
load_variant(name: str) -> dict
Load the model settings and class weights for M1–M5.
hyperFVC.segmentation.unet.UNetModel
UNetModel(in_channels, out_channels, ...)
Build the spectral segmentation network. See Quick start for preset arguments.
Evaluation and deployment
hyperFVC.evaluation.zero_shot.predict_classes
predict_classes(model, images)
Return per-pixel class IDs from semantic logits.
hyperFVC.deployment.export.export_onnx
export_onnx(model, example_input, output_path)
Write an ONNX model with dynamic batch size and the example’s spatial dimensions.
See the package README for spectral layers, losses, fine-tuning and optional 3D label transfer.
Cite the study
Use the citation on the EarthArXiv preprint. Cite the Fractional Vegetation Cover Mapping dataset when using the study data.