NRCan / geo-inference

A light-weight python package for extracting features from geospatial imagery
Other
2 stars 3 forks source link

Geo Inference

PyPI - Version Codecov tests

geo-inference is a Python package designed for feature extraction from geospatial imagery using compatible deep learning models. It provides a convenient way to extract features from large TIFF images and save the output mask as a TIFF file. It also supports converting the output mask to vector format (file_name.geojson), YOLO format (file_name.csv), and COCO format (file_name.json). This package is particularly useful for applications in remote sensing, environmental monitoring, and urban planning.

Installation

Geo-inference requires Python 3.11.

Linux Installation

To install the package, use:

pip install geo-inference

Windows Installation

The recipe to use cuda-enabled Geo-inference on Windows OS is slightly different than on Linux-based OS.

Docker installation

Alternatively, you can build the Dockerfile to use Geo-Inference.

Usage

Input: GeoTiffs with compatible TorchScript model. For example: A pytorch model trained on high resolution geospatial imagery with the following features:

expects an input image with the same features. An example notebook for how the package is used is provided in this repo.

Here's an example of how to use Geo Inference (Command line and Script):

Command line

geo_inference -a <args>

You can also use the -h option to get a list of supported arguments:

geo_inference -h

Import script

from geo_inference.geo_inference import GeoInference

# Initialize the GeoInference object
geo_inference = GeoInference(
    model="/path/to/segformer_B5.pt",
    work_dir="/path/to/work/dir",
    mask_to_vec=False,
    mask_to_yolo=False,
    mask_to_coco=False, 
    device="gpu",
    multi_gpu=False,
    gpu_id=0, 
    num_classes=5,
    prediction_threshold=0.3,
    transformers=True,
    transformer_flip=False,
    transformer_rotate=True,
)

# Perform feature extraction on a TIFF image
image_path = "/path/to/image.tif"
bands_requested = "1,2,3"
patch_size = 1024
workers = 0
patch_size = 512
bbox = "0, 0, 1000, 1000"
geo_inference(
    inference_input = image_path,  
    bands_requested = bands_requested, 
    patch_size = patch_size, 
    workers = workers, 
    bbox=bbox
)

Parameters

Initiating the GeoInference class takes the following parameters:

Calling the GeoInference object takes the following parameters:

Output

The GeoInference class outputs the following files:

Each file contains the extracted features from the input geospatial imagery.

License

Geo Inference is released under the Open Government License - Canada. See LICENSE for more information.

Contact

For any questions or concerns, please open an issue on GitHub.