Update README.md
Browse files
README.md
CHANGED
|
@@ -12,4 +12,90 @@ base_model:
|
|
| 12 |
pipeline_tag: image-classification
|
| 13 |
tags:
|
| 14 |
- geotechnics
|
| 15 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
pipeline_tag: image-classification
|
| 13 |
tags:
|
| 14 |
- geotechnics
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# 🪨 Core Sample Secondary Fraction Classifier
|
| 18 |
+
|
| 19 |
+
This multi-label classification model was fine-tuned for automated visual analysis of soil core samples, and trained / validated / tested on the `grano1/core_sample_image_data` dataset available via the HuggingFace eco-system. The model aims to predict one of the following nine class labels - termed in accordance with DIN 4023 - from cropped core sample images (300x300 pixels):
|
| 20 |
+
- very gravelly | gravelly (g* | g)
|
| 21 |
+
- very sandy | sandy (s* | s)
|
| 22 |
+
- very silty | silty (u* | u)
|
| 23 |
+
- very clayey | clayey (t* | t)
|
| 24 |
+
- stony (x)
|
| 25 |
+
|
| 26 |
+
## 📊 Metrics
|
| 27 |
+
|
| 28 |
+
The following table summarizes selected metrics quantifying the model performance on the test set:
|
| 29 |
+
|
| 30 |
+
| 📈 Metric | Value |
|
| 31 |
+
|------------------------------------|--------|
|
| 32 |
+
| Binary Cross-Entropy Loss | 0.1146 |
|
| 33 |
+
| Subset Accuracy | 0.7606 |
|
| 34 |
+
| F1-score (macro, aggregated) | 0.7734 |
|
| 35 |
+
| F1-score (weighted, aggregated) | 0.8124 |
|
| 36 |
+
| Hamming Loss | 0.0363 |
|
| 37 |
+
|
| 38 |
+
## ⚙️ Hyperparameters
|
| 39 |
+
|
| 40 |
+
The following table summarizes selected hyperparameters used for training the model:
|
| 41 |
+
|
| 42 |
+
| Metric | Value |
|
| 43 |
+
|---------------------------|----------|
|
| 44 |
+
| Batch size | 16 |
|
| 45 |
+
| Optimizer | AdamW |
|
| 46 |
+
| Warm-up ratio | 0.1 |
|
| 47 |
+
| Metric for best model | Bin. CE |
|
| 48 |
+
| Early stopping patience | 3 |
|
| 49 |
+
| Threshold | 0.3 |
|
| 50 |
+
|
| 51 |
+
## 🚀 Usage
|
| 52 |
+
|
| 53 |
+
```python
|
| 54 |
+
# Load the dataset
|
| 55 |
+
data_dataset = load_dataset("grano1/core_sample_image_data")
|
| 56 |
+
|
| 57 |
+
# Load image processor and model
|
| 58 |
+
processor = AutoImageProcessor.from_pretrained("grano1/core_sample_image_secondary_fraction_model")
|
| 59 |
+
model = AutoModelForImageClassification.from_pretrained("grano1/core_sample_image_secondary_fraction_model")
|
| 60 |
+
model.eval() # Set model to evaluation mode
|
| 61 |
+
|
| 62 |
+
# Show sample features
|
| 63 |
+
data_dataset["test"].features
|
| 64 |
+
|
| 65 |
+
# Select sample from test set
|
| 66 |
+
split = "test"
|
| 67 |
+
sample = data_dataset[split][5] # Pick one sample
|
| 68 |
+
image = sample["image"]
|
| 69 |
+
|
| 70 |
+
# Prepare input for model
|
| 71 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 72 |
+
|
| 73 |
+
# Run inference
|
| 74 |
+
with torch.no_grad():
|
| 75 |
+
outputs = model(**inputs)
|
| 76 |
+
logits = outputs.logits
|
| 77 |
+
predicted_class = logits.argmax(dim=1).item()
|
| 78 |
+
print(sample)
|
| 79 |
+
|
| 80 |
+
# Get predicted and true label name
|
| 81 |
+
id2label = model.config.id2label
|
| 82 |
+
label2id = model.config.label2id
|
| 83 |
+
predicted_label_name = id2label[predicted_class]
|
| 84 |
+
|
| 85 |
+
# Show result
|
| 86 |
+
print(f"✅ Predicted label: {predicted_label_name}")
|
| 87 |
+
print(f"🧾 True label: {sample['NB']}")
|
| 88 |
+
|
| 89 |
+
# Display image
|
| 90 |
+
plt.imshow(sample['image'])
|
| 91 |
+
plt.axis('off') # Hide axes
|
| 92 |
+
plt.show()
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
## 🔒 Limitations
|
| 96 |
+
The `grano1/core_sample_image_data` dataset includes more `NB` labels than the nine identified by this model. This may require data cleansing procedures, e.g., s' (slightly sandy) label has been removed. Instructions can be found in the citation documented below.
|
| 97 |
+
|
| 98 |
+
## ✨ Citation
|
| 99 |
+
If you use this model, please cite:
|
| 100 |
+
|
| 101 |
+
@thesis{Granitzer2025, author = {Andreas-Nizar Granitzer}, title = {Data-centric core sample classification and constitutive model selection in geotechnics}, school = {University of Applied Sciences Kufstein}, year = {2025}, type = {Master's thesis} }
|