GeoSAM Image Encoder Package#

Superseded by the geosam library

The standalone GeoSAM-Image-Encoder Python package has been superseded by the geosam core library since Geo-SAM v2.0.

Use the geosam library directly (see the migration section below). The legacy package is no longer supported by the Geo-SAM QGIS plugin v2.0+; it is only compatible with plugins older than v2.0.


Legacy Overview#

The GeoSAM-Image-Encoder package was a standalone Python package that did not depend on QGIS. It allowed you to encode remote sensing images into features on a remote server (e.g., Colab or AWS) and then load them in the Geo-SAM QGIS plugin.

Legacy Installation#

Install PyTorch first

Installing GeoSAM-Image-Encoder directly installs the CPU version of PyTorch. Install the appropriate PyTorch version first from https://pytorch.org/get-started/locally/.

pip install GeoSAM-Image-Encoder
# or from source
pip install git+https://github.com/Fanchengyan/GeoSAM-Image-Encoder.git

Legacy Python Usage#

import geosam
from geosam import ImageEncoder

# check GPU availability
geosam.gpu_available()

# encode by direct parameters
checkpoint_path = "/content/sam_vit_l_0b3195.pth"
image_path = "/content/beiluhe_google_img_201211_clip.tif"
feature_dir = "./"

img_encoder = ImageEncoder(checkpoint_path)
img_encoder.encode_image(image_path, feature_dir)

Using a Settings JSON File#

import geosam
from geosam import ImageEncoder

setting_file = "/content/setting.json"
feature_dir = "./"

settings = geosam.parse_settings_file(setting_file)
settings.update({"feature_dir": feature_dir})
init_settings, encode_settings = geosam.split_settings(settings)

img_encoder = ImageEncoder(**init_settings)
img_encoder.encode_image(**encode_settings)

Legacy Terminal Usage#

image_encoder.py -i /content/image.tif -c /content/checkpoint.pth -f ./
# override settings from a file
image_encoder.py -s /content/setting.json -f ./ --stride 256 --value_range "10,255"
# see all options
image_encoder.py -h

Legacy Colab Example#

The original Colab notebook is still available:

https://colab.research.google.com/github/Fanchengyan/GeoSAM-Image-Encoder/blob/main/examples/geosam-image-encoder.ipynb