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
f6fa768f
Commit
f6fa768f
authored
8 years ago
by
tgupta6
Browse files
Options
Downloads
Patches
Plain Diff
multilabel_margin_loss
parent
98f2b8b5
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
losses.py
+15
-0
15 additions, 0 deletions
losses.py
with
15 additions
and
0 deletions
losses.py
+
15
−
0
View file @
f6fa768f
...
...
@@ -57,6 +57,21 @@ def margin_loss(y, y_pred, margin):
keep_dims
=
True
,
name
=
'
correct_score
'
)
return
tf
.
reduce_mean
(
tf
.
maximum
(
0.0
,
y_pred
+
margin
-
correct_score
))
def
multilabel_margin_loss
(
y
,
y_pred
,
margin
):
y_list
=
tf
.
unpack
(
y
)
y_pred_list
=
tf
.
unpack
(
y
):
loss
=
0.0
for
y_
,
y_pred_
in
zip
(
y_list
,
y_pred_list
):
partition
=
tf
.
dynamic_partition
(
y_pred_
,
y_
,
2
)
pos_labels_scores
=
tf
.
expand_dims
(
tf
.
transpose
(
partition
[
1
]),
1
)
neg_labels_scores
=
partition
[
0
]
margin_violation
=
tf
.
maximum
(
0
,
neg
-
labels_scores
+
margin
-
pos_labels_scores
)
loss
+=
tf
.
reduce_mean
(
margin_violation
)
loss
/=
len
(
y_list
)
return
loss
def
mil_loss
(
scores
,
y
,
type
=
'
obj
'
,
epsilon
=
1e-5
):
if
type
==
'
obj
'
:
log_prob
=
tf
.
nn
.
log_softmax
(
scores
)
...
...
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