Views
No views yet
AutoImageProcessor class from Hugging Face Transformers. This can be accomplished as follows:1from transformers import AutoImageProcessor
2
3preprocessor = AutoImageProcessor.from_pretrained(
4 'fomofo/tap-ct-s-2-5d',
5 trust_remote_code=True
6)1import torch
2from transformers import AutoModel
3
4# Load the model
5model = AutoModel.from_pretrained('fomofo/tap-ct-s-2-5d', trust_remote_code=True)
6
7# Prepare input (batch_size, channels, depth, height, width)
8x = torch.randn((16, 1, 6, 224, 224))
9
10# Forward pass
11with torch.no_grad():
12 output = model.forward(x)1import numpy as np
2import SimpleITK as sitk
3import torch
4from transformers import AutoModel, AutoImageProcessor
5
6# Load the model
7model = AutoModel.from_pretrained('fomofo/tap-ct-s-2-5d', trust_remote_code=True)
8preprocessor = AutoImageProcessor.from_pretrained('fomofo/tap-ct-s-2-5d', trust_remote_code=True)
9
10# Load image & set orientation to LPS
11volume = sitk.ReadImage('/path/to/ct-scan.nii.gz')
12volume = sitk.DICOMOrient(volume, 'LPS')
13
14# Get array, expand to (B, C, D, H, W) and preprocess
15array = sitk.GetArrayFromImage(volume)
16array = np.expand_dims(array, axis=(0, 1))
17x = preprocessor(array)['pixel_values']
18
19# Forward pass
20with torch.no_grad():
21 output = model.forward(x)
22
23# OR
24
25# Forward pass with sliding window
26from monai.inferers import SlidingWindowInferer
27
28def predictor_fn(x):
29 # Reshape the patch tokens to resemble a 3D feature map
30 out = model(x, reshape=True)
31 return out.last_hidden_state
32
33inferer = SlidingWindowInferer(
34 roi_size=[6, 224, 224],
35 sw_batch_size=1,
36 overlap=0.75,
37 mode='gaussian'
38)
39
40with torch.no_grad():
41 output = inferer(x, predictor_fn)BaseModelOutputWithPooling object from the transformers library. The output.pooler_output contains the pooled [CLS] token representation, while output.last_hidden_state contains the spatial patch token embeddings. To extract features from all intermediate transformer layers, pass output_hidden_states=True to the forward method.(batch_size, 1, depth, height, width)(16, 1, 6, 224, 224) - batch of 16 CT crops with 6 slices at 224×224 resolution1@article{veenboer2025tapct,
2 title={TAP-CT: 3D Task-Agnostic Pretraining of Computed Tomography Foundation Models},
3 author={Veenboer, Tim and Yiasemis, George and Marcus, Eric and Van Veldhuizen, Vivien and Snoek, Cees G. M. and Teuwen, Jonas and Groot Lipman, Kevin B. W.},
4 journal={arXiv preprint arXiv:2512.00872},
5 year={2025}
6}