Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GenVQA
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vision
GenVQA
Commits
f290b6ef
Commit
f290b6ef
authored
8 years ago
by
tgupta6
Browse files
Options
Downloads
Patches
Plain Diff
added metrics for object classification performance
parent
a0c4b8aa
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
metrics.py
+25
-0
25 additions, 0 deletions
metrics.py
with
25 additions
and
0 deletions
metrics.py
0 → 100644
+
25
−
0
View file @
f290b6ef
def
fraction_in_top_k
(
y
,
y_pred
):
y_list
=
tf
.
unpack
(
y
)
y_pred_list
=
tf
.
unpack
(
y_pred
)
accuracy
=
0.0
for
y_
,
y_pred_
in
zip
(
y_list
,
y_pred_list
):
k
=
tf
.
reduce_sum
(
y_
)
pos_label_ids
=
tf
.
nn
.
top_k
(
y_
,
k
)
pos_label_ids_list
=
tf
.
unpack
(
pos_label_ids
)
num_pos_labels_in_top_k
=
0.0
for
pos_label_id
in
pos_label_ids_list
:
is_present
=
tf
.
nn
.
in_top_k
(
y_pred_
,
pos_label_id
,
k
)
num_pos_labels_in_top_k
+=
tf
.
cast
(
is_present
,
tf
.
float32
)
frac_pos_labels_in_top_k
=
num_pos_labels_in_top_k
/
tf
.
maximum
(
k
,
1e-5
)
accuracy
+=
frac_pos_labels_in_top_k
accuracy
/=
len
(
y_list
)
return
accuracy
def
presence_in_top_k
(
y
,
y_pred
,
k
):
max_ids
=
tf
.
argmax
(
y
,
1
)
is_present
=
tf
.
nn
.
in_top_k
(
y_pred
,
max_ids
,
k
)
is_present
=
tf
.
cast
(
is_present
,
tf
.
float32
)
return
tf
.
reduce_mean
(
is_present
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment