Semi-Supervised Multispectral Scene Classification with Few Labels
Table of Contents
This is the code for the paper "MSMatch: Semi-Supervised Multispectral Scene Classification with Few Labels" by Pablo Gómez and Gabriele Meoni, which aims to apply the state of the art of semi-supervised learning techniques to land-use and land-cover classification problems. Currently, the repository includes an implementation of FixMatch for the training of EfficientNet Convolutional Neural Networks. The code builds on and extends the FixMatch-pytorch implementation based on PyTorch. Compared to the original repository, this repository includes code to work with both the RGB and the multispectral (MS) versions of EuroSAT dataset and the UC Merced Land Use (UCM) dataset.
- PyTorch
- conda
- EfficientNet PyTorch
- albumentations
- imageio, numpy, pandas
This is a brief example of setting up MSMatch.
We recommend using conda to set-up your environment. This will also automatically set up CUDA and the cudatoolkit for you, enabling the use of GPUs for training, which is recommended.
- conda, which will take care of all requirements for you. For a detailed list of required packages, please refer to the conda environment file.
- Get miniconda or similar
- Clone the repo
git clone https://github.com/gomezzz/MSMatch.git
- Setup the environment. This will create a conda environment called
torchmatch
conda env create -f environment.yml
To launch the training on EuroSAT (rgb or MS), it is necessary to download the corresponding datasets. The root_dir
variable in the corresponding datasets/eurosat_dataset.py
and datasets/eurosat_rgb_dataset.py
files shall be adjusted according to the dataset path.
The repository is structured as follows:
- datasets: contains the semi-supervised learning datasets usable for training, and augmentation code. To add a new dataset, a new class similar to, e.g.,
eurosat_rgb.py
needs to be added. - external/visualizations: contains tools to create visualizations of trained models. We utilized the code from the
src
directory of pytorch-cnn-visualizations repository and slightly adapted it. - models: contains the neural networks models used for training.
- notebooks: contains some jupyter notebooks used to create paper figures, collect training results, showing augmentation effects on images and provide additional functionalities. To be able to use the notebooks, it is necessary to additionally install Jupyter.
- runscripts: includes bash scripts used to train the networks.
utils.py
: some utility functions.train_utils.py
: providing utils for training.train.py
: main train script.eval.py
: main script for evaluating a trained network.environment.yml
: conda environment file describing dependencies.
To train a model on EuroSAT RGB by using EfficientNet B0 from scratch, you can use:
python train.py --dataset eurosat_rgb --net efficientnet-b0
--net
can be used to specify the EfficientNet model, whilst --dataset
can be used to specify the dataset. Use eurosat_rgb
for EuroSAT RGB, eurosat_ms
for EuroSAT MS, and ucm
for UCM dataset.
Instead of starting the training from scratch, it is possible exploit a model pretrained on ImageNet. To do it, you can use:
python train.py --dataset eurosat_rgb --net efficientnet-b0 --pretrained
Information on additional flags can be obtained by typing:
python train.py --help
For additional information on training, including the use of single/multiple GPUs, please refer to FixMatch-pytorch.
To evaluate a trained model on a target dataset, you can use:
python eval.py --load_path [LOAD_PATH] --dataset [DATASET] --net [NET]
where LOAD_PATH
is the path of the trained model (.pth
file), DATASET
is the target dataset, NET
is the network model used during the training.
See the open issues for a list of proposed features (and known issues).
The project is open to community contributions. Feel free to open an issue or write us an email if you would like to discuss a problem or idea first.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the GPL-3.0 License. See LICENSE for more information.
Created by ESA's Advanced Concepts Team
- Pablo Gómez -
pablo.gomez at esa.int
- Gabriele Meoni -
gabriele.meoni at esa.int
Project Link: https://www.esa.int/gsp/ACT/projects/semisupervised/