Skip to content

Commit

Permalink
feat: display response in predictions
Browse files Browse the repository at this point in the history
  • Loading branch information
antwxne committed Jun 9, 2022
1 parent 3944327 commit 2a02bd3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="CVAT wrapper",
version="0.0.10",
version="0.0.11",
author="antwxne",
author_email="[email protected]",
description="Python wrapper for CVAT API",
Expand Down
32 changes: 17 additions & 15 deletions src/CVAT/Predictions/Foodvisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, prediction: list[dict], frame_map: dict, label_map: dict):
asset["externalId"] in frame_map
]

def export(self) -> LabeledData:
def export(self, display_response: bool = False) -> LabeledData:
shapes: list[dict] = []
tags: list[dict] = []
for asset in self.assets:
Expand Down Expand Up @@ -44,27 +44,29 @@ def to_shapes(self) -> list[dict]:
"""
return [annotation.to_json() for annotation in self.annotations]

def to_tags(self) -> list[dict]:
def to_tags(self, display_response: bool = False) -> list[dict]:
"""
> The function takes a `Question` object as input and returns a list of dictionaries, each of which represents a
tag
Returns:
A list of dictionaries.
"""
tags = [{
"frame": self.image.frame_number,
"label_id": self.choice.id,
"group": 0,
"source": "manual",
"attributes": [
{
"spec_id": self.choice.attributes[0]["id"],
"value": "Je ne sais pas"
}
]
}]
if True:
tags: list[dict] = []
if not display_response:
tags.append({
"frame": self.image.frame_number,
"label_id": self.choice.id,
"group": 0,
"source": "manual",
"attributes": [
{
"spec_id": self.choice.attributes[0]["id"],
"value": "Je ne sais pas"
}
]
})
else:
tags.append(
{
"frame": self.image.frame_number,
Expand Down
7 changes: 5 additions & 2 deletions src/CVAT/Predictions/Interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ def __init__(self, prediction: Union[list[dict], dict], frame_map: dict, label_m
raise NotImplementedError

@abc.abstractmethod
def export(self) -> LabeledData:
def export(self, display_response: bool = False) -> LabeledData:
"""
> This function takes in a `self` object and returns a `LabeledData` object
> This function takes in a boolean value and returns a LabeledData object
Args:
display_response (bool): If True, the response will be displayed in the output. Defaults to False
"""
raise NotImplementedError
14 changes: 11 additions & 3 deletions src/CVAT/_put.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ class Put:
def __init__(self):
raise NotImplementedError

def upload_predictions(self, task: Task, prediction: IPrediction) -> None:
a = prediction.export().to_json()
def upload_predictions(self, task: Task, prediction: IPrediction, display_response: bool = False) -> None:
"""
It takes a task and a prediction, converts the prediction to JSON, and sends it to the server
Args:
task (Task): Task - the task object that you want to upload the prediction to
prediction (IPrediction): IPrediction - the prediction object that you want to upload
display_response (bool): bool = False. Defaults to False
"""
prediction_json: dict = prediction.export(display_response).to_json()
response: Response = self.session.put(
url=f'{self.url}/api/tasks/{task.id}/annotations',
json=a
json=prediction_json
)
if response.status_code != 200:
raise Exception(response.content)

0 comments on commit 2a02bd3

Please sign in to comment.