Extract features from geospatial imagery using deep learning models
Project description
Geo Inference
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. To install the package, use:
pip install geo-inference
Usage
Input: GeoTiffs with compatible TorchScript model. For example: A pytorch model trained on high resolution geospatial imagery with the following features:
- pixel size (0.1m to 3m)
- data type (uint8)
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
python geo_inference.py -a <args>
-a
,--args
: Path to arguments stored in yaml, consult ./config/sample_config.yaml
python geo_inference.py -i <image> -m <model> -wd <work_dir> -bs <batch_size> -v <vec> -d <device> -id <gpu_id>
-i
,--image
: Path to Geotiff-bb
,--bbox
: AOI bbox in this format "minx, miny, maxx, maxy" (Optional)-m
,--model
: Path or URL to the model file-wd
,--work_dir
: Working Directory-bs
,--batch_size
: The Batch Size-v
,--vec
: Vector Conversion-d
,--device
: CPU or GPU Device-id
,--gpu_id
: GPU ID, Default = 0
You can also use the -h
option to get a list of supported arguments:
python geo_inference.py -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",
batch_size=4,
mask_to_vec=True,
device="gpu",
gpu_id=0
)
# Perform feature extraction on a TIFF image
image_path = "/path/to/image.tif"
patch_size = 512
stride_size = 256
geo_inference(image_path, patch_size, stride_size)
Parameters
The GeoInference
class takes the following parameters:
model
: The path or URL to the model file (.pt for PyTorch models) to use for feature extraction.work_dir
: The path to the working directory. Default is"~/.cache"
.batch_size
: The batch size to use for feature extraction. Default is4
.mask_to_vec
: If set to"True"
, vector files will be created. Default is"False"
device
: The device to use for feature extraction. Can be"cpu"
or"gpu"
. Default is"gpu"
.gpu_id
: The ID of the GPU to use for feature extraction. Default is0
.
Output
The GeoInference
class outputs the following files:
mask.tif
: The output mask file in TIFF format.polygons.geojson
: The output polygon file in GeoJSON format. This file is only generated if themask_to_vec
parameter is set toTrue
.yolo.csv
: The output YOLO file in CSV format. This file is only generated if themask_to_vec
parameter is set toTrue
.
Each file contains the extracted features from the input geospatial imagery.
License
Geo Inference is released under the MIT License. See LICENSE
for more information.
Contact
For any questions or concerns, please open an issue on GitHub.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for geo_inference-2.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 660b0b85a76fa75b2481ae99ffdc17881bec43f918e220b4e9b4594b83103fa6 |
|
MD5 | cc90bb4c765663e1d6991797c7ab2307 |
|
BLAKE2b-256 | be15d8afac92aa3ddb25fbae968d9b81c7405ce1b642348d7bec5ba1532febe8 |