A package for encoding satellite images into Geo-SAM features.
Project description
GeoSAM-Image-Encoder
This package is part of Geo-SAM and is used to encode image data into features recognized by Geo-SAM.
Installation
It is recommended to use the latest version of pip to install GeoSAM-Image-Encoder.
pip install GeoSAM-Image-Encoder
Usage
You can call this script in Python or Terminal.
Using Python
from geosam import encode_image
image_path = "path_to_image_file"
checkpoint_path = "path_to_checkpoint"
feature_dir = "output_feature_dir"
encode_image(image_path, checkpoint_path, feature_dir)
Parameters:
image_path: str or Path
Path to the input image.
checkpoint_path: str or Path
Path to the SAM checkpoint.
feature_dir: str or Path
Path to the output feature directory.
model_type: one of ["vit_h", "vit_l", "vit_b"] or [0, 1, 2] or None, optional
The type of the SAM model. If None, the model type will be
inferred from the checkpoint path. Default: None.
bands: list of int, optional
The bands to be used for encoding. Should not be more than three bands.
If None, the first three bands (if available) will be used. Default: None.
stride: int, optional
The stride of the sliding window. Default: 512.
extent: str, optional
The extent of the image to be encoded. Should be in the format of
"minx, miny, maxx, maxy, [crs]". If None, the extent of the input
image will be used. Default: None.
value_range: tuple of float, optional
The value range of the input image. If None, the value range will be
automatically calculated from the input image. Default: None.
resolution: float, optional
The resolution of the output feature in the unit of raster crs.
If None, the resolution of the input image will be used. Default: None.
batch_size: int, optional
The batch size for encoding. Default: 1.
gpu: bool, optional
Whether to use GPU for encoding if available. Default: True.
gpu_id: int, optional
The device id of the GPU to be used. Default: 0.
or using setting.json
file
from geosam import encode_image_from_cmd
setting_path = "path_to_setting_file.json"
feature_dir = "output_feature_dir"
cmd = f"image_encoder.py -s {setting_path} -f {feature_dir}"
encode_image_from_cmd(cmd.split())
Using Terminal
Before running this script in terminal, you need to add the folder contains the image_encoder.py script to the environment variables. You can use the following code to view the contents of this folder.
import geosam
print(geosam.folder)
Once the environment variables are configured, you can directly call this script in terminal.
image_encoder.py -s path_to_setting_file.json -f output_feature_dir
You can find all Parameters by running:
image_encoder.py -h
# or
image_encoder.py --help
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 GeoSAM-Image-Encoder-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d80feaef0832356f49266c699c3b29c0afc2cab8d53a89b3fb83852543c41601 |
|
MD5 | 6db128768f239a1d2bd0cacb387cac43 |
|
BLAKE2b-256 | fa193a0bebe18eedc8a423509ce65082f2123566e5a620522fcb41c1fbfddc5c |
Hashes for GeoSAM_Image_Encoder-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 659f97556f6ad0faf395c4f292353e5eae3c7e4b0b1be4563439b7af1fc64234 |
|
MD5 | d5135c5ac273f5ecf645ab85c6e4e96f |
|
BLAKE2b-256 | 05a9a30d0f56c6b5381b3deb6e89bc7b15c1a7fc1d186c9b9d7b325330b850af |