Skip to content

Semantic Segmentation

Very light weight semantic segmentation model.

Image title

Query image and prediction

BiWAKO.FastSCNN

Semantic Segmentation

Attributes:

Name Type Description
model_path str

Path to the model file.

model onnxruntime.InferenceSession

Inference session.

input_shape tuple

Input shape of the model. Set to (384, 384) for fast_scnn384 and (1344, 768) for fast_scnn7681344.

input_name str

Name of the input node.

output_name str

Name of the output node.

mean np.ndarray

Mean value of the dataset.

std np.ndarray

Standard deviation of the dataset.

c_map

Color map for the semantic segmentation 19 object classes.

__init__(self, model='fast_scnn384', **kwargs) special

Initialize FastSCNN model.

Parameters:

Name Type Description Default
model str

Choice of model. Accept model name or path to the downloaded onnx file. If onnx file has not been downloaded, it will be downloaded automatically. Currently avaiable models are [fast_scnn384, fast_scnn7681344]. Defaults to "fast_scnn384".

'fast_scnn384'

_preprocess(self, image) private

Preprocess the image. Automatically called.

Preprocess

  1. Resize to the input shape.
  2. To RGB and normalize.
  3. Add the mean and divide by the standard deviation.
  4. Channel swap and float32.
  5. Add batch dimension.

Parameters:

Name Type Description Default
image np.ndarray

Image to be preprocessed.

required

Returns:

Type Description
np.ndarray

Preprocessed image.

predict(self, image)

Return the prediction map. The last channel has 19 classes.

Parameters:

Name Type Description Default
image Image

Image to be predicted. Accept path to the image or cv2 image.

required

Returns:

Type Description
np.ndarray

Prediction map in the shape of (height, width, 19).

render(self, prediction, image, **kwargs)

Apply the prediction map to the image.

Parameters:

Name Type Description Default
prediction np.ndarray

Prediction map retuned by predict.

required
image Image

Image to be rendered. Accept path to the image or cv2 image.

required

Returns:

Type Description
np.ndarray

Rendered image.