Views
No views yet
1{
2 "mean": [0.485, 0.456, 0.406],
3 "std": [0.229, 0.224, 0.225],
4 "max_pixel_value": 255.0
5}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 kelp species segmentation on RGB drone imagery
8kom segment \
9 --model kelp-rgb \
10 --input /path/to/rgb_drone_image.tif \
11 --output /path/to/kelp_species_segmentation.tif \
12 --batch-size 8 \
13 --crop-size 2048 \
14 --blur-kernel 5 \
15 --morph-kernel 3
16
17# Use specific model version
18kom segment \
19 --model kelp-rgb \
20 --version 20250728 \
21 --input image.tif \
22 --output result.tif
23
24# For high-resolution imagery, use larger tiles
25kom segment \
26 --model kelp-rgb \
27 --input high_res_drone_image.tif \
28 --output result.tif \
29 --batch-size 4 \
30 --crop-size 10241from kelp_o_matic import model_registry
2
3# Load the model (automatically downloads if needed)
4model = model_registry["kelp-rgb"]
5
6# Process a large aerial image with automatic tiling
7model.process(
8 input_path="path/to/your/rgb_drone_image.tif",
9 output_path="path/to/output/kelp_species_segmentation.tif",
10 batch_size=8, # Higher batch size for RGB
11 crop_size=2048,
12 blur_kernel_size=5, # Post-processing median blur
13 morph_kernel_size=3, # Morphological operations
14)
15
16# For more control, use the predict method directly
17import rasterio
18import numpy as np
19
20with rasterio.open("drone_image.tif") as src:
21 # Read a 2048x2048 tile (3 bands: RGB)
22 tile = src.read(window=((0, 2048), (0, 2048))) # Shape: (3, 2048, 2048)
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, 2048, 2048, 3)
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)
34 # Result: 0=background, 1=giant kelp, 2=bull kelp1import numpy as np
2import onnxruntime as ort
3from huggingface_hub import hf_hub_download
4from PIL import Image
5
6# Download the model
7model_path = hf_hub_download(repo_id="HakaiInstitute/kelp-rgb", filename="model.onnx")
8
9# Load the model
10session = ort.InferenceSession(model_path)
11
12# ImageNet normalization parameters
13mean = np.array([0.485, 0.456, 0.406])
14std = np.array([0.229, 0.224, 0.225])
15
16# Preprocess your RGB image
17def preprocess(image):
18 """
19 Preprocess RGB image for model input
20 image: numpy array of shape [height, width, 3] with pixel values 0-255
21 """
22 # Normalize to 0-1
23 image = image.astype(np.float32) / 255.0
24
25 # Apply ImageNet normalization
26 image = (image - mean) / std
27
28 # Reshape to model input format [batch, channels, height, width]
29 image = np.transpose(image, (2, 0, 1)) # HWC to CHW
30 image = np.expand_dims(image, axis=0) # Add batch dimension
31
32 return image
33
34# Load and preprocess image
35image = np.array(Image.open("drone_image.jpg"))
36preprocessed = preprocess(image)
37
38# Run inference
39input_name = session.get_inputs()[0].name
40output = session.run(None, {input_name: preprocessed})
41
42# Postprocess to get class predictions
43logits = output[0] # Raw probabilities for each class
44prediction = np.argmax(logits, axis=1).squeeze(0).astype(np.uint8)
45# Result: 0=background, 1=giant kelp, 2=bull kelp1from 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-rgb",
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 pillow
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}