OneFormer

class grid.model.perception.segmentation.oneformer.OneFormer(*args, **kwargs)

OneFormer Image segmentation model

This class implements a wrapper for the OneFormer model, which performs image segmentation using the OneFormer architecture.

Credits: https://github.com/SHI-Labs/OneFormer

License:

This code is licensed under the MIT License.

__init__()
Return type:

None

panoptic_run(img)

Runs the OneFormer segmentation model in panoptic mode.

Parameters:

img (np.ndarray) -- The input image to perform segmentation on.

Returns:

A tuple containing the predicted segmentation map and the visualization image.

Return type:

Tuple[np.ndarray, np.ndarray]

Example

>>> oneformer = OneFormer()
>>> img = np.array(Image.open("data/turbine/rgb.png"))
>>> seg, viz = oneformer.panoptic_run(img)
run(image, mode='panoptic')

Runs the OneFormer segmentation model on the given image.

Parameters:
  • image (np.ndarray) -- The input image to perform segmentation on.

  • mode (str, optional) -- The segmentation mode. Must be one of ['panoptic', 'semantic']. Defaults to "panoptic".

Returns:

A tuple containing the predicted segmentation map and the visualization image.

Return type:

Tuple[np.ndarray, np.ndarray]

Example

>>> oneformer = OneFormer()
>>> img = np.array(Image.open("data/turbine/rgb.png"))
>>> seg, viz = oneformer.run(img, mode="panoptic")
semantic_run(img)

Runs the OneFormer segmentation model in semantic mode.

Parameters:

img (np.ndarray) -- The input image to perform segmentation on.

Returns:

A tuple containing the predicted segmentation map and the visualization image.

Return type:

Tuple[np.ndarray, np.ndarray]

Example

>>> oneformer = OneFormer()
>>> img = np.array(Image.open("data/turbine/rgb.png"))
>>> seg, viz = oneformer.semantic_run(img)