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

Accelerated SAM decoder, fixed serverless for EXIF rotated images #6275

Merged
merged 11 commits into from
Jun 13, 2023
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## \[2.5.0] - Unreleased
### Added
- New option ``semi-auto`` is available as annotations source (<https://github.com/opencv/cvat/pull/6263>)
- \[API\] Support for Ground Truth job creation and removal (<https://github.com/opencv/cvat/pull/6204>)
- \[API\] Task quality estimation endpoints (<https://github.com/opencv/cvat/pull/6204>)

Expand All @@ -24,7 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- TDB

### Fixed
- TDB
- Running serverless models for EXIF-rotated images (<https://github.com/opencv/cvat/pull/6275/>)

### Security
- TDB
Expand Down
40 changes: 24 additions & 16 deletions cvat/apps/engine/media_extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

ORIENTATION_EXIF_TAG = 274


class ORIENTATION(IntEnum):
NORMAL_HORIZONTAL=1
MIRROR_HORIZONTAL=2
Expand All @@ -42,7 +41,6 @@ class ORIENTATION(IntEnum):
MIRROR_HORIZONTAL_90_ROTATED=7
NORMAL_270_ROTATED=8


def get_mime(name):
for type_name, type_def in MEDIA_TYPES.items():
if type_def['has_mime_type'](name):
Expand Down Expand Up @@ -648,22 +646,37 @@ def save_as_chunk(self, images, chunk_path):
pass

class ZipChunkWriter(IChunkWriter):
IMAGE_EXT = 'jpeg'
POINT_CLOUD_EXT = 'pcd'

def _write_pcd_file(self, image):
image_buf = open(image, "rb") if isinstance(image, str) else image
try:
properties = ValidateDimension.get_pcd_properties(image_buf)
w, h = int(properties["WIDTH"]), int(properties["HEIGHT"])
image_buf.seek(0, 0)
return io.BytesIO(image_buf.read()), self.POINT_CLOUD_EXT, w, h
finally:
if isinstance(image, str):
image_buf.close()

def save_as_chunk(self, images, chunk_path):
with zipfile.ZipFile(chunk_path, 'x') as zip_chunk:
for idx, (image, path, _) in enumerate(images):
arcname = '{:06d}{}'.format(idx, os.path.splitext(path)[1])
if isinstance(image, io.BytesIO):
zip_chunk.writestr(arcname, image.getvalue())
ext = os.path.splitext(path)[1]
output = io.BytesIO()
if self._dimension == DimensionType.DIM_2D:
pil_image = rotate_within_exif(Image.open(image))
pil_image.save(output, format=pil_image.format if pil_image.format else ext or self.IMAGE_EXT, quality=100, subsampling=0)
else:
zip_chunk.write(filename=image, arcname=arcname)
output, ext = self._write_pcd_file(image)[0:2]
arcname = '{:06d}.{}'.format(idx, ext)
zip_chunk.writestr(arcname, output.getvalue())
# return empty list because ZipChunkWriter write files as is
# and does not decode it to know img size.
return []

class ZipCompressedChunkWriter(IChunkWriter):
IMAGE_EXT = 'jpeg'
POINT_CLOUD_EXT = 'pcd'

class ZipCompressedChunkWriter(ZipChunkWriter):
def save_as_chunk(
self, images, chunk_path, *, compress_frames: bool = True, zip_compress_level: int = 0
):
Expand All @@ -680,12 +693,7 @@ def save_as_chunk(

extension = self.IMAGE_EXT
else:
image_buf = open(image, "rb") if isinstance(image, str) else image
properties = ValidateDimension.get_pcd_properties(image_buf)
w, h = int(properties["WIDTH"]), int(properties["HEIGHT"])
extension = self.POINT_CLOUD_EXT
image_buf.seek(0, 0)
image_buf = io.BytesIO(image_buf.read())
image_buf, extension, w, h = self._write_pcd_file(image)
image_sizes.append((w, h))
arcname = '{:06d}.{}'.format(idx, extension)
zip_chunk.writestr(arcname, image_buf.getvalue())
Expand Down
2 changes: 1 addition & 1 deletion cvat/apps/engine/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ def update_progress(progress):
if validate_dimension.dimension == models.DimensionType.DIM_3D:
kwargs["dimension"] = validate_dimension.dimension
compressed_chunk_writer = compressed_chunk_writer_class(db_data.image_quality, **kwargs)
original_chunk_writer = original_chunk_writer_class(original_quality)
original_chunk_writer = original_chunk_writer_class(original_quality, **kwargs)

# calculate chunk size if it isn't specified
if db_data.chunk_size is None:
Expand Down
Binary file modified cvat/apps/lambda_manager/static/lambda_manager/decoder.onnx
Binary file not shown.