未验证 提交 3b3f9ca6 编写于 作者: B Boris Sekachev 提交者: GitHub

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

<!-- 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.
上级 f87cce59
......@@ -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>)
......@@ -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
......
......@@ -31,7 +31,6 @@ from utils.dataset_manifest import VideoManifestManager, ImageManifestManager
ORIENTATION_EXIF_TAG = 274
class ORIENTATION(IntEnum):
NORMAL_HORIZONTAL=1
MIRROR_HORIZONTAL=2
......@@ -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):
......@@ -648,22 +646,37 @@ class IChunkWriter(ABC):
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
):
......@@ -680,12 +693,7 @@ class ZipCompressedChunkWriter(IChunkWriter):
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())
......
......@@ -897,7 +897,7 @@ def _create_thread(
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:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册