Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex G Rice committed Aug 25, 2022
0 parents commit e1e4033
Show file tree
Hide file tree
Showing 16 changed files with 647 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# don't add these paths to docker image, they will be accessed by bind volumes.
data/input
data/output

**/__pycache__
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
**/venv

129 changes: 129 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
25 changes: 25 additions & 0 deletions Dockerfile_cpu
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Dockerfile for image tagged {{your_org_name}}/{{repository_name}}:1
# {{ replace Docker recipe with actual code for model to run inferencing }}

FROM tensorflow/tensorflow:2.8.2

WORKDIR /tf

COPY . .

RUN apt-get update && \
# apt-get install -y --no-install-recommends \
# gdal-bin \
# libgdal-dev \
# python3-opencv && \
mkdir -p \
data/input/images \
data/input/checkpoint \
data/output && \
pip install --upgrade pip && \
pip install -r requirements.txt && \
apt-get clean -y && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*

CMD ["/tf/run_model.sh"]
25 changes: 25 additions & 0 deletions Dockerfile_gpu
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Dockerfile for image tagged {{your_org_name}}/{{repository_name}}:1-gpu
# {{ replace Docker recipe with actual code for model to run inferencing }}

FROM tensorflow/tensorflow:2.8.2-gpu

WORKDIR /tf

COPY . .

RUN apt-get update && \
# apt-get install -y --no-install-recommends \
# gdal-bin \
# libgdal-dev \
# python3-opencv && \
mkdir -p \
data/input/images \
data/input/checkpoint \
data/output && \
pip install --upgrade pip && \
pip install -r requirements.txt && \
apt-get clean -y && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*

CMD ["/tf/run_model.sh"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Radiant Earth Foundation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
162 changes: 162 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{{

:construction: This is a template git repository for a ml-model to be published
on [mlhub.earth](https://mlhub.earth). Create a repository using this template,
named as the model id, without the version suffix.

For example model id `model_unet_agri_western_cape_v1` would use:

* Github repository name for publishing: `model_unet_agri_western_cape`, release to be tagged as `v1`.
* Github repository name for Radiant internal development (if needed): `model_unet_agri_western_cape_dev`.

:warning: Remember: all text in all files this repo using `{{` mustache brackets `}}` should be
edited, or the text yanked out.

:pushpin: stac references are in reference to the ml-model extension: <https://github.com/stac-extensions/ml-model>

}}

# {{ stac.properties.title }}

{{ stac.properties.description }}

![{{stac.id}}](https://radiantmlhub.blob.core.windows.net/frontend-dataset-images/odk_sample_agricultural_dataset.png)

MLHub model id: `{{stac.id}}`. Browse on [Radiant MLHub](https://mlhub.earth/model/{{stac.id}}).

## ML Model Documentation

Please review the model architecture, license, applicable spatial and temporal extents
and other details in the [model documentation](/docs/index.md).

## System Requirements

* Git client
* [Docker](https://www.docker.com/) with
[Compose](https://docs.docker.com/compose/) v1.28 or newer.

## Hardware Requirements

|Inferencing|Training|
|-----------|--------|
|{{int}}GB RAM | {{int}}GB RAM|
| | NVIDIA GPU |

## Get Started With Inferencing

First clone this Git repository.

{{

(:pushpin: only include the following LFS section if a file > 100MB had to be
committed using LFS

<https://docs.github.com/en/repositories/working-with-files/managing-large-files/about-large-files-on-github>)

}}

{{

Please note: this repository uses
[Git Large File Support (LFS)](https://git-lfs.github.com/) to include the
model checkpoint file. Either install `git lfs` support for your git client,
use the official Mac or Windows GitHub client to clone this repository.

}}

```bash
git clone https://github.com/{{your_org_name}}/{{repository_name}}.git
cd {{repository_name}}/
```

After cloning the model repository, you can use the Docker Compose runtime
files as described below.

## Pull or Build the Docker Image

{{

:pushpin: Model developer: please build and publish your images to [Docker
Hub](https://hub.docker.com/). The images should be public, and should be
tagged as `model_id:version` and `model_id:version-gpu`.

For example model_id `model_unet_agri_western_cape_v1`
would have two docker image tags published on Docker Hub:

* `model_unet_agri_western_cape:1` for cpu inferencing
* `model_unet_agri_western_cape:1-gpu` for gpu inferencing

}}

Pull pre-built image from Docker Hub (recommended):

```bash
# cpu
docker pull docker.io/{{your_org_name}}/{{repository_name}}:1
# optional, for NVIDIA gpu
docker pull docker.io/{{your_org_name}}/{{repository_name}}:1-gpu

```

Or build image from source:

```bash
# cpu
docker build -t {{your_org_name}}/{{repository_name}}:1 -f Dockerfile_cpu .
# for NVIDIA gpu
docker build -t {{your_org_name}}/{{repository_name}}:1-gpu -f Dockerfile_gpu .

```

## Run Model to Generate New Inferences

{{

:pushpin: Model developer: do not commit training data to the data folder on
this repo, this is only a placeholder to run the model locally for inferencing.

}}

1. Prepare your input and output data folders. The `data/` folder in this repository
contains some placeholder files to guide you.

* The `data/` folder must contain:
* `input/chips` {{ Landsat, Maxar Open-Data 30cm, Sentinel-2, etc. }} imagery chips for inferencing:
* File name: {{ `chip_id.tif` }} e.g. {{ `0fec2d30-882a-4d1d-a7af-89dac0198327.tif` }}
* File Format: {{ GeoTIFF, 256x256 }}
* Coordinate Reference System: {{ WGS84, EPSG:4326 }}
* Bands: {{ 3 bands per file:
* Band 1 Type=Byte, ColorInterp=Red
* Band 2 Type=Byte, ColorInterp=Green
* Band 3 Type=Byte, ColorInterp=Blue
}}
* `/input/checkpoint` the model checkpoint {{ file | folder }}, `{{ checkpoint file or folder name }}`.
Please note: the model checkpoint is included in this repository.
* The `output/` folder is where the model will write inferencing results.

2. Set `INPUT_DATA` and `OUTPUT_DATA` environment variables corresponding with
your input and output folders. These commands will vary depending on operating
system and command-line shell:

```bash
# change paths to your actual input and output folders
export INPUT_DATA="/home/my_user/{{repository_name}}/data/input/"
export OUTPUT_DATA="/home/my_user/{{repository_name}}/data/output/"
```

3. Run the appropriate Docker Compose command for your system:

```bash
# cpu
docker compose up {{stac.id}}_cpu
# NVIDIA gpu driver
docker compose up {{stac.id}}_gpu
```

4. Wait for the `docker compose` to finish running, then inspect the
`OUTPUT_DATA` folder for results.

## Understanding Output Data

Please review the model output format and other technical details in the [model
documentation](/docs/index.md).
Loading

0 comments on commit e1e4033

Please sign in to comment.