LSNet: See Large, Focus Small
Paper • 2503.23135 • Published • 11
模型名称:
Kaloscope Artist Style Classification Model
模型版本: v2.0
发布日期: 2025年11月
模型类型: 图像分类 (艺术家风格识别)
架构: LSNet (See Large, Focus Small)
本模型基于LSNet架构构建,专门用于识别和分类不同艺术家的绘画风格。LSNet是一个轻量级视觉模型,灵感来源于人类视觉系统的动态异尺度能力,即"看大局,聚焦细节"的特性。
| 指标 | 数值 |
|---|---|
| Top-1 准确率 | 90.13% |
| 总类别数 | 39,260 |
| 参数量 | ~183M |
| 训练时长 | 400+小时 (H20) |
| 输入分辨率 | 448×448 |
以下示例使用 Python 3.10+、PyTorch 2.6+。建议在 Linux 或 WSL2 中运行;上游 model/ska.py 在导入时依赖 Triton,不能只安装 torch torchvision timm。
先安装与本机 CUDA 环境匹配的 PyTorch 和 torchvision,再安装其余依赖:
python -m pip install "torch>=2.6" torchvision
python -m pip install "timm>=1.0" pillow huggingface_hub triton
git clone https://github.com/spawner1145/lsnet-test.git
cd lsnet-test
在上面的 lsnet-test 目录中运行以下代码,并将 example.jpg 替换为自己的图片路径。首次运行会从本仓库下载 checkpoint 和类别映射。
import argparse
import csv
import torch
from PIL import Image
from huggingface_hub import hf_hub_download
from timm.models import create_model
from timm.data import resolve_data_config
from timm.data.transforms_factory import create_transform
from model import lsnet_artist # 注册 lsnet_xl_artist_448
repo_id = "heathcliff01/Kaloscope2.0"
checkpoint_path = hf_hub_download(
repo_id=repo_id, filename="448-90.13/best_checkpoint.pth"
)
mapping_path = hf_hub_download(repo_id=repo_id, filename="class_mapping.csv")
with open(mapping_path, encoding="utf-8-sig", newline="") as f:
class_names = {
int(row["class_id"]): row["class_name"]
for row in csv.DictReader(f)
}
# 该训练 checkpoint 含有 argparse.Namespace,需要加入安全加载白名单。
# mmap=True 避免一次性将优化器等训练状态全部读入内存。
with torch.serialization.safe_globals([argparse.Namespace]):
checkpoint = torch.load(
checkpoint_path, map_location="cpu", weights_only=True, mmap=True
)
state_dict = checkpoint["model"]
num_classes, feature_dim = state_dict["head.l.weight"].shape
assert set(class_names) == set(range(num_classes)), "类别映射与分类头不匹配"
model = create_model(
"lsnet_xl_artist_448",
pretrained=False,
num_classes=num_classes,
feature_dim=feature_dim,
)
model.load_state_dict(state_dict, strict=True)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = model.to(device).eval()
del checkpoint, state_dict
# 使用模型配置的 448×448 输入、bicubic 插值、中心裁剪和 ImageNet 归一化。
data_config = resolve_data_config({"input_size": (3, 448, 448)}, model=model)
transform = create_transform(**data_config, is_training=False)
with Image.open("example.jpg") as image:
input_tensor = transform(image.convert("RGB")).unsqueeze(0).to(device)
with torch.inference_mode():
logits = model(input_tensor) # [1, num_classes]
probabilities = torch.softmax(logits, dim=1)
scores, indices = probabilities[0].topk(5)
for score, index in zip(scores.cpu().tolist(), indices.cpu().tolist()):
print(f"{class_names[index]}: {score:.2%}")
当前发布的 checkpoint 分类头尺寸为 **[39261, 2048]**,class_mapping.csv 也有 39,261 个类别(ID 为 0–39260)。示例从权重读取类别数与特征维度,避免使用模型定义默认的 50,000 类。输出的 softmax 分数表示模型在这些类别之间的相对预测概率,不代表对图片真实作者的鉴定。
安装comfyui节点:https://github.com/spawner1145/comfyui-lsnet 下载本仓库模型即可使用
@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},
}
免责声明: 本模型仅供研究和教育用途。在商业应用中使用时,请确保遵守相关法律法规和伦理准则。