1aurent's picture
Add CervixFM ViT-Large/16 (timm re-upload of official checkpoint, bit-identical 342/342; parity 0.0 @224-512)
4539d79
|
Raw History Blame Contribute Delete
3.03 kB
---
tags:
- timm
- feature-extraction
- image-classification
- biology
- cytology
- cervix
library_name: timm
license: mit
---
# Model card for vit_large_patch16_224.cervixfm
![](https://raw.githubusercontent.com/yehua201826/CervixFM/main/asset/Fig_1.png)
## Model Details
- **Model Type:** Feature backbone (DINOv2-style ViT-Large/16, self-supervised)
- **Model Stats:**
- Params: 304M (large)
- Image size: 224 x 224 x 3
- Patch size: 16 x 16 x 3
- Registers: 0
- **Paper:** [CervixFM: A General Foundation Model for Cervical Cytology Image Analysis](https://doi.org/10.21203/rs.3.rs-8629620/v1) (Research Square preprint, submitted to Nature Communications)
- **Repository:** [github.com:yehua201826/CervixFM](https://github.com/yehua201826/CervixFM)
- **Original Weights:** [CervixFM.pth (Google Drive)](https://drive.google.com/file/d/1fvAy0-ovoD4WCg8423HWUv8H-P2fdr5l/view?usp=drive_link) (1.13 GiB, from the repo README)
This repo is a timm-format re-upload of the official checkpoint: key remap is 1:1 (chunked `blocks.{c}.{g}` -> `blocks.{g}`, SwiGLU `w12/w3` -> `fc1/fc2`, training-only `mask_token` dropped). Verified **bit-identical: 342/342 tensors** (sha256) and layer-by-layer activation parity vs the original checkpoint at input sizes 224/256/320/384/512 (max diff 0.0, cosine 1.0).
## Model Usage
### Image Embeddings
```python
from PIL import Image
import torch
import timm
# load model from the hub
import torch.nn as nn
from timm.layers import SwiGLUPacked
model = timm.create_model(
model_name="hf-hub:1aurent/vit_large_patch16_224.cervixfm",
pretrained=True,
mlp_layer=SwiGLUPacked, # SwiGLU-fused FFN (w12/w3), as in the original DINOv2-style arch
mlp_ratio=5.34375, # 1024 -> packed hidden 5472 (2 x 2736)
act_layer=nn.SiLU,
init_values=1e-5, # LayerScale
num_classes=0,
dynamic_img_size=True,
).eval()
# get model specific transforms (normalization, resize)
data_config = timm.data.resolve_model_data_config(model)
transforms = timm.data.create_transform(**data_config, is_training=False)
img = Image.open(...).convert("RGB")
data = transforms(img).unsqueeze(0) # (batch, 3, 224, 224)
output = model(data) # (batch, 1024) — LayerNorm(cls_token)
```
Upstream preprocessing (patch level) is exactly `convert("RGB")` -> `ToTensor()` -> `Normalize(mean=[0.485,0.456,0.406], std=[0.229,0.224,0.225])` at native 224x224 (no resize/crop). WSI level: 256x256 tiles, stride 128, bilinear-resized to 224x224, then the same normalize; slide feature = max-pool over patch CLS tokens.
## Citation
```bibtex
@article{cheng2026cervixfm,
title = {CervixFM: A General Foundation Model for Cervical Cytology Image Analysis},
author = {Cheng, Shenghua and Ye, Hua and Liu, Shijie and Pei, Lanjie and Bai, Jiaxin and Lu, Qiqi and Hu, Junbo and Chen, Li and Cai, Jing and Feng, Xi and Xiao, Yuwei and Zeng, Shaoqun and Liu, Xiuli},
year = {2026},
doi = {10.21203/rs.3.rs-8629620/v1},
url = {https://doi.org/10.21203/rs.3.rs-8629620/v1}
}
```