Code Monkey home page Code Monkey logo

crop-maml's Introduction

Meta-learning for crop mapping

This repository contains the implementation of Learning to predict crop type from heterogeneous sparse labels using meta-learning, published at the EarthVision workshop at CVPR 2021.

Pipeline

The main entrypoints into the pipeline are scripts. Specifically:

Two crop type maps created using few positive labelled points are available on Google Earth Engine:

Replicating experiments in the paper

Note: not all datasets used are public, so results cannot be exactly replicated.

  1. Download the LEM+ dataset, and save it in data/raw/lem_brazil
  2. Export the GeoWiki labels, by running export_geowiki in scripts/export.py
  3. Process all the labels, by running scripts/process.py
  4. Export the Sentinel Earth Engine tif files by running the other functions in scripts/export.py
  5. Combine the labels and raw satellite imagery into (X, y) training data by running scripts/engineer.py
  6. Train the MAML model by running maml.py. The MAML model and training results will be saved in data/maml_models/version_<VERSION>, where VERSION increments for each MAML run.
  7. Finetune 10 MAML model with the following commands, bootstrapping the training data each run: (adding --test_mode {pretrained, random} will train the baseline models)
python maml_test.py --version <VERSION> --dataset Togo --many_n --num_cv 10  # Finetune on the Togo data across varying sample sizes
python maml_test.py --version <VERSION> --dataset coffee --num_samples {-1, 40} --num_cv 10  # Finetune on the coffee dataset for all negative samples, or 20 positive and 20 negative samples
python maml_test.py --version <VERSION> --dataset common_beans --num_samples {-1, 64}, --num_cv 10  # Finetune on the common beans dataset for all negative samples, or 32 positive and 32 negative samples

Setup

Anaconda running python 3.6 is used as the package manager. To get set up with an environment, install Anaconda from the link above, and (from this directory) run

conda env create -f environment.yml

This will create an environment named landcover-mapping with all the necessary packages to run the code. To activate this environment, run

conda activate landcover-mapping

Earth Engine

Earth engine is used instead of sentinel hub, because it is free. To use it, once the conda environment has been activated, run

earthengine authenticate

and follow the instructions. To test that everything has worked, run

python -c "import ee; ee.Initialize()"

Note that Earth Engine exports files to Google Drive by default (to the same google account used sign up to Earth Engine).

Running exports can be viewed (and individually cancelled) in the Tabs bar on the Earth Engine Code Editor. For additional support the Google Earth Engine forum is super helpful.

Tests

The following tests can be run against the pipeline:

pytest  # unit tests, written in the test folder
black .  # code formatting

Reference

If you find this code useful, please cite the following paper:

@InProceedings{Tseng_2021_CVPR,
    author    = {Tseng, Gabriel and Kerner, Hannah and Nakalembe, Catherine and Becker-Reshef, Inbal},
    title     = {Learning To Predict Crop Type From Heterogeneous Sparse Labels Using Meta-Learning},
    booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) Workshops},
    month     = {June},
    year      = {2021},
    pages     = {1111-1120}
}

crop-maml's People

Contributors

gabrieltseng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.