Skip to main content

OpenMapFlow 🌍

CI Status Docker Status tb1 db1 tb2 db2 tb3 db3

Rapid map creation with machine learning and earth observation data.

Examples: Cropland, Buildings, Maize

3maps-gif

Tutorial cb

Colab notebook tutorial demonstrating data exploration, model training, and inference over small region. (video)

Prerequisites:

How it works

To create your own maps with OpenMapFlow, you need to

  1. Generate your own OpenMapFlow project, this will allow you to:
  2. Add your own labeled data
  3. Train a model using that labeled data, and
  4. Create a map using the trained model.

openmapflow-pipeline

Generating a project cb

Prerequisites:

Once all prerequisites are satisfied, inside your Github repository run:

pip install openmapflow
openmapflow generate

The command will prompt for project configuration such as project name and Google Cloud Project ID. Several prompts will have defaults shown in square brackets. These will be used if nothing is entered.

After all configuration is set, the following project structure will be generated:

<YOUR PROJECT NAME>
│   README.md
│   datasets.py             # Dataset definitions (how labels should be processed)
│   evaluate.py             # Template script for evaluating a model
│   openmapflow.yaml        # Project configuration file
│   train.py                # Template script for training a model
│   
└─── .dvc/                  # https://dvc.org/doc/user-guide/what-is-dvc
│       
└─── .github
│   │
│   └─── workflows          # Github actions
│       │   deploy.yaml     # Automated Google Cloud deployment of trained models
│       │   test.yaml       # Automated integration tests of labeled data
│       
└─── data
    │   raw_labels/                     # User added labels
    │   datasets/                       # ML ready datasets (labels + earth observation data)
    │   models/                         # Models trained using datasets
    |   raw_labels.dvc                  # Reference to a version of raw_labels/
    |   datasets.dvc                    # Reference to a version of datasets/
    │   models.dvc                      # Reference to a version of models/
    

This project contains all the code necessary for: Adding data ➞ Training a model ➞ Creating a map.

Important: When code is pushed to the repository a Github action will be run to verify project configuration, data integrity, and script functionality. This action will pull data using dvc and thereby needs access to remote storage (your Google Drive). To allow the Github action to access the data add a new repository secret (instructions).

  • In step 5 of the instructions, name the secret: GDRIVE_CREDENTIALS_DATA
  • In step 6, enter the value in .dvc/tmp/gdrive-user-creditnals.json (in your repository)

After this the Github action should successfully run.

Adding data cb

Prerequisites:

Move raw labels into project:

export RAW_LABEL_DIR=$(openmapflow datapath RAW_LABELS)
mkdir RAW_LABEL_DIR/<my dataset name>
cp -r <path to my raw data files> RAW_LABEL_DIR/<my dataset name>

Add reference to data using a LabeledDataset object in datasets.py, example:

datasets = [
    LabeledDataset(
        dataset="example_dataset",
        country="Togo",
        raw_labels=(
            RawLabels(
                filename="Togo_2019.csv",
                longitude_col="longitude",
                latitude_col="latitude",
                class_prob=lambda df: df["crop"],
                start_year=2019,
            ),
        ),
    ),
    ...
]

Run dataset creation:

earthengine authenticate    # For getting new earth observation data
gcloud auth login           # For getting cached earth observation data

openmapflow create-dataset # Initiatiates or checks progress of dataset creation
openmapflow datasets        # Shows the status of datasets

dvc commit && dvc push      # Push new data to data version control

git add .
git commit -m'Created new dataset'
git push

Training a model cb

Prerequisites:

# Pull in latest data
dvc pull    
tar -xzf $(openmapflow datapath COMPRESSED_FEATURES) -C data

# Set model name, train model, record test metrics
export MODEL_NAME=<YOUR MODEL NAME>              
python train.py --model_name $MODEL_NAME    
python evaluate.py --model_name $MODEL_NAME 

# Push new models to data version control
dvc commit 
dvc push  

# Make a Pull Request to the repository
git checkout -b"$MODEL_NAME"
git add .
git commit -m "$MODEL_NAME"
git push --set-upstream origin "$MODEL_NAME"

Important: When a new model is pushed to the repository a Github action will be run to deploy this model to Google Cloud. To allow the Github action to access Google Cloud add a new repository secret (instructions).

  • In step 5 of the instructions, name the secret: GCP_SA_KEY
  • In step 6, enter a Google Cloud Service Account key (how to create)

Now after merging the pull request, the model will be deployed to Google Cloud.

Creating a map cb

Prerequisites:

Only available through Colab. Cloud Architecture must be deployed using the deploy.yaml Github Action.

Release files for openmapflow 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openmapflow 0.1.0
File Size Uploaded
openmapflow-0.1.0.tar.gz 53.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openmapflow 0.1.0
File Interpreter ABI Platform
openmapflow-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 119.0 kB

Release files / openmapflow-0.1.0.tar.gz

Download URL openmapflow-0.1.0.tar.gz
Size 53.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d1fa5577c28c6a0ec808a16f9e9a89a15bf2fcddf150d5067f4e9f650bd7b8cb
BLAKE2b-256 checksum
How to use checksums
6300683438c2a8575f67562a8d4bac074bbe4f6a71695541f31ce416301213f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / openmapflow-0.1.0-py3-none-any.whl

Download URL openmapflow-0.1.0-py3-none-any.whl
Size 65.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8963e554a7beb2f9498505a8faae611458bc361df4da6a9994154cadf9245eda
BLAKE2b-256 checksum
How to use checksums
f00a9e8ddda90be6628c6193cf6c871a363184d414ff595144be4cd6b768d311
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page