Skip to content

i.ann.maskrcnn.detect

Detect features in images using a Mask R-CNN model

i.ann.maskrcnn.detect [-e] [band1=string] [band2=string] [band3=string] [images_directory=name] [images_format=string] model=string classes=string [,string,...] [output_type=string] [--verbose] [--quiet] [--qq] [--ui]

Example:

i.ann.maskrcnn.detect images_directory=name model=string classes=string

grass.script.run_command("i.ann.maskrcnn.detect", band1=None, band2=None, band3=None, images_directory=None, images_format=None, model, classes, output_type="area", flags=None, verbose=False, quiet=False, superquiet=False)

Example:

gs.run_command("i.ann.maskrcnn.detect", images_directory="name", model="string", classes="string")

Parameters

band1=string
    Name of raster maps to use for detection as the first band (divided by ",")
band2=string
    Name of raster maps to use for detection as the second band (divided by ",")
band3=string
    Name of raster maps to use for detection as the third band (divided by ",")
images_directory=name
    Path to a directory with external images to detect
    Name of input directory
images_format=string
    Format suffix of images
    .jpg, .tiff, .png, etc.
model=string [required]
    Path to the .h5 file containing the model
classes=string [,string,...] [required]
    Names of classes separated with ","
output_type=string
    Type of output
    Allowed values: area, point
    Default: area
-e
    External georeferencing in the images folder (when using images_directory)
--help
    Print usage summary
--verbose
    Verbose module output
--quiet
    Quiet module output
--qq
    Very quiet module output
--ui
    Force launching GUI dialog

band1 : str, optional
    Name of raster maps to use for detection as the first band (divided by ",")
band2 : str, optional
    Name of raster maps to use for detection as the second band (divided by ",")
band3 : str, optional
    Name of raster maps to use for detection as the third band (divided by ",")
images_directory : str, optional
    Path to a directory with external images to detect
    Name of input directory
    Used as: input, dir, name
images_format : str, optional
    Format suffix of images
    .jpg, .tiff, .png, etc.
model : str, required
    Path to the .h5 file containing the model
classes : str | list[str], required
    Names of classes separated with ","
output_type : str, optional
    Type of output
    Allowed values: area, point
    Default: area
flags : str, optional
    Allowed values: e
    e
        External georeferencing in the images folder (when using images_directory)
verbose: bool, optional
    Verbose module output
    Default: False
quiet: bool, optional
    Quiet module output
    Default: False
superquiet: bool, optional
    Very quiet module output
    Default: False

DESCRIPTION

i.ann.maskrcnn.detect allows the user to use a Mask R-CNN model to detect features in GRASS GIS raster maps or georeferenced files and extract them either as areas or points. The module creates a separate map for each class.

NOTES

The detection may be used for raster maps imported in GRASS GIS or for external files (or using both). To use raster maps in GRASS GIS, you need to pass them in three bands following the order used during the training, e.g. if the training has been made on RGB images, use band1=*.red, band1=*.green and band3=*.blue. To pass multiple images, put more maps into band* parameters, divided by ",".

The detection may be used also for multiple external files. However, all files for the detection must be in one directory specified in the images_directory parameter. Even when using only one image, the module finds it through this parameter.

When detecting, you can use new names of classes. Classes in the model are not referenced by their name, but by their order. It means that if the model was trained with classes corn,rice and you use i.ann.maskrcnn.detect with classes zea,oryza, zea areas will present areas detected as corn and oryza areas will present areas detected as rice.

If the external file is georeferenced externally (by a worldfile or an .aux.xml file), please use -e flag.

EXAMPLES

Detect buildings and lakes and import them as areas

One map imported in GRASS GIS:

i.ann.maskrcnn.detect band1=map1.red band2=map1.green band3=map1.blue classes=buildings,lakes model=/home/user/Documents/logs/mask_rcnn_buildings_lakes_0100.h5

Two maps (map1, map2) imported in GRASS GIS:

i.ann.maskrcnn.detect band1=map1.red,map2.red band2=map1.green,map2.green band3=map1.blue,map2.blue classes=buildings,lakes model=/home/user/Documents/logs/mask_rcnn_buildings_lakes_0100.h5

External files, the georeferencing is internal (GeoTIFF):

i.ann.maskrcnn.detect images_directory=/home/user/Documents/georeferenced_images classes=buildings,lakes model=/home/user/Documents/logs/mask_rcnn_buildings_lakes_0100.h5 images_format=tif

External files, the georeferencing is external:

i.ann.maskrcnn.detect images_directory=/home/user/Documents/georeferenced_images classes=buildings,lakes model=/home/user/Documents/logs/mask_rcnn_buildings_lakes_0100.h5 images_format=png -e

Detect cottages and plattenbaus and import them as points

i.ann.maskrcnn.detect band1=map1.red band2=map1.green band3=map1.blue classes=buildings,lakes model=/home/user/Documents/logs/mask_rcnn_buildings_lakes_0100.h5 output_type=point

SEE ALSO

Mask R-CNN in GRASS GIS, i.ann.maskrcnn.train

AUTHOR

Ondrej Pesek

SOURCE CODE

Available at: i.ann.maskrcnn.detect source code (history)
Latest change: Thursday Feb 20 13:02:26 2025 in commit 53de819