landingai.predict
Module for making predictions on LandingLens models.
EdgePredictor
Bases: Predictor
EdgePredictor
runs local inference by connecting to an edge inference service (e.g. LandingEdge)
Source code in landingai/predict.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
|
__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.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.py
OcrPredictor
Bases: Predictor
A class that calls your OCR inference endpoint on the LandingLens platform.
Source code in landingai/predict.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
|
__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.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.py
Predictor
A class that calls your inference endpoint on the LandingLens platform.
Source code in landingai/predict.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 |
|
__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.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.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.py
serialize_rois(rois, mode)
Serialize the regions of interest into a JSON string.