Skip to content

Python Library Reference

The Python library provide two functions that run classification on an input image and write data to an output location.

API

kelp_o_matic.find_kelp(source, dest, species=False, crop_size=512, padding=256, batch_size=1, use_gpu=True)

Detect kelp in image at path source and output the resulting classification raster to file at path dest.

Parameters:

Name Type Description Default
source str

Input image with Byte data type.

required
dest str

File path location to save output to.

required
species bool

Do species classification instead of presence/absence.

False
crop_size int

The size of cropped image square run through the segmentation model.

512
padding int

The number of context pixels added to each side of the cropped image squares.

256
batch_size int

The batch size of cropped image sections to process together.

1
use_gpu bool

Disable Cuda GPU usage and run on CPU only.

True
Source code in kelp_o_matic/lib.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def find_kelp(
    source: str,
    dest: str,
    species: bool = False,
    crop_size: int = 512,
    padding: int = 256,
    batch_size: int = 1,
    use_gpu: bool = True,
):
    """Detect kelp in image at path `source` and output the resulting classification raster to file at path `dest`.

    :param source: Input image with Byte data type.
    :param dest: File path location to save output to.
    :param species: Do species classification instead of presence/absence.
    :param crop_size: The size of cropped image square run through the segmentation model.
    :param padding: The number of context pixels added to each side of the cropped image squares.
    :param batch_size: The batch size of cropped image sections to process together.
    :param use_gpu: Disable Cuda GPU usage and run on CPU only.
    """
    if species:
        model = KelpSpeciesSegmentationModel(use_gpu=use_gpu)
    else:
        model = KelpPresenceSegmentationModel(use_gpu=use_gpu)
    GeotiffSegmentation(
        model, source, dest, crop_size=crop_size, padding=padding, batch_size=batch_size
    )()

Example

import kelp_o_matic
kelp_o_matic.find_kelp("./path/to/kelp_image.tif", "./path/to/output_file_to_write.tif", crop_size=3200)

kelp_o_matic.find_mussels(source, dest, crop_size=512, padding=256, batch_size=1, use_gpu=True)

Detect mussels in image at path source and output the resulting classification raster to file at path dest.

Parameters:

Name Type Description Default
source str

Input image with Byte data type.

required
dest str

File path location to save output to.

required
crop_size int

The size of cropped image square run through the segmentation model.

512
padding int

The number of context pixels added to each side of the cropped image squares.

256
batch_size int

The batch size of cropped image sections to process together.

1
use_gpu bool

Disable Cuda GPU usage and run on CPU only.

True
Source code in kelp_o_matic/lib.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def find_mussels(
    source: str,
    dest: str,
    crop_size: int = 512,
    padding: int = 256,
    batch_size: int = 1,
    use_gpu: bool = True,
):
    """Detect mussels in image at path `source` and output the resulting classification raster to file at path `dest`.

    :param source: Input image with Byte data type.
    :param dest: File path location to save output to.
    :param crop_size: The size of cropped image square run through the segmentation model.
    :param padding: The number of context pixels added to each side of the cropped image squares.
    :param batch_size: The batch size of cropped image sections to process together.
    :param use_gpu: Disable Cuda GPU usage and run on CPU only.
    """
    model = MusselPresenceSegmentationModel(use_gpu=use_gpu)
    GeotiffSegmentation(
        model, source, dest, crop_size=crop_size, padding=padding, batch_size=batch_size
    )()

Example

import kelp_o_matic
kelp_o_matic.find_mussels("./path/to/mussel_image.tif", "./path/to/output_file_to_write.tif", crop_size=3200)