landingai.predict
Predictor
A class that calls your inference endpoint on the LandingLens platform.
Source code in landingai/predict/cloud.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
__init__(endpoint_id, *, api_key=None, check_server_ready=True)
Predictor constructor
Parameters
endpoint_id A unique string that identifies your inference endpoint. This string can be found in the URL of your inference endpoint. Example: "9f237028-e630-4576-8826-f35ab9000abc" is the endpoint id in this URL: https://predict.app.landing.ai/inference/v1/predict?endpoint_id=9f237028-e630-4576-8826-f35ab9000abc api_key The API Key of your LandingLens organization. If not provided, it will try to load from the environment variable LANDINGAI_API_KEY or from the .env file. check_server_ready : bool, optional Check if the cloud inference service is reachable, by default True
Source code in landingai/predict/cloud.py
get_metrics()
Return the performance metrics for the last inference call.
Returns:
Name | Type | Description |
---|---|---|
Dict[str, int]
|
A dictionary containing the performance metrics. |
|
Example |
Dict[str, int]
|
|
Dict[str, int]
|
{ "decoding_s": 0.0084266, "infer_s": 3.3537345, "postprocess_s": 0.0255059, "preprocess_s": 0.0124037, "waiting_s": 0.0001487 |
|
Dict[str, int]
|
} |
Source code in landingai/predict/cloud.py
predict(image, metadata=None, **kwargs)
Call the inference endpoint and return the prediction result.
Parameters
image The input image to be predicted. The image should be in the RGB format if it has three channels. metadata The (optional) metadata associated with this inference/image. Metadata is helpful for attaching additional information to the inference result so you can later filter the historical inference results by your custom values in LandingLens.
See `landingai.common.InferenceMetadata` for more information.
Returns
The inference result in a list of dictionary Each dictionary is a prediction result. The inference result has been filtered by the confidence threshold set in LandingLens and sorted by confidence score in descending order.
Source code in landingai/predict/cloud.py
EdgePredictor
Bases: Predictor
EdgePredictor
runs local inference by connecting to an edge inference service (e.g. LandingEdge)
Source code in landingai/predict/edge.py
__init__(host='localhost', port=8000, check_server_ready=True)
By default the inference service runs on localhost:8000
Parameters
host : str, optional Hostname or IP, by default "localhost" port : int, optional Port, by default 8000 check_server_ready : bool, optional Check if the inference server is running, by default True
Source code in landingai/predict/edge.py
predict(image, metadata=None, reuse_session=True, **kwargs)
Run Edge inference on the input image and return the prediction result.
Parameters
image The input image to be predicted metadata The (optional) metadata associated with this inference/image. Metadata is helpful for attaching additional information to the inference result so you can later filter the historical inference results by your custom values in LandingLens. Note: The metadata is not reported back to LandingLens by default unless the edge inference server (i.e. ModelRunner) enables the feature of reporting historical inference results.
See `landingai.common.InferenceMetadata` for more details.
reuse_session Whether to reuse the HTTPS session for sending multiple inference requests. By default, the session is reused to improve the performance on high latency networks (e.g. fewer SSL negotiations). If you are sending requests from multiple threads, set this to False. Returns
List[Prediction] A list of prediction result.
Source code in landingai/predict/edge.py
OcrPredictor
Bases: Predictor
A class that calls your OCR inference endpoint on the LandingLens platform.
Source code in landingai/predict/ocr.py
__init__(threshold=0.5, *, language='ch', api_key=None)
OCR Predictor constructor
Parameters
threshold:
The minimum confidence threshold of the prediction to keep, by default 0.5
api_key
The API Key of your LandingLens organization.
If not provided, it will try to load from the environment variable
LANDINGAI_API_KEY or from the .env file.
language:
Specifies the character set to use. Can either be "en"
for English
or "ch"
for Chinese and English (default).
Source code in landingai/predict/ocr.py
predict(image, **kwargs)
Run OCR on the input image and return the prediction result.
Parameters
image: The input image to be predicted mode: The mode of this prediction. It can be either "multi-text" (default) or "single-text". In "multi-text" mode, the predictor will detect multiple lines of text in the image. In "single-text" mode, the predictor will detect a single line of text in the image. regions_of_interest: A list of region of interest boxes/quadrilateral. Each quadrilateral is a list of 4 points (x, y). In "single-text" mode, the caller must provide a list of quadrilateral(s) that cover the text in the image. Each quadrilateral is a list of 4 points (x, y), and it should cover a single line of text in the image. In "multi-text" mode, regions_of_interest is not required. If it is None, the whole image will be used as the region of interest.
Returns
List[OcrPrediction] A list of OCR prediction result.
Source code in landingai/predict/ocr.py
Snowflake-specific adapters and helpers
SnowflakeNativeAppPredictor
Bases: Predictor
Snowflake Native App Predictor, which is basically a regular cloud predictor with a different auth mechanism.
Source code in landingai/predict/snowflake.py
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
Module for making predictions on LandingLens models.
PredictionExtractor
The base class for all extractors. This is useful for type checking.
Source code in landingai/predict/utils.py
create_requests_session(url, num_retry, headers)
Create a requests session with retry
Source code in landingai/predict/utils.py
get_cloudinference_prediction(session, endpoint_url, files, params, extractor_class, *, data=None)
Call the inference endpoint and extract the prediction result.
Source code in landingai/predict/utils.py
serialize_rois(rois, mode)
Serialize the regions of interest into a JSON string.