SemanticSegmentation¶
- class SemanticSegmentationResults(class_map, duration, image)¶
The results of semantic segmentation from
SemanticSegmentation
.- Parameters
class_map (
ndarray
) – The class label with the highest probability for each and every (x, y)-coordinate in the imageduration (
float
) – The duration of the inference.image (
ndarray
) – The image that the inference was performed on.
- property duration: float¶
The duration of the inference in seconds.
- Return type
float
- property class_map: ndarray¶
The class label with the highest probability for each and every (x, y)-coordinate in the image.
- Return type
ndarray
- property image: ndarray¶
The image the results were processed on.
- Return type
ndarray
- class SemanticSegmentation(model_id, model_config=None)¶
Classify every pixel in an image.
The build_legend() is useful when used with the
Streamer
.Typical usage:
semantic_segmentation = edgeiq.SemanticSegmentation('alwaysai/enet') semantic_segmentation.load(engine=edgeiq.Engine.DNN) with edgeiq.Streamer() as streamer: <get image> results = semantic_segmentation.segment_image(image) text = 'Inference time: {:1.3f} s'.format(results.duration) text.append('Legend:') text.append(semantic_segmentation.build_legend()) mask = semantic_segmentation.build_image_mask(results.class_map) blended = edgeiq.blend_images(image, mask, alpha=0.5) streamer.send_data(blended, text)
- Parameters
model_id (
str
) – The ID of the model you want to use for semantic segmentation.
- segment_image(image)¶
Classify every pixel within the specified image.
- Parameters
image (
ndarray
) – The image to analyze.- Return type
- build_image_mask(class_map)¶
Create an image mask by mapping colors to the class map. Colors can be set by the colors attribute.
- Parameters
class_map (
ndarray
) – The class label with the highest probability for each and every (x, y)-coordinate in the image- Return type
ndarray
- Returns
Class color visualization for each pixel
- build_legend()¶
Create a class legend that associates color with a class object
- Return type
str
- Returns
An HTML table with class labels and colors that can be used with the streamer.
- build_object_map(class_map, class_list)¶
Create a object map by isolating classes within the class map.
- Parameters
class_map (
ndarray
) – The class with the highest probability for each and every (x, y)-coordinate in the imageclass_list (
List
[str
]) – The list of labels to include in the object map.
- Return type
ndarray
- Returns
The specific classes from the class list for each and every (x, y)-coordinate in the original image. Other classes not in the specified class list are rendered as non-labled or background.
- property accelerator: Optional[Accelerator]¶
The accelerator being used.
- Return type
Optional
[Accelerator
]
- property colors: Optional[ndarray]¶
The auto-generated colors for the loaded model.
Note: Initialized to None when the model doesn’t have any labels. Note: To update, the new colors list must be same length as the label list.
- Return type
Optional
[ndarray
]
- property labels: Optional[List[str]]¶
The labels for the loaded model.
Note: Initialized to None when the model doesn’t have any labels.
- Return type
Optional
[List
[str
]]
- load(engine=Engine.DNN, accelerator=Accelerator.DEFAULT)¶
Load the model to an engine and accelerator.
- Parameters
engine (
Engine
) – The engine to load the model toaccelerator (
Accelerator
) – The accelerator to load the model to
- property model_config: ModelConfig¶
The configuration of the model that was loaded
- Return type
- property model_id: str¶
The ID of the loaded model.
- Return type
str
- property model_purpose: SupportedPurposes¶
The purpose of the model being used.
- Return type
SupportedPurposes
- publish_analytics(results, tag=None, **kwargs)¶
Publish results to the alwaysAI Analytics Service
Example usage:
try: inference.publish_analytics(results, tag='custom_tag') except edgeiq.PublishError as e: # Retry publish except edgeiq.ConnectionError as e: # Save state and exit app to reconnect
- Parameters
results (
TypeVar
(ResultsT
)) – The results to publish.tag (
Optional
[Any
]) – Additional information to assist in querying and visualizations.
- Raises
ConnectionBlockedError
when using connection to the alwaysAI Device Agent and resources are at capacity,- Raises
PacketRateError
when publish rate exceeds current limit,- Raises
PacketSizeError
when packet size exceeds current limit. Packet publish size and rate limits will be provided in the error message.