Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the quality parameter from lambda function call endpoints #8683

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog.d/20241111_195229_roman_remove_lambda_quality.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Removed

- It it no longer possible to run lambda functions on compressed images;
original images will always be used
(<https://github.com/cvat-ai/cvat/pull/8683>)
3 changes: 0 additions & 3 deletions cvat/apps/lambda_manager/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ class FunctionCallRequestSerializer(serializers.Serializer):
function = serializers.CharField(help_text="The name of the function to execute")
task = serializers.IntegerField(help_text="The id of the task to be annotated")
job = serializers.IntegerField(required=False, help_text="The id of the job to be annotated")
quality = serializers.ChoiceField(choices=['compressed', 'original'], default="original",
help_text="The quality of the images to use in the model run"
)
max_distance = serializers.IntegerField(required=False)
threshold = serializers.FloatField(required=False)
cleanup = serializers.BooleanField(help_text="Whether existing annotations should be removed", default=False)
Expand Down
36 changes: 0 additions & 36 deletions cvat/apps/lambda_manager/tests/test_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ def test_api_v2_lambda_requests_read(self):
"task": self.main_task["id"],
"cleanup": True,
"threshold": 55,
"quality": "original",
"mapping": {
"car": { "name": "car" },
},
Expand Down Expand Up @@ -447,7 +446,6 @@ def test_api_v2_lambda_requests_create(self):
"task": self.main_task["id"],
"cleanup": True,
"threshold": 55,
"quality": "original",
"mapping": {
"car": { "name": "car" },
},
Expand All @@ -456,7 +454,6 @@ def test_api_v2_lambda_requests_create(self):
"function": id_func,
"task": self.assigneed_to_user_task["id"],
"cleanup": False,
"quality": "compressed",
"max_distance": 70,
"mapping": {
"car": { "name": "car" },
Expand Down Expand Up @@ -769,7 +766,6 @@ def test_api_v2_lambda_functions_create_reid(self):
OrderedDict([('attributes', []), ('frame', 1), ('group', None), ('id', 11260), ('label_id', 8), ('occluded', False), ('points', [1076.0, 199.0, 1218.0, 593.0]), ('source', 'auto'), ('type', 'rectangle'), ('z_order', 0)]),
OrderedDict([('attributes', []), ('frame', 1), ('group', None), ('id', 11261), ('label_id', 8), ('occluded', False), ('points', [924.0, 177.0, 1090.0, 615.0]), ('source', 'auto'), ('type', 'rectangle'), ('z_order', 0)]),
],
"quality": None,
"threshold": 0.5,
"max_distance": 55,
}
Expand All @@ -785,7 +781,6 @@ def test_api_v2_lambda_functions_create_reid(self):
OrderedDict([('attributes', []), ('frame', 1), ('group', None), ('id', 11260), ('label_id', 8), ('occluded', False), ('points', [1076.0, 199.0, 1218.0, 593.0]), ('source', 'auto'), ('type', 'rectangle'), ('z_order', 0)]),
OrderedDict([('attributes', []), ('frame', 1), ('group', 0), ('id', 11398), ('label_id', 8), ('occluded', False), ('points', [184.3935546875, 211.5048828125, 331.64968722073354, 97.27792672028772, 445.87667560321825, 126.17873100983161, 454.13404825737416, 691.8087578194827, 180.26452189455085]), ('source', 'manual'), ('type', 'polygon'), ('z_order', 0)]),
],
"quality": None,
}

response = self._post_request(f"{LAMBDA_FUNCTIONS_PATH}/{id_function_reid_with_response_data}", self.admin, data_main_task)
Expand Down Expand Up @@ -829,42 +824,11 @@ def test_api_v2_lambda_functions_create_negative(self):
self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)


def test_api_v2_lambda_functions_create_quality(self):
qualities = [None, "original", "compressed"]

for quality in qualities:
data = {
"task": self.main_task["id"],
"frame": 0,
"cleanup": True,
"quality": quality,
"mapping": {
"car": { "name": "car" },
},
}

response = self._post_request(f"{LAMBDA_FUNCTIONS_PATH}/{id_function_detector}", self.admin, data)
self.assertEqual(response.status_code, status.HTTP_200_OK)

