Skip to content

Semantic Segmentation

SemanticSegmentationModel

Bases: InferenceModel

Run inference on a semantic segmentation model hosted on Roboflow or served through Roboflow Inference.

Source code in roboflow/models/semantic_segmentation.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class SemanticSegmentationModel(InferenceModel):
    """
    Run inference on a semantic segmentation model hosted on Roboflow or served through Roboflow Inference.
    """

    def __init__(self, api_key: str, version_id: str):
        """
        Create a SemanticSegmentationModel object through which you can run inference.

        Args:
            api_key (str): private roboflow api key
            version_id (str): the workspace/project id
        """
        super(SemanticSegmentationModel, self).__init__(api_key, version_id)
        self.api_url = f"{SEMANTIC_SEGMENTATION_URL}/{self.dataset_id}/{self.version}"

    def predict(self, image_path: str, confidence: int = 50):
        """
        Infers detections based on image from a specified model and image path.

        Args:
            image_path (str): path to the image you'd like to perform prediction on
            confidence (int): confidence threshold for predictions, on a scale from 0-100

        Returns:
            PredictionGroup Object

        Example:
            >>> import roboflow

            >>> rf = roboflow.Roboflow(api_key="")

            >>> project = rf.workspace().project("PROJECT_ID")

            >>> model = project.version("1").model

            >>> prediction = model.predict("YOUR_IMAGE.jpg")
        """
        return super(SemanticSegmentationModel, self).predict(
            image_path,
            confidence=confidence,
            prediction_type=SEMANTIC_SEGMENTATION_MODEL,
        )

    def __str__(self):
        return f"<{type(self).__name__} id={self.id}, api_url={self.api_url}>"

__init__(api_key, version_id)

Create a SemanticSegmentationModel object through which you can run inference.

Parameters:

Name Type Description Default
api_key str

private roboflow api key

required
version_id str

the workspace/project id

required
Source code in roboflow/models/semantic_segmentation.py
10
11
12
13
14
15
16
17
18
19
def __init__(self, api_key: str, version_id: str):
    """
    Create a SemanticSegmentationModel object through which you can run inference.

    Args:
        api_key (str): private roboflow api key
        version_id (str): the workspace/project id
    """
    super(SemanticSegmentationModel, self).__init__(api_key, version_id)
    self.api_url = f"{SEMANTIC_SEGMENTATION_URL}/{self.dataset_id}/{self.version}"

predict(image_path, confidence=50)

Infers detections based on image from a specified model and image path.

Parameters:

Name Type Description Default
image_path str

path to the image you'd like to perform prediction on

required
confidence int

confidence threshold for predictions, on a scale from 0-100

50

Returns:

Type Description

PredictionGroup Object

Example

import roboflow

rf = roboflow.Roboflow(api_key="")

project = rf.workspace().project("PROJECT_ID")

model = project.version("1").model

prediction = model.predict("YOUR_IMAGE.jpg")

Source code in roboflow/models/semantic_segmentation.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def predict(self, image_path: str, confidence: int = 50):
    """
    Infers detections based on image from a specified model and image path.

    Args:
        image_path (str): path to the image you'd like to perform prediction on
        confidence (int): confidence threshold for predictions, on a scale from 0-100

    Returns:
        PredictionGroup Object

    Example:
        >>> import roboflow

        >>> rf = roboflow.Roboflow(api_key="")

        >>> project = rf.workspace().project("PROJECT_ID")

        >>> model = project.version("1").model

        >>> prediction = model.predict("YOUR_IMAGE.jpg")
    """
    return super(SemanticSegmentationModel, self).predict(
        image_path,
        confidence=confidence,
        prediction_type=SEMANTIC_SEGMENTATION_MODEL,
    )