Utilities

Helper functions in instanseg.utils.utils.

Images and labels

percentile_normalize(img, percentile=0.1, subsampling_factor=1, epsilon=0.001)

Normalize an image using percentile-based scaling.

count_instances(labels)

Count the number of distinct non-zero labels (objects) in an input tensor.

Parameters:

labels (Union[ndarray, Tensor]) – The input tensor.

Returns:

The total number of non-zero labels.

Return type:

int

labels_to_features(lab, object_type='annotation', connectivity=4, transform=None, downsample=1.0, include_labels=False, classification=None, offset=None)

Create a GeoJSON FeatureCollection from a labeled image.

Parameters:
  • classification (str) – Optional classification added to output features.

  • offset (int) – Offset added to x coordinates of output features.

Returns:

A GeoJSON FeatureCollection.

Return type:

geojson.FeatureCollection

Note

Requires the rasterio and geojson packages. Install with pip install instanseg-torch[io].

Models

download_model(model_str, version=None, verbose=True, force=False)

Download and load an InstanSeg model from the model repository.

export_to_torchscript(model_str, show_example=False, output_dir='../torchscripts', model_path='../models', torchscript_name=None, use_optimized_params=False)

Export an InstanSeg model to TorchScript format.