Views
No views yet
build_HyperVision_bbuild_HyperVision_lbuild_HyperVision_h1import torch
2from HyperVision import build_HyperVision_h, HyperVision_Predictor
3from hyperspectral_image_reader.read_dataset_image import load_hypervision_matrix
4from hyperspectral_image_reader.hyperspectral_pipelines import LoadHyperspectralImage
5
6device = "cuda" if torch.cuda.is_available() else "cpu"
7image_size = 512
8
9# 1. Build the HyperVision model (HyperVision-H configuration shown below)
10model = build_HyperVision_h(
11 checkpoint="path/to/hypervision_distilled_h.pth", # Optional checkpoint path (.pth weights)
12 image_size=512, # Input resolution
13 vit_patch_size=16, # Patch size of the backbone
14 encoder_global_attn_indexes=[15, 23, 31], # Layers using global attention (can be adjusted for debugging/tuning)
15 merge_indexs=[8, 32], # Layers doing patch merging (can be adjusted for debugging/tuning)
16 class_number=-1 # Number of classes for mask decoder
17)
18model = model.to(device)
19model.eval()
20
21# 2. Use HyperVision_Predictor to manage preprocessing and feature extraction
22predictor = HyperVision_Predictor(model)
23
24# 3. Load the preprocessed HSI image as a numpy array using load_hypervision_matrix
25# Preprocessed shape: (H_ori, W_ori, C_hsi) with values in range [0, 255]
26img_matrix = load_hypervision_matrix("path/to/image.mat", dataset_name="harvard")
27
28# 4. Automatically retrieve the wavelengths list from the dataset pipeline config
29loader = LoadHyperspectralImage(dataset_type="harvard")
30wavelengths = loader.wavelengths
31
32# 5. Call predictor.set_image to preprocess the image and extract features (calculating embeddings)
33# GSD represents Ground Sampling Distance (defaults to 0.01)
34with torch.no_grad():
35 predictor.set_image(img_matrix, test_mode=False, spectral_lengths=wavelengths, GSD=0.01)
36
37# 6. Extract multi-scale features from the predictor
38multi_stage_features = predictor.multi_scale_featuresLoadHyperspectralImage from configs/hypervision/hyperspectral_pipelines.py to normalize the images (scaled to [0, 255]) and reshape them into the format expected by HyperVision: (H_ori, W_ori, C_hsi).1from hyperspectral_image_reader.read_dataset_image import load_hypervision_matrix
2
3# Load and preprocess HSI matrix
4# dataset_name must be one of the supported dataset identifiers (e.g., 'harvard', 'arad_1k_31')
5img_matrix = load_hypervision_matrix("path/to/image.mat", dataset_name="harvard")
6print("Processed shape (H, W, C):", img_matrix.shape).npy file:python hyperspectral_image_reader/read_dataset_image.py --path /path/to/image.mat --dataset harvard --output output.npy--dataset parameter:| Dataset Name | --dataset Key | # Bands | Wavelengths | # Images | Expected Extension | File Loader Detail / Required Accompanying Files |
|---|---|---|---|---|---|---|
| 50 Outdoor | fiftyoutdoor | 33 | 400–720 nm | 50 | .mat | Custom Mat loader |
| Agricultural Plant | aphid | 237 | 436–965 nm | 361 | .npy | NumPy array loader |
| ARAD1K16 | arad_1k_16 | 16 | 400–1000 nm | 950 | .mat | HDF5 H5PY loader |
| ARAD1K31 | arad_1k_31 | 31 | 400–700 nm | 949 | .mat | HDF5 H5PY loader |
| CAVE | cave | 31 | 400–700 nm | 32 | .mat | Mat loader |
| DeepHS-NIR | deephsnir | 252 | 950–1700 nm | 718 | .bin | ENVI binary (requires corresponding .hdr file in the same directory) |
| DeepHS-VIS | deephsvis | 224 | 400–1000 nm | 3405 | .bin | ENVI binary (requires corresponding .hdr file in the same directory) |
| DeepHS-VISCOR | deephsviscor | 249 | 400–1000 nm | 1566 | .bin | ENVI binary (requires corresponding .hdr file in the same directory) |
| Harvard | harvard | 31 | 420–720 nm | 77 | .mat | Mat loader |
| HOT-2024-NIR | hotnir | 25 | 665–960 nm | 477 | .png | PNG frame loader (requires corresponding false-color .jpg file) |
| HOT-2024-RedNIR | hotrednir | 15 | 600–850 nm | 348 | .png | PNG frame loader (requires corresponding false-color .jpg file) |
| HOT-2024-VIS | hotvis | 16 | 470–600 nm | 1070 | .png | PNG frame loader (requires corresponding false-color .jpg file) |
| HSI Drive v2.0 | hsidrive20 | 25 | 600–975 nm | 752 | .npy | NumPy loader (requires corresponding pseudocolor .png file) |
| HSI Road | hsiroad | 25 | 600–960 nm | 380 | .tif | TIF image loader |
| HSODBIT v2 | hsodbitv2 | 200 | 400–1000 nm | 500 | .mat | HDF5 H5PY loader (requires corresponding color .jpg file) |
| HSSOD | hs_sod | 81 | 380–720 nm | 60 | .h5 | HDF5 H5PY loader (requires corresponding color .jpg file) |
| HyKo v2-NIR | hykov2nir | 25 | 600–975 nm | 78 | .mat | Mat loader |
| HyKo v2-VIS | hykov2vis | 16 | 470–630 nm | 163 | .mat | Mat loader |
| HyperBlood | hyperblood | 128 | 377–1046 nm | 14 | .mat | Custom Mat loader |
| HyperDrive-VNIR | hyperdrivevnir | 24 | 660–900 nm | 504 | .npz | NumPy archive (must contain cube.npy file inside) |
| HyperspectralCity v2 | hyperspectralcityv2 | 128 | 450–950 nm | 1330 | .hsd | HSD raw data loader |
| ICVL | icvl | 31 | 400–700 nm | 187 | .h5 | HDF5 H5PY loader |
| LIB-HSI | libhsi | 204 | 400–1000 nm | 393 | .hdr | ENVI header (requires corresponding raw binary data .raw/.dat file) |
| UM-EMM | umemm | 33 | 400–720 nm | 3 | .mat | Mat loader |
| UM-LD 2015 | umld2015 | 33 | 400–720 nm | 20 | .mat | Mat loader |
| UM-NS 2002 | umns2002 | 31 | 410–710 nm | 8 | .mat | Mat loader |
| UM-NS 2004 | umns2004 | 33 | 400–720 nm | 10 | .mat | Mat loader |
| UM-OS | umos | 33 | 400–720 nm | 50 | .mat | Mat loader |
| UM-RI 2015 | umri2015 | 33 | 400–720 nm | 33 | .mat | Mat loader |
| Virginia Tech Tree | virginia_tech_tree | 420 | 400–1000 nm | 51 | .hdr | ENVI header (requires corresponding raw binary data file) |
| Apple Fire Blight | vnihdhiatlimafb | 204 | 400–1000 nm | 420 | .hdr | ENVI header (requires corresponding raw binary data file) |
1@misc{fu2026hypervision,
2 title={HyperVision: A Channel-Adaptive Ground-Based Hyperspectral Vision Pre-trained Backbone},
3 author={Guanyiman Fu and Jingtao Li and Zihang Cheng and Zhuanfeng Li and Diqi Chen and Yan Xu and Xiangyu Liu and Fengchao Xiong and Jianfeng Lu and Chengrong Chen and Jun Zhou},
4 year={2026},
5 eprint={2605.17286},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV},
8 url={https://arxiv.org/abs/2605.17286},
9}