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
83ae348b
Commit
83ae348b
authored
Jun 14, 2022
by
SunJong Park
Browse files
eval_utils unittest, typo bug fixed
parent
aef943ed
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
3 deletions
+103
-3
official/projects/yt8m/configs/yt8m_test.py
official/projects/yt8m/configs/yt8m_test.py
+1
-1
official/projects/yt8m/dataloaders/yt8m_input.py
official/projects/yt8m/dataloaders/yt8m_input.py
+1
-1
official/projects/yt8m/eval_utils/average_precision_calculator.py
.../projects/yt8m/eval_utils/average_precision_calculator.py
+2
-1
official/projects/yt8m/eval_utils/eval_util_test.py
official/projects/yt8m/eval_utils/eval_util_test.py
+99
-0
No files found.
official/projects/yt8m/configs/yt8m_test.py
View file @
83ae348b
...
...
@@ -26,7 +26,7 @@ class YT8MTest(tf.test.TestCase, parameterized.TestCase):
@
parameterized
.
parameters
(
(
'yt8m_experiment'
,),)
def
test_
assemblenet
_configs
(
self
,
config_name
):
def
test_
yt8m
_configs
(
self
,
config_name
):
config
=
exp_factory
.
get_exp_config
(
config_name
)
self
.
assertIsInstance
(
config
,
cfg
.
ExperimentConfig
)
self
.
assertIsInstance
(
config
.
task
,
cfg
.
TaskConfig
)
...
...
official/projects/yt8m/dataloaders/yt8m_input.py
View file @
83ae348b
...
...
@@ -176,7 +176,7 @@ def _get_video_matrix(features, feature_size, dtype, max_frames,
num_frames
=
tf
.
math
.
minimum
(
tf
.
shape
(
decoded_features
)[
0
],
max_frames
)
if
dtype
.
is_integer
:
feature_matrix
=
utils
.
D
equantize
(
decoded_features
,
max_quantized_value
,
feature_matrix
=
utils
.
d
equantize
(
decoded_features
,
max_quantized_value
,
min_quantized_value
)
else
:
feature_matrix
=
decoded_features
...
...
official/projects/yt8m/eval_utils/average_precision_calculator.py
View file @
83ae348b
...
...
@@ -268,6 +268,7 @@ class AveragePrecisionCalculator(object):
The normalized prediction.
"""
denominator
=
numpy
.
max
(
predictions
)
-
numpy
.
min
(
predictions
)
ret
=
(
predictions
-
numpy
.
min
(
predictions
))
/
numpy
.
max
(
tmp
=
predictions
-
numpy
.
min
(
predictions
)
ret
=
(
predictions
-
numpy
.
min
(
predictions
))
/
max
(
denominator
,
epsilon
)
return
ret
official/projects/yt8m/eval_utils/eval_util_test.py
0 → 100644
View file @
83ae348b
# Copyright 2022 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Lint as: python3
from
absl.testing
import
parameterized
from
absl
import
logging
import
tensorflow
as
tf
from
official.projects.yt8m.eval_utils.average_precision_calculator
import
AveragePrecisionCalculator
import
numpy
as
np
from
official.projects.yt8m.eval_utils.eval_util
import
calculate_precision_at_equal_recall_rate
'''
p = np.array([random.random() for _ in xrange(10)])
a = np.array([random.choice([0, 1]) for _ in xrange(10)])
ap = average_precision_calculator.AveragePrecisionCalculator.ap(p, a)
p1 = np.array([random.random() for _ in xrange(5)])
a1 = np.array([random.choice([0, 1]) for _ in xrange(5)])
p2 = np.array([random.random() for _ in xrange(5)])
a2 = np.array([random.choice([0, 1]) for _ in xrange(5)])
# interpolated average precision at 10 using 1000 break points
calculator = average_precision_calculator.AveragePrecisionCalculator(10)
calculator.accumulate(p1, a1)
calculator.accumulate(p2, a2)
ap3 = calculator.peek_ap_at_n()
'''
class
YT8MAveragePrecisionCalculatorTest
(
parameterized
.
TestCase
,
tf
.
test
.
TestCase
):
def
setUp
(
self
):
super
().
setUp
()
self
.
prediction
=
np
.
array
([
[
0.98
,
0.88
,
0.77
,
0.65
,
0.64
,
0.59
,
0.45
,
0.43
,
0.20
,
0.05
],
[
0.878
,
0.832
,
0.759
,
0.621
,
0.458
,
0.285
,
0.134
],
[
0.98
],
[
0.56
],
])
self
.
raw_prediction
=
np
.
random
.
rand
(
5
,
10
)
+
\
np
.
random
.
randint
(
low
=
0
,
high
=
10
,
size
=
(
5
,
10
))
self
.
ground_truth
=
np
.
array
([
[
1
,
1
,
0
,
0
,
0
,
1
,
1
,
0
,
0
,
1
],
[
1
,
0
,
1
,
0
,
0
,
1
,
0
],
[
1
],
[
0
]
])
self
.
expected_ap
=
np
.
array
([
0.714
,
0.722
,
1.000
,
0.000
,
])
# self.prediction_expand = np.random.rand(10)
# self.ground_truth_expand = np.random.choice(2,10,True)
def
test_ap_calculator_ap
(
self
):
# Compare Expected Average Precision with function expected
for
i
,
_
in
enumerate
(
self
.
ground_truth
):
calculator
=
AveragePrecisionCalculator
()
ap
=
calculator
.
ap
(
self
.
prediction
[
i
],
self
.
ground_truth
[
i
])
self
.
assertNear
(
ap
,
self
.
expected_ap
[
i
],
err
=
1e-3
)
logging
.
info
(
f
'DEBUG
{
i
+
1
}
th AP:
{
ap
}
'
)
def
test_ap_calculator_zero_one_normalize
(
self
):
for
i
,
_
in
enumerate
(
self
.
raw_prediction
):
calculator
=
AveragePrecisionCalculator
()
logging
.
error
(
f
'
{
self
.
raw_prediction
[
i
]
}
'
)
normalized_score
=
calculator
.
_zero_one_normalize
(
self
.
raw_prediction
[
i
])
self
.
assertAllInRange
(
normalized_score
,
lower_bound
=
0.0
,
upper_bound
=
1.0
)
@
parameterized
.
parameters
(
(
None
,
None
),
(
3
,
None
),
(
5
,
None
),
(
10
,
None
),
(
20
,
None
)
)
def
test_ap_calculator_ap_at_n
(
self
,
n
,
total_num_positives
):
for
i
,
_
in
enumerate
(
self
.
ground_truth
):
calculator
=
AveragePrecisionCalculator
(
n
)
ap
=
calculator
.
ap_at_n
(
self
.
prediction
[
i
],
self
.
ground_truth
[
i
],
n
)
logging
.
info
(
f
'DEBUG
{
i
+
1
}
th AP:
{
ap
}
'
)
if
__name__
==
'__main__'
:
tf
.
test
.
main
()
\ No newline at end of file
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