Skip to content

Chaouki-AI/FSL-MicroWood

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Few-Shot Learning for Microscopic Wood Species Classification

alt text

Overview

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

Dataset

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:

alt text


Repository Structure

.
├── 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)


Installation

1. Clone the repository

git clone https://github.com/Chaouki-AI/FSL-MicroWood.git
cd FSL-MicroWood

2. Create a virtual environment

chmod +x install.sh
./install.sh

Training

Run the main training notebook

jupyter notebook train.ipynb

You can configure the training parameters (N-way, K-shot, Q-query, image size, learning rate, etc.) via the Args class in train.ipynb.


Model Architecture

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

Results

For a 5-shot, 15-query, 6-way configuration:

  • Accuracy: 98%
  • Precision: 95%

Training Curves:

alt text alt text

Confusion Matrix:

alt text


Key Features

  • 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.

How to Adapt to Charcoal Classification

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.


License

This project is released under the MIT License.

About

Few-Shot Learning for Microscopic Wood Species Classification

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published