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
ModelZoo
ResNet50_tensorflow
Commits
5e5e6f6e
Commit
5e5e6f6e
authored
Apr 22, 2022
by
A. Unique TensorFlower
Browse files
Internal change
PiperOrigin-RevId: 443735362
parent
14c32065
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
official/vision/utils/object_detection/balanced_positive_negative_sampler.py
...ls/object_detection/balanced_positive_negative_sampler.py
+6
-4
No files found.
official/vision/utils/object_detection/balanced_positive_negative_sampler.py
View file @
5e5e6f6e
...
@@ -77,8 +77,8 @@ class BalancedPositiveNegativeSampler(minibatch_sampler.MinibatchSampler):
...
@@ -77,8 +77,8 @@ class BalancedPositiveNegativeSampler(minibatch_sampler.MinibatchSampler):
tf
.
zeros
(
input_length
,
tf
.
int32
))
tf
.
zeros
(
input_length
,
tf
.
int32
))
num_sampled_pos
=
tf
.
reduce_sum
(
num_sampled_pos
=
tf
.
reduce_sum
(
input_tensor
=
tf
.
cast
(
valid_positive_index
,
tf
.
int32
))
input_tensor
=
tf
.
cast
(
valid_positive_index
,
tf
.
int32
))
max_num_positive_samples
=
tf
.
c
onstan
t
(
max_num_positive_samples
=
tf
.
c
as
t
(
in
t
(
sample_size
*
self
.
_positive_fraction
)
,
tf
.
int32
)
tf
.
cas
t
(
sample_size
,
tf
.
float32
)
*
self
.
_positive_fraction
,
tf
.
int32
)
num_positive_samples
=
tf
.
minimum
(
max_num_positive_samples
,
num_sampled_pos
)
num_positive_samples
=
tf
.
minimum
(
max_num_positive_samples
,
num_sampled_pos
)
num_negative_samples
=
tf
.
constant
(
sample_size
,
num_negative_samples
=
tf
.
constant
(
sample_size
,
tf
.
int32
)
-
num_positive_samples
tf
.
int32
)
-
num_positive_samples
...
@@ -219,7 +219,7 @@ class BalancedPositiveNegativeSampler(minibatch_sampler.MinibatchSampler):
...
@@ -219,7 +219,7 @@ class BalancedPositiveNegativeSampler(minibatch_sampler.MinibatchSampler):
indicator: boolean tensor of shape [N] whose True entries can be sampled.
indicator: boolean tensor of shape [N] whose True entries can be sampled.
batch_size: desired batch size. If None, keeps all positive samples and
batch_size: desired batch size. If None, keeps all positive samples and
randomly selects negative samples so that the positive sample fraction
randomly selects negative samples so that the positive sample fraction
matches self._positive_fraction. It cannot be None i
s
is_static is True.
matches self._positive_fraction. It cannot be None i
f
is_static is True.
labels: boolean tensor of shape [N] denoting positive(=True) and negative
labels: boolean tensor of shape [N] denoting positive(=True) and negative
(=False) examples.
(=False) examples.
scope: name scope.
scope: name scope.
...
@@ -259,7 +259,9 @@ class BalancedPositiveNegativeSampler(minibatch_sampler.MinibatchSampler):
...
@@ -259,7 +259,9 @@ class BalancedPositiveNegativeSampler(minibatch_sampler.MinibatchSampler):
max_num_pos
=
tf
.
reduce_sum
(
max_num_pos
=
tf
.
reduce_sum
(
input_tensor
=
tf
.
cast
(
positive_idx
,
dtype
=
tf
.
int32
))
input_tensor
=
tf
.
cast
(
positive_idx
,
dtype
=
tf
.
int32
))
else
:
else
:
max_num_pos
=
int
(
self
.
_positive_fraction
*
batch_size
)
max_num_pos
=
tf
.
cast
(
self
.
_positive_fraction
*
tf
.
cast
(
batch_size
,
tf
.
float32
),
tf
.
int32
)
sampled_pos_idx
=
self
.
subsample_indicator
(
positive_idx
,
max_num_pos
)
sampled_pos_idx
=
self
.
subsample_indicator
(
positive_idx
,
max_num_pos
)
num_sampled_pos
=
tf
.
reduce_sum
(
num_sampled_pos
=
tf
.
reduce_sum
(
input_tensor
=
tf
.
cast
(
sampled_pos_idx
,
tf
.
int32
))
input_tensor
=
tf
.
cast
(
sampled_pos_idx
,
tf
.
int32
))
...
...
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