Skip to content

Commit

Permalink
Accelerated SAM decoder, fixed serverless for EXIF rotated images (#6275
Browse files Browse the repository at this point in the history
)

<!-- Raise an issue to propose your change
(https://github.com/opencv/cvat/issues).
It helps to avoid duplication of efforts from multiple independent
contributors.
Discuss your ideas with maintainers to be sure that changes will be
approved and merged.
Read the [Contribution
guide](https://opencv.github.io/cvat/docs/contributing/). -->

<!-- Provide a general summary of your changes in the Title above -->
Removed extra interpolation layer

### Motivation and context
Fixed #6250

### How has this been tested?
<!-- Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc. -->

### Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply.
If an item isn't applicable for some reason, then ~~explicitly
strikethrough~~ the whole
line. If you don't do that, GitHub will show incorrect progress for the
pull request.
If you're unsure about any of these, don't hesitate to ask. We're here
to help! -->
- [x] I submit my changes into the `develop` branch
- [x] I have added a description of my changes into the
[CHANGELOG](https://github.com/opencv/cvat/blob/develop/CHANGELOG.md)
file
- [ ] I have updated the documentation accordingly
- [ ] I have added tests to cover my changes
- [x] I have linked related issues (see [GitHub docs](

https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword))
- [ ] I have increased versions of npm packages if it is necessary

([cvat-canvas](https://github.com/opencv/cvat/tree/develop/cvat-canvas#versioning),

[cvat-core](https://github.com/opencv/cvat/tree/develop/cvat-core#versioning),

[cvat-data](https://github.com/opencv/cvat/tree/develop/cvat-data#versioning)
and

[cvat-ui](https://github.com/opencv/cvat/tree/develop/cvat-ui#versioning))

### License

- [x] I submit _my code changes_ under the same [MIT License](
https://github.com/opencv/cvat/blob/develop/LICENSE) that covers the
project.
  Feel free to contact the maintainers if that's a concern.
  • Loading branch information
bsekachev authored Jun 13, 2023
1 parent f87cce5 commit 3b3f9ca
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
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.

0 comments on commit 3b3f9ca

Please sign in to comment.