Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
8c4a1149
Unverified
Commit
8c4a1149
authored
Aug 29, 2022
by
amyeroberts
Committed by
GitHub
Aug 29, 2022
Browse files
Revert to and safely handle flag in owlvit config (#18750)
parent
da5bb292
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
4 deletions
+11
-4
src/transformers/image_utils.py
src/transformers/image_utils.py
+4
-4
src/transformers/models/owlvit/feature_extraction_owlvit.py
src/transformers/models/owlvit/feature_extraction_owlvit.py
+7
-0
No files found.
src/transformers/image_utils.py
View file @
8c4a1149
...
@@ -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
):
...
...
src/transformers/models/owlvit/feature_extraction_owlvit.py
View file @
8c4a1149
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment