-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88c87e0
commit d4722d4
Showing
5 changed files
with
83 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,58 @@ | ||
from .image_processing_base import ImageProcessingMixin | ||
# coding=utf-8 | ||
# Copyright 2022 The HuggingFace Inc. team. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from functools import cache | ||
|
||
class BaseImageProcessorFast(ImageProcessingMixin): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
from .image_processing_utils import BaseImageProcessor | ||
|
||
def __call__(self, images, **kwargs): | ||
return self.preprocess(images, **kwargs) | ||
|
||
def preprocess(self, images, **kwargs): | ||
class BaseImageProcessorFast(BaseImageProcessor): | ||
_transform_params = None | ||
|
||
def _set_transform_settings(self, **kwargs): | ||
settings = {} | ||
for k, v in kwargs.items(): | ||
if k not in self._transform_params: | ||
raise ValueError(f"Invalid transform parameter {k}={v}.") | ||
settings[k] = v | ||
self._transform_settings = settings | ||
|
||
def _same_transforms_settings(self, **kwargs): | ||
""" | ||
Check if the current settings are the same as the current transforms. | ||
""" | ||
for key, value in kwargs.items(): | ||
if value not in self._transform_settings or value != self._transform_settings[key]: | ||
return False | ||
return True | ||
|
||
def _build_transforms(self, **kwargs): | ||
raise NotImplementedError | ||
|
||
def set_transforms(self, **kwargs): | ||
# FIXME - put input validation or kwargs for all these methods | ||
|
||
if self._same_transforms_settings(**kwargs): | ||
return self._transforms | ||
|
||
transforms = self._build_transforms(**kwargs) | ||
self._set_transform_settings(**kwargs) | ||
self._transforms = transforms | ||
|
||
@cache | ||
def _maybe_update_transforms(self, **kwargs): | ||
if self._same_transforms_settings(**kwargs): | ||
return | ||
self.set_transforms(**kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters