diff --git a/cvat/apps/engine/media_extractors.py b/cvat/apps/engine/media_extractors.py index fc57d08ac1a3..6e30ea9119d2 100644 --- a/cvat/apps/engine/media_extractors.py +++ b/cvat/apps/engine/media_extractors.py @@ -66,7 +66,7 @@ def image_names(self): pass @abstractmethod - def get_avg_image_size(self, percent_to_analize=10): + def get_avg_image_size(self): pass #Note step, start, stop have no affect @@ -97,15 +97,9 @@ def save_preview(self, preview_path): def image_names(self): return self._source_path - def get_avg_image_size(self, percent_to_analize=10): - widths = [] - heights = [] - step = 100 // percent_to_analize or 1 - for img_path in itertools.islice(self._source_path, 0, None, step): - img = Image.open(img_path) - widths.append(img.width) - heights.append(img.height) - return (sum(widths) // len(widths), sum(heights) // len(heights)) + def get_avg_image_size(self): + img = Image.open(self._source_path[0]) + return img.width, img.height #Note step, start, stop have no affect class DirectoryReader(ImageListReader): @@ -197,16 +191,9 @@ def save_preview(self, preview_path): with open(preview_path, 'wb') as f: f.write(self._zip_source.read(self._source_path[0])) - def get_avg_image_size(self, percent_to_analize=10): - widths = [] - heights = [] - step = 100 // percent_to_analize or 1 - for img_path in itertools.islice(self._source_path, 0, None, step): - img = Image.open(BytesIO(self._zip_source.read(img_path))) - widths.append(img.width) - heights.append(img.height) - return (sum(widths) // len(widths), sum(heights) // len(heights)) - + def get_avg_image_size(self): + img = Image.open(BytesIO(self._zip_source.read(self._source_path[0]))) + return img.width, img.height @property def image_names(self): @@ -259,9 +246,9 @@ def save_preview(self, preview_path): def image_names(self): return self._source_path - def get_avg_image_size(self, percent_to_analize=10): - first_image = (next(iter(self)))[0] - return first_image.width, first_image.height + def get_avg_image_size(self): + image = (next(iter(self)))[0] + return image.width, image.height class IChunkWriter(ABC): def __init__(self, quality): diff --git a/cvat/apps/engine/task.py b/cvat/apps/engine/task.py index e856c6644252..18a184d56063 100644 --- a/cvat/apps/engine/task.py +++ b/cvat/apps/engine/task.py @@ -254,19 +254,22 @@ def update_progress(progress): original_chunk_writer = original_chunk_writer_class(100) # calculate chunk size if it isn't specified - if db_data.chunk_size is None and isinstance(compressed_chunk_writer, ZipCompressedChunkWriter): - avg_w, avg_h = extractor.get_avg_image_size() - avg_area = avg_h * avg_w - if avg_area <= 1920 * 1080: - db_data.chunk_size = 36 - elif avg_area <= 2560 * 1440: - db_data.chunk_size = 18 - elif avg_area <= 3840 * 2160: - db_data.chunk_size = 9 - elif avg_area <= 5120 * 2880: - db_data.chunk_size = 4 + if db_data.chunk_size is None: + if isinstance(compressed_chunk_writer, ZipCompressedChunkWriter): + avg_w, avg_h = extractor.get_avg_image_size() + avg_area = avg_h * avg_w + if avg_area <= 1920 * 1080: + db_data.chunk_size = 36 + elif avg_area <= 2560 * 1440: + db_data.chunk_size = 18 + elif avg_area <= 3840 * 2160: + db_data.chunk_size = 9 + elif avg_area <= 5120 * 2880: + db_data.chunk_size = 4 + else: + db_data.chunk_size = 2 else: - db_data.chunk_size = 2 + db_data.chunk_size = 36 frame_counter = 0 total_len = len(extractor) or 100