Semantic Segmentation
Very light weight semantic segmentation model.
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' |
_preprocess(self, image)
private
Preprocess the image. Automatically called.
Preprocess
- Resize to the input shape.
- To RGB and normalize.
- Add the mean and divide by the standard deviation.
- Channel swap and float32.
- 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 |
required |
image |
Image |
Image to be rendered. Accept path to the image or cv2 image. |
required |
Returns:
Type | Description |
---|---|
np.ndarray |
Rendered image. |