Infer Module¶
The infer module contains the classes and function related to inference.
Folder¶
- The folders in anonymization can be of type VIDEO and IMAGE. In anonymization-sdk, we have a root folder (RootFolder) which has attributes:
folder_id: str
type: FolderType
owner_id: str
Enum: FolderType defines the types of folders supported in the SDK.
class FolderType(Enum):
VIDEO = "VIDEO"
IMAGE = "IMAGE"
- The root folder also has properties:
videos: list of Video objects
images: list of Image objects
- There is a Folder class which inherits from RootFolder and has the following attributes:
name: str
parent_folder_id: Optional[str]
ancestor_folder_ids: List[str]
description: str
To create a folder use the Folder.create() function:
- Folder.create(name, owner_id, client, type, description, parent_folder_id='user')¶
Create a folder.
- Parameters:
name (str) – name of the folder.
owner_id (str) – owner_id by which folder is created.
parent_folder_id (str) – parent folder id of the folder.
type (enum) – type of the folder.
description (str) – description of the folder.
client (anonymization.client.BaseClient) – user client.
- Returns:
Folder object
- Return type:
Folder
We can fetch the folder using the folder_id, owner_id and from from_search_params.
Using the Folder.from_folder_id() function:
- Folder.from_folder_id(folder_id, client)¶
Return the folder object from the folder_id.
- Parameters:
folder_id (str) – folder_id
client (anonymization.client.BaseClient) – user client.
- Returns:
Folder object
- Return type:
Folder
Using the Folder.from_owner_id() function:
- Folder.from_owner_id(owner_id, client)¶
Return the folder object from the owner_id.
- Parameters:
owner_id (str) – owner_id of the folder.
client (anonymization.client.BaseClient) – user client
- Returns:
List of Folder object
- Return type:
List
Using the Folder.from_search_params() function:
- Folder.from_search_params(params, client)¶
Return the folder object from the search_params.
- Parameters:
params (dict) – search_params for the folder.
client (anonymization.client.BaseClient) – user client
- Returns:
List of Folder object
- Return type:
List
Video¶
The video folder in the infer of anonymization-sdk containes all the information related to the inferencing of the videos in anonymization.
- The video class has the following attributes:
video_id: str
input_url: str
owner_id:str
parent_folder_id: str
ancestor_folder_ids: List[str]
video_urls: urls of the video, contains url along with resolution, extensopn, fps and file_size
video_fps: float
duration: float
title: str
vtt_url: str
vtt_type: enum (DEFAULT, AUTO, GCP)
remove_audio :bool
status: {download, inference}
log_file: str
It also contains a property video_url which is used to generate a new presigned url for the video if the current url has expired. We can also send a video for blurring using propery called blur.
Different methods in the Video class are:
To create a video use the Video.create() function:
- Video.create(input_url, client, parent_folder_id=None, remove_audio=False, description=None, title=None)¶
Create a video.
- Parameters:
input_url (str) – url of the video.
parent_folder_id (str) – parent folder id of the video.
client (anonymization.client.BaseClient) – user client
remove_audio (bool) – Flag to remove or keep video audio
description (str) – description of video
title (str) – title of video
- Returns:
VideoId
- Return type:
str
To update a video use the Video.update() function:
- Video.update(video_id, data: Dict, client)¶
Update a video.
- Parameters:
video_id (str) – video_id of the video.
data (dict) – dictionary of the data to be updated.
client (anonymization.client.BaseClient) – user client
- Returns:
VideoId
- Return type:
str
The videos can be fetched using video_id, folder_id and search_params.
To fetch the video using video_id use the Video.from_video_id() function:
- Video.from_video_id(video_id, client)¶
Return the video object from the video_id.
- Parameters:
video_id (str) – video_id of the video.
client (anonymization.client.BaseClient) – user client
- Returns:
Video object
- Return type:
Video
To fetch the video using folder_id use the Video.from_folder_id() function:
- Video.from_folder_id(folder_id, client)¶
Return the video object from the folder_id.
- Parameters:
folder_id (str) – folder_id of the video.
client (anonymization.client.BaseClient) – user client
- Returns:
List of Video object
- Return type:
List
To fetch the video using search_params use the Video.from_search_params() function:
- Video.from_search_params(params, client)¶
Return the video object from the search_params.
- Parameters:
params (dict) – search_params for the video.
client (anonymization.client.BaseClient) – user client
- Returns:
List of Video object
- Return type:
List
- property Video.infer¶
This property can be used to send a video for inference/blurring.
- Returns:
True/False
- Return type:
bool
To update the video satus Video.update_status() function:
- Video.update_status(inference_status: _InferenceStatus | None = None, download_status: _DownloadStatus | None = None)¶
Updates the video download and inference status.
- Parameters:
inference_status (anonymization.infer.video._InferenceStatus) – inference status of video
download_status (anonymization.infer.video._DownloadStatus) – download status of video
- Returns:
Video
- Return type:
Video Object
Images¶
- The Image class consists of the following attributes:
image_id: str
image_url: str
owner_id: str
name: str
inferred_url: str
parent_folder_id: str
ancestor_folder_ids: List[str]
resolution: {height, width}
status: {download, inference}
log_file: str
It has a property(download_annotations) to download the annotation to a file.
To create a image use the Image.create() function:
- Image.create(image_url, name, height, width, client, parent_folder_id)¶
Create a image.
- Parameters:
image_url (str) – url of the image.
name (str) – name of the image.
height (int) – height of the image.
width (int) – width of the image.
client (anonymization.client.BaseClient) – user client
parent_folder_id – parent folder id of the video.
- Returns:
Image object
- Return type:
Image
The images can be fetched using image_id, folder_id and search_params.
To fetch the image using image_id use the Image.from_image_id() function:
- Image.from_image_id(image_id, client)¶
Return the image object from the image_id.
- Parameters:
image_id (str) – image_id of the image.
client (anonymization.client.BaseClient) – user client
- Returns:
Image object
- Return type:
Image
To fetch the image using gallery_and_owner_id use the Image.from_gallery_and_owner_id() function:
- Image.from_folder_id(folder_id, client)¶
Return the image object in folder.
- Parameters:
folder_id (str) – folder_id of the image.
client (anonymization.client.BaseClient) – user client
- Returns:
List of Image object
- Return type:
List
To fetch the image using search_params use the Image.from_search_params() function:
- Image.from_search_params(params, client)¶
Return the image object from the search_params.
- Parameters:
params (dict) – search_params for the image.
client (anonymization.client.BaseClient) – user client
- Returns:
List of Image object
- Return type:
List
To update the image satus Image.update_status() function:
- Image.update_status(inference_status: _InferenceStatus | None = None, download_status: _DownloadStatus | None = None)¶
Updates the image download and inference status.
- Parameters:
inference_status (anonymization.infer.images._InferenceStatus) – inference status of image
download_status (anonymization.infer.images._DownloadStatus) – download status of image
- Returns:
Image
- Return type:
Image Object
- property Image.infer¶
This property can be used to send an image for inference/blurring.
- Returns:
True/False
- Return type:
bool