This is the official implementation of ICLR paper Designing BERT for Convolutional Networks: Sparse and Hierarchical Masked Modeling, which can pretrain any CNN (e.g., ResNet) in a BERT-style self-supervised manner.
We’ve tried our best to make the codebase clean, short, easy to read, state-of-the-art, and only rely on minimal dependencies.
https://user-images.githubusercontent.com/39692511/226858919-dd4ccf7e-a5ba-4a33-ab21-4785b8a7833c.mp4
🔥 News
🕹️ Colab Visualization Demo
Check pretrain/viz_reconstruction.ipynb for visualizing the reconstruction of SparK pretrained models, like:
We also provide pretrain/viz_spconv.ipynb that shows the “mask pattern vanishing” issue of dense conv layers.
What’s new here?
🔥 After SparK pretraining, smaller models can beat un-pretrained larger models:
🔥 All models can benefit, showing a scaling behavior:
🔥 Generative self-supervised pretraining surpasses contrastive learning:
See our paper for more analysis, discussions, and evaluations.
Todo list
catalog
Pretrained weights (self-supervised; w/o decoder; can be directly finetuned)
Note: for network definitions, we directly use timm.models.ResNet and official ConvNeXt.
reso.: the image resolution; acc@1: ImageNet-1K finetuned acc (top-1)
Pretrained weights (with SparK's UNet-style decoder; can be used to reconstruct images)
Installation & Running
We highly recommended you to use torch==1.10.0, torchvision==0.11.1, and timm==0.5.4 for reproduction.
Check INSTALL.md to install all pip dependencies.
- Loading pretrained model weights in 3 lines
# download our weights `resnet50_1kpretrained_timm_style.pth` first
import torch, timm
res50, state = timm.create_model('resnet50'), torch.load('resnet50_1kpretrained_timm_style.pth', 'cpu')
res50.load_state_dict(state.get('module', state), strict=False) # just in case the model weights are actually saved in state['module']
Acknowledgement
We referred to these useful codebases:
License
This project is under the MIT license. See LICENSE for more details.
Citation
If you found this project useful, you can kindly give us a star ⭐, or cite us in your work 📖:
@Article{tian2023designing,
author = {Keyu Tian and Yi Jiang and Qishuai Diao and Chen Lin and Liwei Wang and Zehuan Yuan},
title = {Designing BERT for Convolutional Networks: Sparse and Hierarchical Masked Modeling},
journal = {arXiv:2301.03580},
year = {2023},
}
评论