SemanticSegmentation
- class SemanticSegmentationResults(class_map, duration, image)
The results of semantic segmentation from
SemanticSegmentation
.- Parameters:
- 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.
- build_legend()
Create a class legend that associates color with a class object
- Return type:
- 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:
- Return type:
- 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: Accelerator | None
The accelerator being used.
- property colors: ndarray | None
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.
- property labels: List[str] | None
The labels for the loaded model.
Note: Initialized to None when the model doesn’t have any labels.
- 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
- property model_purpose: SupportedPurposes
The purpose of the model being used.
- 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:
- 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.