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
OpenDAS
vision
Commits
5ba57eae
Unverified
Commit
5ba57eae
authored
May 26, 2020
by
eellison
Committed by
GitHub
May 27, 2020
Browse files
Clean up no longer needed workarorudns (#2261)
Co-authored-by:
eellison
<
eellison@fb.com
>
parent
3974cfeb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
19 deletions
+12
-19
torchvision/models/detection/_utils.py
torchvision/models/detection/_utils.py
+6
-13
torchvision/models/detection/roi_heads.py
torchvision/models/detection/roi_heads.py
+4
-4
torchvision/models/detection/rpn.py
torchvision/models/detection/rpn.py
+2
-2
No files found.
torchvision/models/detection/_utils.py
View file @
5ba57eae
...
...
@@ -6,13 +6,6 @@ from torch import Tensor
import
torchvision
# TODO: https://github.com/pytorch/pytorch/issues/26727
def
zeros_like
(
tensor
,
dtype
):
# type: (Tensor, int) -> Tensor
return
torch
.
zeros_like
(
tensor
,
dtype
=
dtype
,
layout
=
tensor
.
layout
,
device
=
tensor
.
device
,
pin_memory
=
tensor
.
is_pinned
())
class
BalancedPositiveNegativeSampler
(
object
):
"""
This class samples batches, ensuring that they contain a fixed proportion of positives
...
...
@@ -66,15 +59,15 @@ class BalancedPositiveNegativeSampler(object):
neg_idx_per_image
=
negative
[
perm2
]
# create binary mask from indices
pos_idx_per_image_mask
=
zeros_like
(
pos_idx_per_image_mask
=
torch
.
zeros_like
(
matched_idxs_per_image
,
dtype
=
torch
.
uint8
)
neg_idx_per_image_mask
=
zeros_like
(
neg_idx_per_image_mask
=
torch
.
zeros_like
(
matched_idxs_per_image
,
dtype
=
torch
.
uint8
)
pos_idx_per_image_mask
[
pos_idx_per_image
]
=
torch
.
tensor
(
1
,
dtype
=
torch
.
uint8
)
neg_idx_per_image_mask
[
neg_idx_per_image
]
=
torch
.
tensor
(
1
,
dtype
=
torch
.
uint8
)
pos_idx_per_image_mask
[
pos_idx_per_image
]
=
1
neg_idx_per_image_mask
[
neg_idx_per_image
]
=
1
pos_idx
.
append
(
pos_idx_per_image_mask
)
neg_idx
.
append
(
neg_idx_per_image_mask
)
...
...
@@ -304,8 +297,8 @@ class Matcher(object):
between_thresholds
=
(
matched_vals
>=
self
.
low_threshold
)
&
(
matched_vals
<
self
.
high_threshold
)
matches
[
below_low_threshold
]
=
torch
.
tensor
(
self
.
BELOW_LOW_THRESHOLD
)
matches
[
between_thresholds
]
=
torch
.
tensor
(
self
.
BETWEEN_THRESHOLDS
)
matches
[
below_low_threshold
]
=
self
.
BELOW_LOW_THRESHOLD
matches
[
between_thresholds
]
=
self
.
BETWEEN_THRESHOLDS
if
self
.
allow_low_quality_matches
:
assert
all_matches
is
not
None
...
...
torchvision/models/detection/roi_heads.py
View file @
5ba57eae
...
...
@@ -155,8 +155,8 @@ def keypoints_to_heatmap(keypoints, rois, heatmap_size):
y
=
(
y
-
offset_y
)
*
scale_y
y
=
y
.
floor
().
long
()
x
[
x_boundary_inds
]
=
torch
.
tensor
(
heatmap_size
-
1
)
y
[
y_boundary_inds
]
=
torch
.
tensor
(
heatmap_size
-
1
)
x
[
x_boundary_inds
]
=
heatmap_size
-
1
y
[
y_boundary_inds
]
=
heatmap_size
-
1
valid_loc
=
(
x
>=
0
)
&
(
y
>=
0
)
&
(
x
<
heatmap_size
)
&
(
y
<
heatmap_size
)
vis
=
keypoints
[...,
2
]
>
0
...
...
@@ -584,11 +584,11 @@ class RoIHeads(torch.nn.Module):
# Label background (below the low threshold)
bg_inds
=
matched_idxs_in_image
==
self
.
proposal_matcher
.
BELOW_LOW_THRESHOLD
labels_in_image
[
bg_inds
]
=
torch
.
tensor
(
0
)
labels_in_image
[
bg_inds
]
=
0
# Label ignore proposals (between low and high thresholds)
ignore_inds
=
matched_idxs_in_image
==
self
.
proposal_matcher
.
BETWEEN_THRESHOLDS
labels_in_image
[
ignore_inds
]
=
torch
.
tensor
(
-
1
)
# -1 is ignored by sampler
labels_in_image
[
ignore_inds
]
=
-
1
# -1 is ignored by sampler
matched_idxs
.
append
(
clamped_matched_idxs_in_image
)
labels
.
append
(
labels_in_image
)
...
...
torchvision/models/detection/rpn.py
View file @
5ba57eae
...
...
@@ -350,11 +350,11 @@ class RegionProposalNetwork(torch.nn.Module):
# Background (negative examples)
bg_indices
=
matched_idxs
==
self
.
proposal_matcher
.
BELOW_LOW_THRESHOLD
labels_per_image
[
bg_indices
]
=
torch
.
tensor
(
0.0
)
labels_per_image
[
bg_indices
]
=
0.0
# discard indices that are between thresholds
inds_to_discard
=
matched_idxs
==
self
.
proposal_matcher
.
BETWEEN_THRESHOLDS
labels_per_image
[
inds_to_discard
]
=
torch
.
tensor
(
-
1.0
)
labels_per_image
[
inds_to_discard
]
=
-
1.0
labels
.
append
(
labels_per_image
)
matched_gt_boxes
.
append
(
matched_gt_boxes_per_image
)
...
...
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