ascota_classification.decoration¶
The classification decoration module provides functionality for classifying
pottery decoration patterns into two main categories: impressed and incised.
Impressed decorations are created by pressing objects into the clay, while
incised decorations are made by cutting or carving into the clay surface.
The module uses a pre-trained DINOv2 ViT-L/14 model for feature extraction
combined with an optimized Linear Logistic Regression classifier, providing
accurate and reliable classification of pottery decoration patterns from
images with transparent backgrounds.
Decoration classification module for pottery images with transparent backgrounds.
This module classifies pottery decoration patterns into two categories: - Impressed: decorations made by pressing objects into the clay - Incised: decorations made by cutting/carving into the clay
The classification uses a pre-trained DINOv2 ViT-L/14 model with optimized logistic regression classifier.
_load_dino_model ¶
_load_dino_model(device)
Load the DINOv2 ViT-L/14 model for feature extraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
device
|
PyTorch device (cpu or cuda) |
required |
Returns:
| Type | Description |
|---|---|
AutoModel
|
Loaded DINOv2 model in eval mode |
Source code in src/ascota_classification/decoration.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
_extract_features ¶
_extract_features(image, model, device)
Extract DINO features from pottery image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
PIL Image with transparent background (RGBA) |
required |
model
|
AutoModel
|
Pre-loaded DINOv2 model |
required |
device
|
device
|
PyTorch device |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Feature vector as numpy array |
Source code in src/ascota_classification/decoration.py
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 86 87 88 | |
_load_classifier ¶
_load_classifier(model_path)
Load the trained logistic regression classifier and its parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path
|
Path
|
Path to the saved model file |
required |
Returns:
| Type | Description |
|---|---|
Tuple[any, Optional[Dict]]
|
Tuple of (classifier, parameters dict or None) |
Source code in src/ascota_classification/decoration.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
classify_pottery_decoration ¶
classify_pottery_decoration(image, model_path=None, return_confidence=False, debug=False)
Classify pottery decoration pattern from an image with transparent background.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
PIL Image with transparent background (RGBA or RGB format) |
required |
model_path
|
Optional[Path]
|
Path to trained model file. If None, uses default model path. |
None
|
return_confidence
|
bool
|
If True, include decision function scores in output |
False
|
debug
|
bool
|
If True, print debug information |
False
|
Returns:
| Type | Description |
|---|---|
Dict[str, any]
|
Dictionary containing: - "label": Classification result ("Impressed" or "Incised") - "method": "DINOv2 + Logistic Regression" - "confidence": (Optional) Decision function score if return_confidence=True - "model_params": (Optional) Model hyperparameters if available |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If model file is not found |
RuntimeError
|
If model loading or inference fails |
Examples:
>>> from PIL import Image
>>> img = Image.open("pottery_decoration.png")
>>> result = classify_pottery_decoration(img, debug=True)
>>> print(result["label"])
'Impressed'
>>> result = classify_pottery_decoration(img, return_confidence=True)
>>> print(f"Label: {result['label']}, Confidence: {result['confidence']:.4f}")
Label: Impressed, Confidence: 0.8532
Source code in src/ascota_classification/decoration.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
batch_classify_pottery_decoration ¶
batch_classify_pottery_decoration(images, model_path=None, return_confidence=False, debug=False)
Classify multiple pottery decoration images efficiently.
This function loads the models once and reuses them for all images, making it more efficient than calling classify_pottery_decoration repeatedly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
list[Image]
|
List of PIL Images with transparent backgrounds |
required |
model_path
|
Optional[Path]
|
Path to trained model file. If None, uses default model path. |
None
|
return_confidence
|
bool
|
If True, include confidence scores in output |
False
|
debug
|
bool
|
If True, print debug information |
False
|
Returns:
| Type | Description |
|---|---|
list[Dict[str, any]]
|
List of classification result dictionaries, one per image |
Examples:
>>> from PIL import Image
>>> images = [Image.open(f"pottery_{i}.png") for i in range(5)]
>>> results = batch_classify_pottery_decoration(images)
>>> for i, result in enumerate(results):
... print(f"Image {i}: {result['label']}")
Source code in src/ascota_classification/decoration.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |