Feature Extraction
Transformers
Safetensors
English
lessvit
hyperspectral
remote-sensing
geospatial
vision-transformer
custom_code
Instructions to use GFM-Bench/LESSViT-Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use GFM-Bench/LESSViT-Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="GFM-Bench/LESSViT-Base", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("GFM-Bench/LESSViT-Base", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download load_encoder.py from GFM-Bench/LESSViT-Base: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/GFM-Bench/LESSViT-Base/resolve/main/load_encoder.py
- Command line
-
hf download hf://GFM-Bench/LESSViT-Base/load_encoder.py
-
curl -L -o load_encoder.py https://huggingface.co/GFM-Bench/LESSViT-Base/resolve/main/load_encoder.py
1.8 kB
| """Load the released encoder and extract features from a synthetic HSI batch.""" | |
| import argparse | |
| import torch | |
| from transformers import AutoModel | |
| def load_encoder(model_id="GFM-Bench/LESSViT-Base", device="cpu", revision=None): | |
| model = AutoModel.from_pretrained( | |
| model_id, trust_remote_code=True, revision=revision, | |
| ) | |
| return model.to(device).eval() | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument('--model-id', default='GFM-Bench/LESSViT-Base', | |
| help='Hugging Face model ID or local snapshot directory') | |
| parser.add_argument('--revision', default=None, help='Optional commit SHA') | |
| parser.add_argument('--device', default='cpu') | |
| args = parser.parse_args() | |
| torch.set_num_threads(4) | |
| encoder = load_encoder(args.model_id, args.device, args.revision) | |
| # Synthetic values demonstrate tensor shapes, not preprocessing for real imagery. | |
| image = torch.randn(1, 10, 32, 32, device=args.device) | |
| wavelengths_nm = torch.linspace(450, 2300, 10, device=args.device)[None] | |
| # Example: fixed full-EnMAP wavelength bounds. Use the same reference bounds | |
| # for train/eval in your downstream pipeline; do not renormalize each subset. | |
| wavelengths = (wavelengths_nm - 418.24) / (2445.53 - 418.24) | |
| with torch.no_grad(): | |
| output = encoder(optical=image, optical_channel_wv=wavelengths, | |
| spatial_resolution=30) | |
| grid = output.last_hidden_state | |
| assert torch.isfinite(grid).all() | |
| print('Token grid:', tuple(grid.shape)) | |
| print('Global features:', tuple(grid[:, 0, 0].shape)) | |
| print('Spatial features:', tuple(grid[:, 0, 1:].shape)) | |
| print('Per-band patch features:', tuple(grid[:, 1:, 1:].shape)) | |
| if __name__ == '__main__': | |
| main() | |