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
24124709
Unverified
Commit
24124709
authored
Dec 05, 2022
by
Yih-Dar
Committed by
GitHub
Dec 05, 2022
Browse files
Fix torch device issues (#20584)
Co-authored-by:
ydshieh
<
ydshieh@users.noreply.github.com
>
parent
699e9043
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
4 deletions
+4
-4
src/transformers/models/conditional_detr/image_processing_conditional_detr.py
...els/conditional_detr/image_processing_conditional_detr.py
+2
-2
src/transformers/models/deformable_detr/image_processing_deformable_detr.py
...odels/deformable_detr/image_processing_deformable_detr.py
+2
-2
No files found.
src/transformers/models/conditional_detr/image_processing_conditional_detr.py
View file @
24124709
...
@@ -1290,7 +1290,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
...
@@ -1290,7 +1290,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
# and from relative [0, 1] to absolute [0, height] coordinates
# and from relative [0, 1] to absolute [0, height] coordinates
img_h
,
img_w
=
target_sizes
.
unbind
(
1
)
img_h
,
img_w
=
target_sizes
.
unbind
(
1
)
scale_fct
=
torch
.
stack
([
img_w
,
img_h
,
img_w
,
img_h
],
dim
=
1
)
.
to
(
boxes
.
device
)
scale_fct
=
torch
.
stack
([
img_w
,
img_h
,
img_w
,
img_h
],
dim
=
1
)
boxes
=
boxes
*
scale_fct
[:,
None
,
:]
boxes
=
boxes
*
scale_fct
[:,
None
,
:]
results
=
[{
"scores"
:
s
,
"labels"
:
l
,
"boxes"
:
b
}
for
s
,
l
,
b
in
zip
(
scores
,
labels
,
boxes
)]
results
=
[{
"scores"
:
s
,
"labels"
:
l
,
"boxes"
:
b
}
for
s
,
l
,
b
in
zip
(
scores
,
labels
,
boxes
)]
...
@@ -1340,7 +1340,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
...
@@ -1340,7 +1340,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
img_w
=
torch
.
Tensor
([
i
[
1
]
for
i
in
target_sizes
])
img_w
=
torch
.
Tensor
([
i
[
1
]
for
i
in
target_sizes
])
else
:
else
:
img_h
,
img_w
=
target_sizes
.
unbind
(
1
)
img_h
,
img_w
=
target_sizes
.
unbind
(
1
)
scale_fct
=
torch
.
stack
([
img_w
,
img_h
,
img_w
,
img_h
],
dim
=
1
)
scale_fct
=
torch
.
stack
([
img_w
,
img_h
,
img_w
,
img_h
],
dim
=
1
)
.
to
(
boxes
.
device
)
boxes
=
boxes
*
scale_fct
[:,
None
,
:]
boxes
=
boxes
*
scale_fct
[:,
None
,
:]
results
=
[]
results
=
[]
...
...
src/transformers/models/deformable_detr/image_processing_deformable_detr.py
View file @
24124709
...
@@ -1288,7 +1288,7 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
...
@@ -1288,7 +1288,7 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
# and from relative [0, 1] to absolute [0, height] coordinates
# and from relative [0, 1] to absolute [0, height] coordinates
img_h
,
img_w
=
target_sizes
.
unbind
(
1
)
img_h
,
img_w
=
target_sizes
.
unbind
(
1
)
scale_fct
=
torch
.
stack
([
img_w
,
img_h
,
img_w
,
img_h
],
dim
=
1
)
.
to
(
boxes
.
device
)
scale_fct
=
torch
.
stack
([
img_w
,
img_h
,
img_w
,
img_h
],
dim
=
1
)
boxes
=
boxes
*
scale_fct
[:,
None
,
:]
boxes
=
boxes
*
scale_fct
[:,
None
,
:]
results
=
[{
"scores"
:
s
,
"labels"
:
l
,
"boxes"
:
b
}
for
s
,
l
,
b
in
zip
(
scores
,
labels
,
boxes
)]
results
=
[{
"scores"
:
s
,
"labels"
:
l
,
"boxes"
:
b
}
for
s
,
l
,
b
in
zip
(
scores
,
labels
,
boxes
)]
...
@@ -1337,7 +1337,7 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
...
@@ -1337,7 +1337,7 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
img_w
=
torch
.
Tensor
([
i
[
1
]
for
i
in
target_sizes
])
img_w
=
torch
.
Tensor
([
i
[
1
]
for
i
in
target_sizes
])
else
:
else
:
img_h
,
img_w
=
target_sizes
.
unbind
(
1
)
img_h
,
img_w
=
target_sizes
.
unbind
(
1
)
scale_fct
=
torch
.
stack
([
img_w
,
img_h
,
img_w
,
img_h
],
dim
=
1
)
scale_fct
=
torch
.
stack
([
img_w
,
img_h
,
img_w
,
img_h
],
dim
=
1
)
.
to
(
boxes
.
device
)
boxes
=
boxes
*
scale_fct
[:,
None
,
:]
boxes
=
boxes
*
scale_fct
[:,
None
,
:]
results
=
[]
results
=
[]
...
...
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