Image Feature Extraction
Transformers
Safetensors
dinov2
thermal-imaging
computer-vision
knowledge-distillation
robotics
multi-modal
Instructions to use theairlabcmu/AnyThermal with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use theairlabcmu/AnyThermal with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-feature-extraction", model="theairlabcmu/AnyThermal")# Load model directly from transformers import AutoImageProcessor, AutoModel processor = AutoImageProcessor.from_pretrained("theairlabcmu/AnyThermal") model = AutoModel.from_pretrained("theairlabcmu/AnyThermal", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README
#1
by airlabshare - opened
- README.md +17 -13
- anythermal_checkpoints.zip +2 -2
- custom_processor.py +0 -48
- depth/config.json +27 -0
- depth/pytorch_model.bin +3 -0
- preprocessor_config.json +6 -20
- segmentation_cart/config.json +27 -0
- segmentation_cart/preprocessor_config.json +9 -0
- segmentation_cart/pytorch_model.bin +3 -0
- segmentation_mfnet/config.json +27 -0
- segmentation_mfnet/preprocessor_config.json +9 -0
- segmentation_mfnet/pytorch_model.bin +3 -0
- vpr/config.json +29 -0
- vpr/pytorch_model.bin +3 -0
README.md
CHANGED
|
@@ -90,25 +90,29 @@ We are exploring more tasks where the backbone can be leveragead are are looing
|
|
| 90 |
### Basic Feature Extraction
|
| 91 |
|
| 92 |
```python
|
| 93 |
-
import torch
|
| 94 |
from transformers import AutoImageProcessor, AutoModel
|
|
|
|
| 95 |
from PIL import Image
|
| 96 |
|
| 97 |
-
# Load
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
-
#
|
| 103 |
-
|
|
|
|
| 104 |
|
| 105 |
-
#
|
| 106 |
-
|
| 107 |
-
inputs = processor(images=image, return_tensors="pt")
|
| 108 |
|
| 109 |
-
#
|
| 110 |
-
|
| 111 |
-
outputs = model(**inputs)
|
| 112 |
```
|
| 113 |
|
| 114 |
### Task-Specific Applications
|
|
|
|
| 90 |
### Basic Feature Extraction
|
| 91 |
|
| 92 |
```python
|
|
|
|
| 93 |
from transformers import AutoImageProcessor, AutoModel
|
| 94 |
+
import torch
|
| 95 |
from PIL import Image
|
| 96 |
|
| 97 |
+
# Load model and processor
|
| 98 |
+
processor = AutoImageProcessor.from_pretrained("theairlabcmu/AnyThermal")
|
| 99 |
+
model = AutoModel.from_pretrained("theairlabcmu/AnyThermal")
|
| 100 |
+
|
| 101 |
+
# Load thermal image (grayscale)
|
| 102 |
+
thermal_image = Image.open("path/to/thermal_image.png").convert("L")
|
| 103 |
+
|
| 104 |
+
# Convert to 3-channel (required for ViT architecture)
|
| 105 |
+
thermal_image = thermal_image.convert("RGB")
|
| 106 |
|
| 107 |
+
# Process and extract features
|
| 108 |
+
inputs = processor(images=thermal_image, return_tensors="pt")
|
| 109 |
+
outputs = model(**inputs)
|
| 110 |
|
| 111 |
+
# Get CLS token (global image representation)
|
| 112 |
+
cls_features = outputs.last_hidden_state[:, 0] # Shape: [1, 768]
|
|
|
|
| 113 |
|
| 114 |
+
# Get patch features (spatial feature map)
|
| 115 |
+
patch_features = outputs.last_hidden_state[:, 1:] # Shape: [1, num_patches, 768]
|
|
|
|
| 116 |
```
|
| 117 |
|
| 118 |
### Task-Specific Applications
|
anythermal_checkpoints.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cd4574987e56f58d0c6993987ddf9c4b72dd21f3786db3facab5914762aab4ef
|
| 3 |
+
size 2498757381
|
custom_processor.py
DELETED
|
@@ -1,48 +0,0 @@
|
|
| 1 |
-
from transformers import BitImageProcessor as BaseProcessor
|
| 2 |
-
import numpy as np
|
| 3 |
-
|
| 4 |
-
from transformers import AutoImageProcessor
|
| 5 |
-
from transformers.image_utils import PILImageResampling
|
| 6 |
-
|
| 7 |
-
class CustomDinov2Processor(BaseProcessor):
|
| 8 |
-
model_type = "dinov2"
|
| 9 |
-
|
| 10 |
-
def preprocess(self, images, **kwargs):
|
| 11 |
-
# 1. Handle "Already Normalized" (0-1) check
|
| 12 |
-
test_img = images[0] if isinstance(images, list) else images
|
| 13 |
-
|
| 14 |
-
# Determine max value to see if we should rescale
|
| 15 |
-
if hasattr(test_img, "getextrema"): # PIL
|
| 16 |
-
extrema = test_img.getextrema()
|
| 17 |
-
max_val = max([b[1] for b in extrema]) if isinstance(extrema[0], tuple) else extrema[1]
|
| 18 |
-
elif hasattr(test_img, "max"): # Numpy/Tensor
|
| 19 |
-
max_val = test_img.max()
|
| 20 |
-
else:
|
| 21 |
-
max_val = 255
|
| 22 |
-
|
| 23 |
-
# If already 0-1, disable rescaling (1/255)
|
| 24 |
-
if max_val <= 1.0:
|
| 25 |
-
kwargs["do_rescale"] = False
|
| 26 |
-
else:
|
| 27 |
-
kwargs["do_rescale"] = True
|
| 28 |
-
|
| 29 |
-
# 2. Force RGB Conversion (handles grayscale)
|
| 30 |
-
kwargs["do_convert_rgb"] = True
|
| 31 |
-
|
| 32 |
-
return super().preprocess(images, **kwargs)
|
| 33 |
-
|
| 34 |
-
def resize(self, image: np.ndarray, size=None, resample=PILImageResampling.BILINEAR, **kwargs) -> np.ndarray:
|
| 35 |
-
# 3. Your dynamic "nearest 14" logic
|
| 36 |
-
h, w = image.shape[:2]
|
| 37 |
-
new_h = (h // 14) * 14
|
| 38 |
-
new_w = (w // 14) * 14
|
| 39 |
-
|
| 40 |
-
return super().resize(
|
| 41 |
-
image,
|
| 42 |
-
size={"height": new_h, "width": new_w},
|
| 43 |
-
resample=resample,
|
| 44 |
-
**kwargs
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
-
# Register the class so it saves to the Hub correctly
|
| 48 |
-
CustomDinov2Processor.register_for_auto_class("AutoImageProcessor")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
depth/config.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"AnyThermalDepthModel"
|
| 4 |
+
],
|
| 5 |
+
"model_type": "anythermal_depth",
|
| 6 |
+
"auto_map": {
|
| 7 |
+
"AutoConfig": "model.AnyThermalDepthConfig",
|
| 8 |
+
"AutoModel": "model.AnyThermalDepthModel"
|
| 9 |
+
},
|
| 10 |
+
"hidden_size": 768,
|
| 11 |
+
"num_hidden_layers": 12,
|
| 12 |
+
"num_attention_heads": 12,
|
| 13 |
+
"mlp_ratio": 4,
|
| 14 |
+
"hidden_act": "gelu",
|
| 15 |
+
"dropout": 0.0,
|
| 16 |
+
"attention_dropout": 0.0,
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"layer_norm_eps": 1e-06,
|
| 19 |
+
"image_size": 518,
|
| 20 |
+
"patch_size": 14,
|
| 21 |
+
"num_channels": 3,
|
| 22 |
+
"qkv_bias": true,
|
| 23 |
+
"layerscale_value": 1.0,
|
| 24 |
+
"drop_path_rate": 0.0,
|
| 25 |
+
"use_swiglu_ffn": false,
|
| 26 |
+
"features": 256
|
| 27 |
+
}
|
depth/pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1d45f5b9c90e4243a85c80dda747b28efcef527195dc5eceea21bd93dd56d269
|
| 3 |
+
size 425617642
|
preprocessor_config.json
CHANGED
|
@@ -1,30 +1,16 @@
|
|
| 1 |
{
|
| 2 |
-
"crop_size": {
|
| 3 |
-
"height": 224,
|
| 4 |
-
"width": 224
|
| 5 |
-
},
|
| 6 |
"do_center_crop": false,
|
| 7 |
"do_convert_rgb": true,
|
| 8 |
"do_normalize": true,
|
| 9 |
"do_rescale": true,
|
| 10 |
"do_resize": true,
|
| 11 |
-
"image_mean": [
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
],
|
| 16 |
-
"image_processor_type": "CustomDinov2Processor",
|
| 17 |
-
"image_std": [
|
| 18 |
-
0.26862954,
|
| 19 |
-
0.26130258,
|
| 20 |
-
0.27577711
|
| 21 |
-
],
|
| 22 |
-
"resample": 2,
|
| 23 |
"rescale_factor": 0.00392156862745098,
|
| 24 |
"size": {
|
| 25 |
-
"
|
| 26 |
-
|
| 27 |
-
"auto_map": {
|
| 28 |
-
"AutoImageProcessor": "custom_processor.CustomDinov2Processor"
|
| 29 |
}
|
| 30 |
}
|
|
|
|
| 1 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
"do_center_crop": false,
|
| 3 |
"do_convert_rgb": true,
|
| 4 |
"do_normalize": true,
|
| 5 |
"do_rescale": true,
|
| 6 |
"do_resize": true,
|
| 7 |
+
"image_mean": [0.48145466, 0.4578275, 0.40821073],
|
| 8 |
+
"image_std": [0.26862954, 0.26130258, 0.27577711],
|
| 9 |
+
"image_processor_type": "BitImageProcessor",
|
| 10 |
+
"resample": 3,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
"rescale_factor": 0.00392156862745098,
|
| 12 |
"size": {
|
| 13 |
+
"height": 224,
|
| 14 |
+
"width": 224
|
|
|
|
|
|
|
| 15 |
}
|
| 16 |
}
|
segmentation_cart/config.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"AnyThermalSegmentationModel"
|
| 4 |
+
],
|
| 5 |
+
"model_type": "anythermal",
|
| 6 |
+
"auto_map": {
|
| 7 |
+
"AutoConfig": "model.AnyThermalConfig",
|
| 8 |
+
"AutoModel": "model.AnyThermalSegmentationModel"
|
| 9 |
+
},
|
| 10 |
+
"hidden_size": 768,
|
| 11 |
+
"num_hidden_layers": 12,
|
| 12 |
+
"num_attention_heads": 12,
|
| 13 |
+
"mlp_ratio": 4,
|
| 14 |
+
"hidden_act": "gelu",
|
| 15 |
+
"dropout": 0.0,
|
| 16 |
+
"attention_dropout": 0.0,
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"layer_norm_eps": 1e-06,
|
| 19 |
+
"image_size": 518,
|
| 20 |
+
"patch_size": 14,
|
| 21 |
+
"num_channels": 3,
|
| 22 |
+
"qkv_bias": true,
|
| 23 |
+
"layerscale_value": 1.0,
|
| 24 |
+
"drop_path_rate": 0.0,
|
| 25 |
+
"use_swiglu_ffn": false,
|
| 26 |
+
"num_labels": 10
|
| 27 |
+
}
|
segmentation_cart/preprocessor_config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"do_center_crop": false,
|
| 3 |
+
"do_convert_rgb": true,
|
| 4 |
+
"do_normalize": false,
|
| 5 |
+
"do_rescale": true,
|
| 6 |
+
"do_resize": false,
|
| 7 |
+
"image_processor_type": "BitImageProcessor",
|
| 8 |
+
"rescale_factor": 0.00392156862745098
|
| 9 |
+
}
|
segmentation_cart/pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:28f828818cdbb6dde254df59ee6b221d3f91875766c621bd5206d4f82e75bdf6
|
| 3 |
+
size 348159849
|
segmentation_mfnet/config.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"AnyThermalSegmentationModel"
|
| 4 |
+
],
|
| 5 |
+
"model_type": "anythermal",
|
| 6 |
+
"auto_map": {
|
| 7 |
+
"AutoConfig": "model.AnyThermalConfig",
|
| 8 |
+
"AutoModel": "model.AnyThermalSegmentationModel"
|
| 9 |
+
},
|
| 10 |
+
"hidden_size": 768,
|
| 11 |
+
"num_hidden_layers": 12,
|
| 12 |
+
"num_attention_heads": 12,
|
| 13 |
+
"mlp_ratio": 4,
|
| 14 |
+
"hidden_act": "gelu",
|
| 15 |
+
"dropout": 0.0,
|
| 16 |
+
"attention_dropout": 0.0,
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"layer_norm_eps": 1e-06,
|
| 19 |
+
"image_size": 518,
|
| 20 |
+
"patch_size": 14,
|
| 21 |
+
"num_channels": 3,
|
| 22 |
+
"qkv_bias": true,
|
| 23 |
+
"layerscale_value": 1.0,
|
| 24 |
+
"drop_path_rate": 0.0,
|
| 25 |
+
"use_swiglu_ffn": false,
|
| 26 |
+
"num_labels": 9
|
| 27 |
+
}
|
segmentation_mfnet/preprocessor_config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"do_center_crop": false,
|
| 3 |
+
"do_convert_rgb": true,
|
| 4 |
+
"do_normalize": false,
|
| 5 |
+
"do_rescale": true,
|
| 6 |
+
"do_resize": false,
|
| 7 |
+
"image_processor_type": "BitImageProcessor",
|
| 8 |
+
"rescale_factor": 0.00392156862745098
|
| 9 |
+
}
|
segmentation_mfnet/pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0841214f4ac2b7b31405037593c79960ae2b10ed4cece3c93953c3c4560b26ec
|
| 3 |
+
size 348159776
|
vpr/config.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"AnyThermalVPRModel"
|
| 4 |
+
],
|
| 5 |
+
"model_type": "anythermal_vpr",
|
| 6 |
+
"auto_map": {
|
| 7 |
+
"AutoConfig": "model.AnyThermalVPRConfig",
|
| 8 |
+
"AutoModel": "model.AnyThermalVPRModel"
|
| 9 |
+
},
|
| 10 |
+
"hidden_size": 768,
|
| 11 |
+
"num_hidden_layers": 12,
|
| 12 |
+
"num_attention_heads": 12,
|
| 13 |
+
"mlp_ratio": 4,
|
| 14 |
+
"hidden_act": "gelu",
|
| 15 |
+
"dropout": 0.0,
|
| 16 |
+
"attention_dropout": 0.0,
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"layer_norm_eps": 1e-06,
|
| 19 |
+
"image_size": 518,
|
| 20 |
+
"patch_size": 14,
|
| 21 |
+
"num_channels": 3,
|
| 22 |
+
"qkv_bias": true,
|
| 23 |
+
"layerscale_value": 1.0,
|
| 24 |
+
"drop_path_rate": 0.0,
|
| 25 |
+
"use_swiglu_ffn": false,
|
| 26 |
+
"num_clusters": 64,
|
| 27 |
+
"cluster_dim": 128,
|
| 28 |
+
"token_dim": 256
|
| 29 |
+
}
|
vpr/pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:41f4aa7b27bae7e4ff6331b27222c703845933bf668f312a3578eeb82fcdaa25
|
| 3 |
+
size 352035578
|