Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.learn.tensorflow
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.learn.tensorflow
Commits
e155ed50
Commit
e155ed50
authored
5 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Patches
Plain Diff
improve logging in losses
parent
036a308f
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!79
Add keras-based models, add pixel-wise loss, other improvements
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bob/learn/tensorflow/loss/StyleLoss.py
+4
-4
4 additions, 4 deletions
bob/learn/tensorflow/loss/StyleLoss.py
bob/learn/tensorflow/loss/TripletLoss.py
+3
-8
3 additions, 8 deletions
bob/learn/tensorflow/loss/TripletLoss.py
with
7 additions
and
12 deletions
bob/learn/tensorflow/loss/StyleLoss.py
+
4
−
4
View file @
e155ed50
...
@@ -4,8 +4,8 @@
...
@@ -4,8 +4,8 @@
import
logging
import
logging
import
tensorflow
as
tf
import
tensorflow
as
tf
logger
=
logging
.
getLogger
(
"
bob.learn.tensorflow
"
)
import
functools
import
functools
logger
=
logging
.
getLogger
(
"
bob.learn.tensorflow
"
)
def
content_loss
(
noises
,
content_features
):
def
content_loss
(
noises
,
content_features
):
...
@@ -24,7 +24,7 @@ def content_loss(noises, content_features):
...
@@ -24,7 +24,7 @@ def content_loss(noises, content_features):
----------
----------
noises: :any:`list`
noises: :any:`list`
A list of tf.Tensor containing all the noises convolved
A list of tf.Tensor containing all the noises convolved
content_features: :any:`list`
content_features: :any:`list`
A list of numpy.array containing all the content_features convolved
A list of numpy.array containing all the content_features convolved
...
@@ -36,7 +36,7 @@ def content_loss(noises, content_features):
...
@@ -36,7 +36,7 @@ def content_loss(noises, content_features):
content_losses
.
append
((
2
*
tf
.
nn
.
l2_loss
(
n
-
c
)
/
c
.
size
))
content_losses
.
append
((
2
*
tf
.
nn
.
l2_loss
(
n
-
c
)
/
c
.
size
))
return
functools
.
reduce
(
tf
.
add
,
content_losses
)
return
functools
.
reduce
(
tf
.
add
,
content_losses
)
def
linear_gram_style_loss
(
noises
,
gram_style_features
):
def
linear_gram_style_loss
(
noises
,
gram_style_features
):
"""
"""
...
@@ -89,7 +89,7 @@ def denoising_loss(noise):
...
@@ -89,7 +89,7 @@ def denoising_loss(noise):
noise_y_size
=
_tensor_size
(
noise
[:,
1
:,:,:])
noise_y_size
=
_tensor_size
(
noise
[:,
1
:,:,:])
noise_x_size
=
_tensor_size
(
noise
[:,:,
1
:,:])
noise_x_size
=
_tensor_size
(
noise
[:,:,
1
:,:])
denoise_loss
=
2
*
(
(
tf
.
nn
.
l2_loss
(
noise
[:,
1
:,:,:]
-
noise
[:,:
shape
[
1
]
-
1
,:,:])
/
noise_y_size
)
+
denoise_loss
=
2
*
(
(
tf
.
nn
.
l2_loss
(
noise
[:,
1
:,:,:]
-
noise
[:,:
shape
[
1
]
-
1
,:,:])
/
noise_y_size
)
+
(
tf
.
nn
.
l2_loss
(
noise
[:,:,
1
:,:]
-
noise
[:,:,:
shape
[
2
]
-
1
,:])
/
noise_x_size
))
(
tf
.
nn
.
l2_loss
(
noise
[:,:,
1
:,:]
-
noise
[:,:,:
shape
[
2
]
-
1
,:])
/
noise_x_size
))
return
denoise_loss
return
denoise_loss
...
...
This diff is collapsed.
Click to expand it.
bob/learn/tensorflow/loss/TripletLoss.py
+
3
−
8
View file @
e155ed50
...
@@ -57,24 +57,19 @@ def triplet_loss(anchor_embedding,
...
@@ -57,24 +57,19 @@ def triplet_loss(anchor_embedding,
with
tf
.
name_scope
(
"
TripletLoss
"
):
with
tf
.
name_scope
(
"
TripletLoss
"
):
# Between
# Between
between_class_loss
=
tf
.
reduce_mean
(
d_negative
)
between_class_loss
=
tf
.
reduce_mean
(
d_negative
)
tf
.
summary
.
scalar
(
'
between_class
'
,
between_class_loss
)
tf
.
summary
.
scalar
(
'
loss_
between_class
'
,
between_class_loss
)
tf
.
add_to_collection
(
tf
.
GraphKeys
.
LOSSES
,
between_class_loss
)
tf
.
add_to_collection
(
tf
.
GraphKeys
.
LOSSES
,
between_class_loss
)
# Within
# Within
within_class_loss
=
tf
.
reduce_mean
(
d_positive
)
within_class_loss
=
tf
.
reduce_mean
(
d_positive
)
tf
.
summary
.
scalar
(
'
within_class
'
,
within_class_loss
)
tf
.
summary
.
scalar
(
'
loss_
within_class
'
,
within_class_loss
)
tf
.
add_to_collection
(
tf
.
GraphKeys
.
LOSSES
,
within_class_loss
)
tf
.
add_to_collection
(
tf
.
GraphKeys
.
LOSSES
,
within_class_loss
)
# Total loss
# Total loss
loss
=
tf
.
reduce_mean
(
loss
=
tf
.
reduce_mean
(
tf
.
maximum
(
basic_loss
,
0.0
),
0
,
name
=
"
total_loss
"
)
tf
.
maximum
(
basic_loss
,
0.0
),
0
,
name
=
"
total_loss
"
)
tf
.
add_to_collection
(
tf
.
GraphKeys
.
LOSSES
,
loss
)
tf
.
add_to_collection
(
tf
.
GraphKeys
.
LOSSES
,
loss
)
tf
.
summary
.
scalar
(
'
loss_raw
'
,
loss
)
tf
.
summary
.
scalar
(
'
loss_triplet
'
,
loss
)
# Appending the regularization loss
#regularization_losses = tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)
#loss = tf.add_n([loss] + regularization_losses, name="total_loss")
#tf.summary.scalar('loss', loss)
return
loss
return
loss
...
...
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