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
fe01ec34
Unverified
Commit
fe01ec34
authored
Sep 23, 2022
by
Alara Dirik
Committed by
GitHub
Sep 23, 2022
Browse files
Detr preprocessor fix (#19007)
* fix in-place preprocessing of inputs
parent
7e84723f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
0 deletions
+24
-0
src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
...s/conditional_detr/feature_extraction_conditional_detr.py
+8
-0
src/transformers/models/deformable_detr/feature_extraction_deformable_detr.py
...els/deformable_detr/feature_extraction_deformable_detr.py
+8
-0
src/transformers/models/detr/feature_extraction_detr.py
src/transformers/models/detr/feature_extraction_detr.py
+8
-0
No files found.
src/transformers/models/conditional_detr/feature_extraction_conditional_detr.py
View file @
fe01ec34
...
@@ -555,6 +555,12 @@ class ConditionalDetrFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtrac
...
@@ -555,6 +555,12 @@ class ConditionalDetrFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtrac
if
annotations
is
not
None
:
if
annotations
is
not
None
:
annotations
=
[
annotations
]
annotations
=
[
annotations
]
# Create deep copies to avoid editing inputs in place
images
=
[
image
for
image
in
images
]
if
annotations
is
not
None
:
annotations
=
[
annotation
for
annotation
in
annotations
]
# prepare (COCO annotations as a list of Dict -> ConditionalDETR target as a single Dict per image)
# prepare (COCO annotations as a list of Dict -> ConditionalDETR target as a single Dict per image)
if
annotations
is
not
None
:
if
annotations
is
not
None
:
for
idx
,
(
image
,
target
)
in
enumerate
(
zip
(
images
,
annotations
)):
for
idx
,
(
image
,
target
)
in
enumerate
(
zip
(
images
,
annotations
)):
...
@@ -587,6 +593,8 @@ class ConditionalDetrFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtrac
...
@@ -587,6 +593,8 @@ class ConditionalDetrFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtrac
images
=
[
images
=
[
self
.
_normalize
(
image
=
image
,
mean
=
self
.
image_mean
,
std
=
self
.
image_std
)[
0
]
for
image
in
images
self
.
_normalize
(
image
=
image
,
mean
=
self
.
image_mean
,
std
=
self
.
image_std
)[
0
]
for
image
in
images
]
]
else
:
images
=
[
np
.
array
(
image
)
for
image
in
images
]
if
pad_and_return_pixel_mask
:
if
pad_and_return_pixel_mask
:
# pad images up to largest image in batch and create pixel_mask
# pad images up to largest image in batch and create pixel_mask
...
...
src/transformers/models/deformable_detr/feature_extraction_deformable_detr.py
View file @
fe01ec34
...
@@ -555,6 +555,12 @@ class DeformableDetrFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtract
...
@@ -555,6 +555,12 @@ class DeformableDetrFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtract
if
annotations
is
not
None
:
if
annotations
is
not
None
:
annotations
=
[
annotations
]
annotations
=
[
annotations
]
# Create deep copies to avoid editing inputs in place
images
=
[
image
for
image
in
images
]
if
annotations
is
not
None
:
annotations
=
[
annotation
for
annotation
in
annotations
]
# prepare (COCO annotations as a list of Dict -> DETR target as a single Dict per image)
# prepare (COCO annotations as a list of Dict -> DETR target as a single Dict per image)
if
annotations
is
not
None
:
if
annotations
is
not
None
:
for
idx
,
(
image
,
target
)
in
enumerate
(
zip
(
images
,
annotations
)):
for
idx
,
(
image
,
target
)
in
enumerate
(
zip
(
images
,
annotations
)):
...
@@ -587,6 +593,8 @@ class DeformableDetrFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtract
...
@@ -587,6 +593,8 @@ class DeformableDetrFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtract
images
=
[
images
=
[
self
.
_normalize
(
image
=
image
,
mean
=
self
.
image_mean
,
std
=
self
.
image_std
)[
0
]
for
image
in
images
self
.
_normalize
(
image
=
image
,
mean
=
self
.
image_mean
,
std
=
self
.
image_std
)[
0
]
for
image
in
images
]
]
else
:
images
=
[
np
.
array
(
image
)
for
image
in
images
]
if
pad_and_return_pixel_mask
:
if
pad_and_return_pixel_mask
:
# pad images up to largest image in batch and create pixel_mask
# pad images up to largest image in batch and create pixel_mask
...
...
src/transformers/models/detr/feature_extraction_detr.py
View file @
fe01ec34
...
@@ -547,6 +547,12 @@ class DetrFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin):
...
@@ -547,6 +547,12 @@ class DetrFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin):
if
annotations
is
not
None
:
if
annotations
is
not
None
:
annotations
=
[
annotations
]
annotations
=
[
annotations
]
# Create deep copies to avoid editing inputs in place
images
=
[
image
for
image
in
images
]
if
annotations
is
not
None
:
annotations
=
[
annotation
for
annotation
in
annotations
]
# prepare (COCO annotations as a list of Dict -> DETR target as a single Dict per image)
# prepare (COCO annotations as a list of Dict -> DETR target as a single Dict per image)
if
annotations
is
not
None
:
if
annotations
is
not
None
:
for
idx
,
(
image
,
target
)
in
enumerate
(
zip
(
images
,
annotations
)):
for
idx
,
(
image
,
target
)
in
enumerate
(
zip
(
images
,
annotations
)):
...
@@ -579,6 +585,8 @@ class DetrFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin):
...
@@ -579,6 +585,8 @@ class DetrFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin):
images
=
[
images
=
[
self
.
_normalize
(
image
=
image
,
mean
=
self
.
image_mean
,
std
=
self
.
image_std
)[
0
]
for
image
in
images
self
.
_normalize
(
image
=
image
,
mean
=
self
.
image_mean
,
std
=
self
.
image_std
)[
0
]
for
image
in
images
]
]
else
:
images
=
[
np
.
array
(
image
)
for
image
in
images
]
if
pad_and_return_pixel_mask
:
if
pad_and_return_pixel_mask
:
# pad images up to largest image in batch and create pixel_mask
# pad images up to largest image in batch and create pixel_mask
...
...
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