From e6c1533c5242e306517ee3c911a5135e108ac09f Mon Sep 17 00:00:00 2001 From: Antoine DESRUET Date: Wed, 8 Jun 2022 13:12:20 +0200 Subject: [PATCH] feat: get prediction from json --- src/CVAT/_get.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/CVAT/_get.py b/src/CVAT/_get.py index 7c80e11..2fc9d85 100644 --- a/src/CVAT/_get.py +++ b/src/CVAT/_get.py @@ -112,6 +112,24 @@ def get_prediction_from_file(self, task: Union[Task, str], prediction_type: str, labels_map: dict = self.get_labels_map(task) return Get.PREDICTION_FACTORY[prediction_type](prediction_json, frame_map, labels_map) + def get_prediction_from_json(self, task: Union[Task, str], prediction_type: str, prediction: dict) -> IPrediction: + """ + > The function takes a task, a prediction type, and a prediction dictionary, and returns a prediction object + + Args: + task (Union[Task, str]): The name of the task. + prediction_type (str): str - the type of prediction. It can be one of the following: + prediction (dict): dict - the prediction in the JSON format + """ + if isinstance(task, str): + task: Task = self.get_task_by_name(task) + if prediction_type not in Get.PREDICTION_FACTORY: + raise ValueError( + f'Prediction type must be one of {Get.PREDICTION_FACTORY.keys()}. Actual: {prediction_type}') + frame_map: dict = self.get_map_external_ids_frame(task) + labels_map: dict = self.get_labels_map(task) + return Get.PREDICTION_FACTORY[prediction_type](prediction, frame_map, labels_map) + def get_project_by_name(self, project_name: str) -> int: """ It takes a project name as a string and returns the project ID as an integer