Feature Extraction
timm
Safetensors
File size: 3,242 Bytes
60a4434
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
tags:
- timm
- feature-extraction
library_name: timm
license: apache-2.0
pipeline_tag: feature-extraction
---

# Model card for vit_base_patch16_224.endofm

Endo-FM: a Vision Transformer (ViT-B/16) foundation model for endoscopy video analysis, self-supervised pre-trained by the authors on 33K+ surgical video clips (up to 5M frames) from 9 endoscopy datasets (MICCAI 2023).

This repo ports the released pre-trained Endo-FM encoder (the spatial ViT-B/16 backbone of the video transformer) to timm, for use as an image/video-frame feature extractor.

![](https://raw.githubusercontent.com/med-air/Endo-FM/main/assets/framework.png)

## Model Details

- **Model Type:** Feature backbone (Vision Transformer, encoder-only, num_classes=0)
- **Developed by**: Med-AIR, CUHK (Zhao Wang, Chang Liu, Shaoting Zhang, Qi Dou)
- **Model Stats:**
  - Params: 85.8M (ViT-Base)
  - Image size: 224 x 224 x 3
  - Patch size: 16 x 16 x 3
- **Pre-training:**
  - Dataset: 33K+ endoscopy video clips (6 public + 1 private), up to 5M frames
  - Framework: self-supervised pre-training (DINO-style self-distillation with global/local views) on a divided space-time video transformer (TimeSformer, 8 frames @ 224x224); the released teacher backbone is ported here as a spatial image encoder
- **Papers:**
  - [Foundation Model for Endoscopy Video Analysis via Large-scale Self-supervised Pre-train](https://arxiv.org/abs/2306.16741) (MICCAI 2023)
- **Original:** https://github.com/med-air/Endo-FM (checkpoint: Google Drive file 1H7B91Ewm4QkZRsnUk1Bn0IQch5P8C7Xl, endo_fm.pth, teacher backbone)
- **License:** [Apache-2.0](https://github.com/med-air/Endo-FM/blob/main/LICENSE)

## Model Usage

### Image Embeddings
```python
from urllib.request import urlopen
from PIL import Image
import timm

# get example image
img = Image.open(
  urlopen(
    "https://raw.githubusercontent.com/med-air/Endo-FM/main/assets/dataset_visualization.png"
  )
)

# load model from the hub
model = timm.create_model(
  model_name="hf-hub:1aurent/vit_base_patch16_224.endofm",
  pretrained=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)

data = transforms(img).unsqueeze(0) # input is a (batch_size, num_channels, img_size, img_size) shaped tensor
output = model(data)  # output is a (batch_size, num_features) shaped tensor
```

## Citation
```bibtex
@inproceedings{wang2023foundation,
    title={Foundation Model for Endoscopy Video Analysis via Large-scale Self-supervised Pre-train},
    author={Zhao Wang and Chang Liu and Shaoting Zhang and Qi Dou},
    booktitle={International Conference on Medical Image Computing and Computer-Assisted Intervention},
    pages={101--111},
    year={2023},
    organization={Springer},
    doi={10.1007/978-3-031-43996-4_10}
}

@article{wang2023arxiv,
    title={Foundation Model for Endoscopy Video Analysis via Large-scale Self-supervised Pre-train},
    author={Zhao Wang and Chang Liu and Shaoting Zhang and Qi Dou},
    journal={arXiv preprint arXiv:2306.16741},
    year={2023},
    eprint={2306.16741},
    archivePrefix={arXiv},
    doi={10.48550/arXiv.2306.16741}
}
```