HuggingFace Transformers version of RSBuilding Swin-Base model, converted from MMDetection/MMSegmentation format.
When loading this model, you may see messages about missing buffer keys (typically ~12 keys). This is expected and normal.
These missing keys are buffers that are computed dynamically during model initialization:
1from transformers import SwinModel, AutoImageProcessor
2from PIL import Image
3import torch
4
5# Load model and processor
6model = SwinModel.from_pretrained("BiliSakura/RSBuilding-Swin-B")
7processor = AutoImageProcessor.from_pretrained("BiliSakura/RSBuilding-Swin-B")
8
9# Load and process image
10image = Image.open("your_image.jpg")
11inputs = processor(image, return_tensors="pt")
12
13# Forward pass
14with torch.no_grad():
15 outputs = model(**inputs)
16
17# Get features
18# outputs.last_hidden_state: (batch_size, num_patches, hidden_size)
19# outputs.pooler_output: (batch_size, hidden_size) - pooled representation
20features = outputs.last_hidden_state
21pooled_features = outputs.pooler_output
22
23print(f"Feature shape: {features.shape}")
24print(f"Pooled feature shape: {pooled_features.shape}")
1from transformers import SwinModel, AutoImageProcessor
2import torch
3
4model = SwinModel.from_pretrained("BiliSakura/RSBuilding-Swin-B")
5processor = AutoImageProcessor.from_pretrained("BiliSakura/RSBuilding-Swin-B")
6
7# Process image
8image = Image.open("your_image.jpg")
9inputs = processor(image, return_tensors="pt")
10
11# Extract features
12with torch.no_grad():
13 outputs = model(**inputs)
14
15# Use pooled features for classification/regression
16features = outputs.pooler_output # Shape: (1, 1024)
17
18# Or use last hidden state for dense prediction tasks
19spatial_features = outputs.last_hidden_state # Shape: (1, num_patches, 1024)
1@article{wangRSBuildingGeneralRemote2024a,
2 title = {{{RSBuilding}}: {{Toward General Remote Sensing Image Building Extraction}} and {{Change Detection With Foundation Model}}},
3 shorttitle = {{{RSBuilding}}},
4 author = {Wang, Mingze and Su, Lili and Yan, Cilin and Xu, Sheng and Yuan, Pengcheng and Jiang, Xiaolong and Zhang, Baochang},
5 year = {2024},
6 journal = {IEEE Transactions on Geoscience and Remote Sensing},
7 volume = {62},
8 pages = {1--17},
9 issn = {1558-0644},
10 doi = {10.1109/TGRS.2024.3439395},
11 keywords = {Building extraction,Buildings,change detection (CD),Data mining,Feature extraction,federated training,foundation model,Image segmentation,Remote sensing,remote sensing images,Task analysis,Training}
12}