Train #109
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Train | |
on: | |
workflow_dispatch: | |
inputs: | |
MODEL_NAME: | |
description: 'Model name (suggested format: <country>-<region>-<year>)' | |
required: true | |
type: string | |
EVAL_DATASETS: | |
description: 'Evaluation dataset(s): (single spaced comma separated)' | |
required: true | |
type: string | |
BBOX: | |
description: 'Bounding box name' | |
required: true | |
type: string | |
OPTIONAL_MODEL_ARGS: | |
description: 'Optional model args' | |
required: false | |
default: '' | |
type: string | |
jobs: | |
train: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash -l {0} | |
env: | |
# Keys | |
WANDB_API_KEY: ${{ secrets.WANDB_API_KEY }} | |
# Script inputs | |
MODEL_NAME: ${{ inputs.MODEL_NAME }} | |
EVAL_DATASETS: ${{ inputs.EVAL_DATASETS }} | |
BBOX: ${{ inputs.BBOX }} | |
OPTIONAL_MODEL_ARGS: ${{ inputs.OPTIONAL_MODEL_ARGS }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup environment | |
uses: mamba-org/provision-with-micromamba@main | |
with: | |
environment-file: environment-dev.yml | |
environment-name: landcover-mapping | |
cache-env: true | |
- name: Login to Weights and Biases | |
run: wandb login $WANDB_API_KEY | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v1 | |
with: | |
credentials_json: ${{ secrets.GCP_SA_KEY }} | |
- name: Setup Google Cloud SDK | |
uses: google-github-actions/setup-gcloud@v1 | |
- name: Setup DVC | |
uses: iterative/setup-dvc@v1 | |
- name: Pull latest data | |
run: dvc pull data/datasets data/models | |
- name: Train model | |
run: | | |
python train.py \ | |
--model_name "$MODEL_NAME" \ | |
--eval_datasets "$EVAL_DATASETS" \ | |
--bbox "$BBOX" \ | |
--wandb \ | |
$(echo $(for m in $(echo $OPTIONAL_MODEL_ARGS | xargs); do echo $m ; done)) | |
- name: Push model to DVC | |
run: | | |
dvc commit data/models.dvc -f | |
dvc push data/models | |
- name: Push changes to remote and PR | |
if: ${{ github.ref == 'refs/heads/master' }} | |
run: | | |
git config --global user.name github-actions | |
git config --global user.email [email protected] | |
git checkout -b"$MODEL_NAME" | |
git add data/models.dvc | |
git add data/models.json | |
git add data/all_dataset_params.json | |
git commit -m "Trained new: $MODEL_NAME" | |
git push -u origin $MODEL_NAME | |
gh pr create --base master --head $MODEL_NAME --title "Trained new: $MODEL_NAME" --fill | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Push changes to branch | |
if: ${{ github.ref != 'refs/heads/master' }} | |
run: | | |
git config --global user.name github-actions | |
git config --global user.email [email protected] | |
git add data/models.dvc | |
git add data/models.json | |
git add data/all_dataset_params.json | |
git commit -m "Trained new: $MODEL_NAME" | |
git push |