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
File size: 1,797 Bytes
586325c bbb9d1f 586325c bbb9d1f 586325c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | """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()
|