lsnet_b / README.md
nielsr's picture
nielsr HF Staff
Add pipeline tag and usage example, remove library_tag
f22b5b0 verified
|
raw
history blame
1.55 kB
metadata
library_name: timm
license: mit
tags:
  - image-classification
  - timm

LSNet: See Large, Focus Small

Paper: https://arxiv.org/abs/2503.23135

Code: https://github.com/THU-MIG/lsnet

Usage

import timm
import torch
from PIL import Image
import requests
from timm.data import resolve_data_config, create_transform

# Load the model
model = timm.create_model(
    'hf_hub:jameslahm/lsnet_b',
    pretrained=True
)
model.eval()

# Load and transform image
# Example using a URL:
url = 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
img = Image.open(requests.get(url, stream=True).raw)

config = resolve_data_config({}, model=model)
transform = create_transform(**config)
input_tensor = transform(img).unsqueeze(0) # transform and add batch dimension

# Make prediction
with torch.no_grad():
    output = model(input_tensor)
probabilities = torch.nn.functional.softmax(output[0], dim=0)

# Get top 5 predictions
top5_prob, top5_catid = torch.topk(probabilities, 5)
# Assuming you have imagenet labels list 'imagenet_labels'
# for i in range(top5_prob.size(0)):
#     print(imagenet_labels[top5_catid[i]], top5_prob[i].item())

Citation

@misc{wang2025lsnetlargefocussmall,
      title={LSNet: See Large, Focus Small}, 
      author={Ao Wang and Hui Chen and Zijia Lin and Jungong Han and Guiguang Ding},
      year={2025},
      eprint={2503.23135},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2503.23135}, 
}