This project implements a Few-Shot Learning (FSL) pipeline for microscopic wood species classification, designed to mimic the low-sample, high-class-imbalance conditions found in archaeological charcoal identification tasks.
The work is inspired by the AI-WOOD project goals and demonstrates how meta-learning techniques can be used to train a classifier that generalizes to unseen wood species with only a few labeled examples.
The complete implementation is based on PyTorch and supports:
- Configurable Few-Shot parameters (
N-way,K-shot,Q-query) - Episodic training setup
- OneCycle learning rate policy for faster convergence
- Detailed metrics tracking (accuracy, precision, F1-score)
- Visualization of confusion matrices for interpretability
We use the Forest Species Database (FSD) — a publicly available dataset containing microscopic images of various wood species.
Dataset details:
- Total images: 2,240
- Number of species: 112
- Images per species: 20
- Image type: Microscopic cross-sections
This dataset closely resembles the microscopy context described for ancient charcoal classification.
Example Images:
.
├── src/ # Source code for dataloader, model, and loss functions
│ ├── dataloader.py # Few-shot episodic data loading
│ ├── model.py # ResNet-based embedding generator + dense
│ └── loss.py # Prototypical loss / metric learning losses
│ # Utility functions for metrics and visualization
│
├── train.ipynb # Main training notebook
├── helper.py # helper functions to load blocks
├── install.sh # envirement installer
├── README.md # Project documentation (this file)
git clone https://github.com/Chaouki-AI/FSL-MicroWood.git
cd FSL-MicroWoodchmod +x install.sh
./install.shjupyter notebook train.ipynbYou can configure the training parameters (N-way, K-shot, Q-query, image size, learning rate, etc.) via the Args class in train.ipynb.
The model uses:
- Backbone: ResNet (pretrained on ImageNet)
- Embedding Layer: Dense layer projecting to 256-dimensional feature space
- Loss: Prototypical loss for few-shot classification
- Optimizer: AdamW
- Learning Policy: OneCycle Learning Rate Scheduler
For a 5-shot, 15-query, 6-way configuration:
- Accuracy: 98%
- Precision: 95%
Training Curves:
Confusion Matrix:
- Episodic Training: Learns how to adapt quickly to new species with minimal examples.
- Parameter Flexibility: All Few-Shot hyperparameters are adjustable.
- Interpretability: Confusion matrix visualization to assist domain experts.
- Extendability: Easily adaptable to other microscopic image classification tasks.
The pipeline is dataset-agnostic — simply replace the dataset in src/dataloader.py with charcoal microscopic imagery and adjust preprocessing as needed. The model and episodic training logic remain unchanged.
This project is released under the MIT License.




