"...git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "5469369480d01b357947ac938e6069e117d154d8"
Unverified Commit 8c4a1149 authored by amyeroberts's avatar amyeroberts Committed by GitHub
Browse files

Revert to and safely handle flag in owlvit config (#18750)

parent da5bb292
...@@ -131,7 +131,7 @@ class ImageFeatureExtractionMixin: ...@@ -131,7 +131,7 @@ class ImageFeatureExtractionMixin:
return image.convert("RGB") return image.convert("RGB")
def rescale_image(self, image: np.ndarray, scale: Union[float, int]) -> np.ndarray: def rescale(self, image: np.ndarray, scale: Union[float, int]) -> np.ndarray:
""" """
Rescale a numpy image by scale amount Rescale a numpy image by scale amount
""" """
...@@ -163,7 +163,7 @@ class ImageFeatureExtractionMixin: ...@@ -163,7 +163,7 @@ class ImageFeatureExtractionMixin:
rescale = isinstance(image.flat[0], np.integer) if rescale is None else rescale rescale = isinstance(image.flat[0], np.integer) if rescale is None else rescale
if rescale: if rescale:
image = self.rescale_image(image.astype(np.float32), 1 / 255.0) image = self.rescale(image.astype(np.float32), 1 / 255.0)
if channel_first and image.ndim == 3: if channel_first and image.ndim == 3:
image = image.transpose(2, 0, 1) image = image.transpose(2, 0, 1)
...@@ -214,9 +214,9 @@ class ImageFeatureExtractionMixin: ...@@ -214,9 +214,9 @@ class ImageFeatureExtractionMixin:
# type it may need rescaling. # type it may need rescaling.
elif rescale: elif rescale:
if isinstance(image, np.ndarray): if isinstance(image, np.ndarray):
image = self.rescale_image(image.astype(np.float32), 1 / 255.0) image = self.rescale(image.astype(np.float32), 1 / 255.0)
elif is_torch_tensor(image): elif is_torch_tensor(image):
image = self.rescale_image(image.float(), 1 / 255.0) image = self.rescale(image.float(), 1 / 255.0)
if isinstance(image, np.ndarray): if isinstance(image, np.ndarray):
if not isinstance(mean, np.ndarray): if not isinstance(mean, np.ndarray):
......
...@@ -85,6 +85,13 @@ class OwlViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin ...@@ -85,6 +85,13 @@ class OwlViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin
image_std=None, image_std=None,
**kwargs **kwargs
): ):
# Early versions of the OWL-ViT config on the hub had "rescale" as a flag. This clashes with the
# vision feature extractor method `rescale` as it would be set as an attribute during the super().__init__
# call. This is for backwards compatibility.
if "rescale" in kwargs:
rescale_val = kwargs.pop("rescale")
kwargs["do_rescale"] = rescale_val
super().__init__(**kwargs) super().__init__(**kwargs)
self.size = size self.size = size
self.resample = resample self.resample = resample
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment