Views
No views yet
1{
2 "mean": [1720.0, 1715.0, 1913.0, 2088.0, 2274.0, 2290.0, 2613.0, 3970.0],
3 "std": [747.0, 698.0, 739.0, 768.0, 849.0, 868.0, 849.0, 914.0],
4}1# Install kelp-o-matic
2pip install git+https://github.com/HakaiInstitute/kelp-o-matic@dev
3
4# List available models
5kom list-models
6
7# Run segmentation
8kom segment \
9 --model kelp-ps8b \
10 --input /path/to/8band_planetscope_image.tif \
11 --output /path/to/kelp_segmentation.tif \
12 --batch-size 4 \
13 --blur-kernel 5 \
14 --morph-kernel 3
15
16# Use specific model version
17kom segment \
18 --model kelp-ps8b \
19 --version 20250626 \
20 --input image.tif \
21 --output result.tif
22
23# For large images, adjust batch size based on available memory
24kom segment \
25 --model kelp-ps8b \
26 --input large_image.tif \
27 --output result.tif \
28 --batch-size 81from kelp_o_matic import model_registry
2
3# Load the model (automatically downloads if needed)
4model = model_registry["kelp-ps8b"]
5
6# Process a large geospatial image with automatic tiling
7model.process(
8 input_path="path/to/your/8band_image.tif",
9 output_path="path/to/output/segmentation.tif",
10 batch_size=4,
11 crop_size=224,
12 blur_kernel_size=5, # Post-processing median blur
13 morph_kernel_size=0, # Morphological operations
14)
15
16# For more control, use the predict method directly
17import rasterio
18import numpy as np
19
20with rasterio.open("your_image.tif") as src:
21 # Read a 224x224 tile (8 bands)
22 tile = src.read(window=((0, 224), (0, 224))) # Shape: (8, 224, 224)
23 tile = np.transpose(tile, (1, 2, 0)) # Convert to HWC
24
25 # Add batch dimension and predict
26 batch = np.expand_dims(tile, axis=0) # Shape: (1, 224, 224, 8)
27 batch = np.transpose(batch, (0, 3, 1, 2)) # Convert to BCHW
28
29 # Run inference (preprocessing handled automatically)
30 predictions = model.predict(batch)
31
32 # Post-process to get final segmentation
33 segmentation = model.postprocess(predictions)1import numpy as np
2import onnxruntime as ort
3from huggingface_hub import hf_hub_download
4
5# Download the model
6model_path = hf_hub_download(repo_id="HakaiInstitute/kelp-ps8b", filename="model.onnx")
7
8# Load the model
9session = ort.InferenceSession(model_path)
10
11# Model normalization parameters
12mean = np.array([1720.0, 1715.0, 1913.0, 2088.0, 2274.0, 2290.0, 2613.0, 3970.0])
13std = np.array([747.0, 698.0, 739.0, 768.0, 849.0, 868.0, 849.0, 914.0])
14
15# Preprocess your 8-band image
16def preprocess(image):
17 """
18 Preprocess 8-band image for model input
19 image: numpy array of shape [height, width, 8] with pixel values 0-65535
20 """
21 # Apply z-score normalization
22 image = (image - mean) / std
23
24 # Reshape to model input format [batch, channels, height, width]
25 image = np.transpose(image, (2, 0, 1)) # HWC to CHW
26 image = np.expand_dims(image, axis=0) # Add batch dimension
27
28 return image
29
30# Run inference
31preprocessed = preprocess(your_8band_image)
32input_name = session.get_inputs()[0].name
33output = session.run(None, {input_name: preprocessed})
34
35# Postprocess to get binary mask
36logits = output[0]
37prediction = np.argmax(logits, axis=1).squeeze(0).astype(np.uint8)1from huggingface_hub import hf_hub_download
2import onnxruntime as ort
3
4# Download and load model
5model_path = hf_hub_download(
6 repo_id="HakaiInstitute/kelp-ps8b",
7 filename="model.onnx",
8 cache_dir="./models"
9)
10
11session = ort.InferenceSession(model_path)
12# ... continue with preprocessing and inference as above1# Via pip
2pip install git+https://github.com/HakaiInstitute/kelp-o-matic@dev1pip install onnxruntime huggingface-hub numpy
2# For GPU support:
3pip install onnxruntime-gpu1@software{Denouden_Kelp-O-Matic,
2 author = {Denouden, Taylor and Reshitnyk, Luba},
3 doi = {10.5281/zenodo.7672166},
4 title = {{Kelp-O-Matic}},
5 url = {https://github.com/HakaiInstitute/kelp-o-matic}
6}