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.

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
35
36
37
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`.

    Args:
        source: Input image with Byte data type.
        dest: File path location to save output to.
        species: Do species classification instead of presence/absence.
        crop_size: The size of cropped image square run through the segmentation model.
        padding: The number of context pixels added to each side of the cropped image.
        batch_size: The batch size of cropped image sections to process together.
        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)
    RichSegmentationManager(
        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.

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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`.

    Args:
        source: Input image with Byte data type.
        dest: File path location to save output to.
        crop_size: The size of cropped image square run through the segmentation model.
        padding: The number of context pixels added to each side of the cropped image.
        batch_size: The batch size of cropped image sections to process together.
        use_gpu: Disable Cuda GPU usage and run on CPU only.
    """
    model = MusselPresenceSegmentationModel(use_gpu=use_gpu)
    RichSegmentationManager(
        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)