Instance¶
Instance ¶
Instance(
project_path: Optional[StrOrPathLike] = None,
dist_path: Optional[StrOrPathLike] = None,
port: Optional[int] = None,
host: str = "127.0.0.1",
*,
already_running: bool = False,
disable_code: bool = False,
tutorial_only: bool = False,
context_in_body: bool = False,
wait_for_init_model: bool = False,
ping: bool = True,
gpu: int = 0
)
A class for starting or connecting to a PEKAT VISION project.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project_path |
Optional[StrOrPathLike]
|
Path to an existing project.
Ignored if |
None
|
dist_path |
Optional[StrOrPathLike]
|
Path to PEKAT VISION installation folder.
Ignored if |
None
|
port |
Optional[int]
|
Port of the project. |
None
|
host |
str
|
IP address of the project.
Set to |
'127.0.0.1'
|
already_running |
bool
|
Whether the project is already running. If the project is not already running, project will be started. |
False
|
disable_code |
bool
|
Disable code module.
Ignored if |
False
|
tutorial_only |
bool
|
Only allow Anomaly module and force tutorial.
Ignored if |
False
|
context_in_body |
bool
|
Whether to send the |
False
|
wait_for_init_model |
bool
|
Whether to wait for all models to be initialized before returning the Instance object.
Ignored if |
False
|
ping |
bool
|
Whether to send a ping request to |
True
|
gpu |
int
|
Which GPU to start project on.
Ignored if |
0
|
Raises:
Type | Description |
---|---|
DistNotExistsError
|
If |
DistNotFoundError
|
If no PEKAT VISION was found in the default installation directory. |
PortIsAllocatedError
|
If the specified port is already used by another process. |
ValueError
|
If not |
RuntimeError
|
If the created process has no |
ProjectNotFoundError
|
If the project was not found in the specified location. |
PekatNotStartedError
|
If PEKAT VISION couldn't start a project. |
analyze ¶
analyze(
image: Union[NDArray[np.uint8], bytes, StrOrPathLike],
response_type: ResponseType = "context",
data: Optional[str] = None,
timeout: float = 20,
) -> Result
Send an image to the running project and get the results.
response_type
will affect the image
of the returned Result
:
"context"
: context only,Result.image_bytes
will beNone
."image"
:Result.image_bytes
will contain the processed image."annotated_image"
:Result.image_bytes
will contain the processed image with drawn detected rectangles."heatmap"
:Result.image_bytes
will contain the layered heatmaps of the processed image.
In order to decode the image in Result.image_bytes
, use get_decoded_image
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
Union[NDArray[uint8], bytes, StrOrPathLike]
|
Path to the image, encoded image bytes or numpy image. |
required |
response_type |
ResponseType
|
Type of response data. |
'context'
|
data |
Optional[str]
|
Data to be added to the query.
Project will be able to access this under the |
None
|
timeout |
float
|
Timeout in seconds for the analyze request. |
20
|
Raises:
Type | Description |
---|---|
InvalidResponseTypeError
|
If |
InvalidDataTypeError
|
If |
Timeout
|
Upon timeout. |
Returns:
Type | Description |
---|---|
Result
|
A tuple of image and |
send_random ¶
send_random(
shape: Tuple[int, ...] = (512, 512, 3),
response_type: ResponseType = "context",
data: Optional[str] = None,
timeout: float = 20,
) -> Result
Send random data for analysis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shape |
Tuple[int, ...]
|
Shape of the image to be sent. |
(512, 512, 3)
|
response_type |
ResponseType
|
Type of response data. |
'context'
|
data |
Optional[str]
|
Data to be added to the query.
Project will be able to access this under the |
None
|
timeout |
float
|
Timeout in seconds for the analyze request. |
20
|
Raises:
Type | Description |
---|---|
Exception
|
Same as |
Returns:
Type | Description |
---|---|
Result
|
A tuple of image and |
stop ¶
stop(timeout: float = 5) -> None
Stop the project if it's running and not stopping already.
It can only stop the project if already_running
was set to True
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
float
|
Timeout in seconds to kill process. |
5
|
Raises:
Type | Description |
---|---|
NoConnectionError
|
Upon timeout. |
ping ¶
ping(timeout: float = 5) -> requests.Response
Ping the project to check if it's running.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
float
|
Timeout in seconds to ping. |
5
|
Raises:
Type | Description |
---|---|
NoConnectionError
|
Upon timeout. |
Returns:
Type | Description |
---|---|
Response
|
Ping response. |