LSNet: See Large, Focus Small
Paper: https://arxiv.org/abs/2503.23135
Code: https://github.com/jameslahm/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
If our code or models help your work, please cite our paper:
@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},
}
LSNet: See Large, Focus Small
Official PyTorch implementation of LSNet. CVPR 2025.
LSNet: See Large, Focus Small.
Ao Wang, Hui Chen, Zijia Lin, Jungong Han, and Guiguang Ding
We introduce LSNet, a new family of lightweight vision models inspired by dynamic heteroscale capability of the human visual system, i.e., "See Large, Focus Small". LSNet achieves state-of-the-art performance and efficiency trade-offs across various vision tasks.
Classification on ImageNet-1K
Models
- * denotes the results with distillation.
- The throughput is tested on a Nvidia RTX3090 using speed.py.
| Model | Top-1 | Params | FLOPs | Throughput | Ckpt | Log |
|---|---|---|---|---|---|---|
| LSNet-T | 74.9 / 76.1* | 11.4M | 0.3G | 14708 | T / T* | T / T* |
| LSNet-S | 77.8 / 79.0* | 16.1M | 0.5G | 9023 | S / S* | S / S* |
| LSNet-B | 80.3 / 81.6* | 23.2M | 1.3G | 3996 | B / B* | B / B* |
ImageNet
Prerequisites
conda virtual environment is recommended.
conda create -n lsnet python=3.8
pip install -r requirements.txt
Data preparation
Download and extract ImageNet train and val images from http://image-net.org/. The training and validation data are expected to be in the train folder and val folder respectively:
|-- /path/to/imagenet/
|-- train
|-- val
Training
To train LSNet-T on an 8-GPU machine:
python -m torch.distributed.launch --nproc_per_node=8 --master_port 12345 --use_env main.py --model lsnet_t --data-path ~/imagenet --dist-eval
# For training with distillation, please add `--distillation-type hard`
# For LSNet-B, please add `--weight-decay 0.05`
Testing
python main.py --eval --model lsnet_t --resume ./pretrain/lsnet_t.pth --data-path ~/imagenet
Models can also be automatically downloaded from 🤗 like below.
import timm
model = timm.create_model(
f'hf_hub:jameslahm/lsnet_{t/t_distill/s/s_distill/b/b_distill}',
pretrained=True
)
Downstream Tasks
Object Detection and Instance Segmentation Semantic Segmentation Robustness Evaluation
Acknowledgement
Classification (ImageNet) code base is partly built with EfficientViT, LeViT, PoolFormer and EfficientFormer.
The detection and segmentation pipeline is from MMCV (MMDetection and MMSegmentation).
Thanks for the great implementations!