data = {
"task": self.main_task["id"],
"frame": 0,
"cleanup": True,
"quality": "test-error-quality",
"mapping": {
"car": { "name": "car" },
},
}

response = self._post_request(f"{LAMBDA_FUNCTIONS_PATH}/{id_function_detector}", self.admin, data)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

def test_api_v2_lambda_functions_convert_mask_to_rle(self):
data_main_task = {
"function": id_function_detector,
"task": self.main_task["id"],
"cleanup": True,
"quality": "original",
"mapping": {
"car": { "name": "car" },
},
Expand Down
45 changes: 15 additions & 30 deletions cvat/apps/lambda_manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from rest_framework.request import Request

import cvat.apps.dataset_manager as dm
from cvat.apps.engine.frame_provider import FrameQuality, TaskFrameProvider
from cvat.apps.engine.frame_provider import TaskFrameProvider
from cvat.apps.engine.models import (
Job, ShapeType, SourceType, Task, Label, RequestAction, RequestTarget
)
Expand Down Expand Up @@ -257,7 +257,6 @@ def mandatory_arg(name: str) -> Any:
threshold = data.get("threshold")
if threshold:
payload.update({ "threshold": threshold })
quality = data.get("quality")
mapping = data.get("mapping", {})

model_labels = self.labels
Expand Down Expand Up @@ -387,19 +386,19 @@ def validate_attributes_mapping(attributes_mapping, model_attributes, db_attribu

if self.kind == FunctionKind.DETECTOR:
payload.update({
"image": self._get_image(db_task, mandatory_arg("frame"), quality)
"image": self._get_image(db_task, mandatory_arg("frame"))
})
elif self.kind == FunctionKind.INTERACTOR:
payload.update({
"image": self._get_image(db_task, mandatory_arg("frame"), quality),
"image": self._get_image(db_task, mandatory_arg("frame")),
"pos_points": mandatory_arg("pos_points"),
"neg_points": mandatory_arg("neg_points"),
"obj_bbox": data.get("obj_bbox", None)
})
elif self.kind == FunctionKind.REID:
payload.update({
"image0": self._get_image(db_task, mandatory_arg("frame0"), quality),
"image1": self._get_image(db_task, mandatory_arg("frame1"), quality),
"image0": self._get_image(db_task, mandatory_arg("frame0")),
"image1": self._get_image(db_task, mandatory_arg("frame1")),
"boxes0": mandatory_arg("boxes0"),
"boxes1": mandatory_arg("boxes1")
})
Expand All @@ -410,7 +409,7 @@ def validate_attributes_mapping(attributes_mapping, model_attributes, db_attribu
})
elif self.kind == FunctionKind.TRACKER:
payload.update({
"image": self._get_image(db_task, mandatory_arg("frame"), quality),
"image": self._get_image(db_task, mandatory_arg("frame")),
"shapes": data.get("shapes", []),
"states": data.get("states", [])
})
Expand Down Expand Up @@ -487,19 +486,9 @@ def transform_attributes(input_attributes, attr_mapping, db_attributes):

return response

def _get_image(self, db_task, frame, quality):
if quality is None or quality == "original":
quality = FrameQuality.ORIGINAL
elif quality == "compressed":
quality = FrameQuality.COMPRESSED
else:
raise ValidationError(
'`{}` lambda function was run '.format(self.id) +
'with wrong arguments (quality={})'.format(quality),
code=status.HTTP_400_BAD_REQUEST)

def _get_image(self, db_task, frame):
frame_provider = TaskFrameProvider(db_task)
image = frame_provider.get_frame(frame, quality=quality)
image = frame_provider.get_frame(frame)

return base64.b64encode(image.data.getvalue()).decode('utf-8')

Expand All @@ -523,7 +512,7 @@ def get_jobs(self):
return [LambdaJob(job) for job in jobs if job and job.meta.get("lambda")]

def enqueue(self,
lambda_func, threshold, task, quality, mapping, cleanup, conv_mask_to_poly, max_distance, request,
lambda_func, threshold, task, mapping, cleanup, conv_mask_to_poly, max_distance, request,
*,
job: Optional[int] = None
) -> LambdaJob:
Expand Down Expand Up @@ -576,7 +565,6 @@ def enqueue(self,
"threshold": threshold,
"task": task,
"job": job,
"quality": quality,
"cleanup": cleanup,
"conv_mask_to_poly": conv_mask_to_poly,
"mapping": mapping,
Expand Down Expand Up @@ -667,7 +655,6 @@ def _call_detector(
function: LambdaFunction,
db_task: Task,
labels: Dict[str, Dict[str, Any]],
quality: str,
threshold: float,
mapping: Optional[Dict[str, str]],
conv_mask_to_poly: bool,
Expand Down Expand Up @@ -799,7 +786,7 @@ def _map(sublabel_body):
continue

annotations = function.invoke(db_task, db_job=db_job, data={
"frame": frame, "quality": quality, "mapping": mapping,
"frame": frame, "mapping": mapping,
"threshold": threshold
})

Expand Down Expand Up @@ -854,7 +841,6 @@ def _call_reid(
cls,
function: LambdaFunction,
db_task: Task,
quality: str,
threshold: float,
max_distance: int,
*,
Expand Down Expand Up @@ -887,7 +873,7 @@ def _call_reid(
boxes1 = boxes_by_frame[frame1]
if boxes0 and boxes1:
matching = function.invoke(db_task, db_job=db_job, data={
"frame0": frame0, "frame1": frame1, "quality": quality,
"frame0": frame0, "frame1": frame1,
"boxes0": boxes0, "boxes1": boxes1, "threshold": threshold,
"max_distance": max_distance})

Expand Down Expand Up @@ -947,7 +933,7 @@ def _call_reid(
dm.task.put_task_data(db_task.id, serializer.data)

@classmethod
def __call__(cls, function, task: int, quality: str, cleanup: bool, **kwargs):
def __call__(cls, function, task: int, cleanup: bool, **kwargs):
# TODO: need logging
db_job = None
if job := kwargs.get('job'):
Expand Down Expand Up @@ -977,11 +963,11 @@ def convert_labels(db_labels):
labels = convert_labels(db_task.get_labels(prefetch=True))

if function.kind == FunctionKind.DETECTOR:
cls._call_detector(function, db_task, labels, quality,
cls._call_detector(function, db_task, labels,
kwargs.get("threshold"), kwargs.get("mapping"), kwargs.get("conv_mask_to_poly"),
db_job=db_job)
elif function.kind == FunctionKind.REID:
cls._call_reid(function, db_task, quality,
cls._call_reid(function, db_task,
kwargs.get("threshold"), kwargs.get("max_distance"), db_job=db_job)

def return_response(success_code=status.HTTP_200_OK):
Expand Down Expand Up @@ -1176,7 +1162,6 @@ def create(self, request):
threshold = request_data.get('threshold')
task = request_data['task']
job = request_data.get('job', None)
quality = request_data.get("quality")
cleanup = request_data.get('cleanup', False)
conv_mask_to_poly = request_data.get('convMaskToPoly', False)
mapping = request_data.get('mapping')
Expand All @@ -1190,7 +1175,7 @@ def create(self, request):
gateway = LambdaGateway()
queue = LambdaQueue()
lambda_func = gateway.get(function)
rq_job = queue.enqueue(lambda_func, threshold, task, quality,
rq_job = queue.enqueue(lambda_func, threshold, task,
mapping, cleanup, conv_mask_to_poly, max_distance, request, job=job)

handle_function_call(function, job or task, category="batch")
Expand Down
17 changes: 0 additions & 17 deletions cvat/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8049,15 +8049,6 @@ components:
job:
type: integer
description: The id of the job to be annotated
quality:
allOf:
- $ref: '#/components/schemas/QualityEnum'
default: original
description: |-
The quality of the images to use in the model run

* `compressed` - compressed
* `original` - original
max_distance:
type: integer
threshold:
Expand Down Expand Up @@ -10020,14 +10011,6 @@ components:
* `AZURE_CONTAINER` - AZURE_CONTAINER
* `GOOGLE_DRIVE` - GOOGLE_DRIVE
* `GOOGLE_CLOUD_STORAGE` - GOOGLE_CLOUD_STORAGE
QualityEnum:
enum:
- compressed
- original
type: string
description: |-
* `compressed` - compressed
* `original` - original
QualityReport:
type: object
properties:
Expand Down
Loading