Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lucas Miranda
deepOF
Commits
a7080a5c
Commit
a7080a5c
authored
May 19, 2021
by
lucas_miranda
Browse files
Replaced for loop with vectorised mapping on ClusterOverlap regularization layer
parent
c36f55b7
Changes
2
Hide whitespace changes
Inline
Side-by-side
deepof/model_utils.py
View file @
a7080a5c
...
...
@@ -612,19 +612,25 @@ class ClusterOverlap(Layer):
)
### CANDIDATE FOR REMOVAL. EXPLORE HOW USEFUL THIS REALLY IS ###
neighbourhood_entropy
=
purity_vector
# * max_groups[random_idxs]
# self.add_metric(
# len(set(hard_groups[max_groups >= self.min_confidence])),
# aggregation="mean",
# name="number_of_populated_clusters",
# )
#
# self.add_metric(
# max_groups,
# aggregation="mean",
# name="average_confidence_in_selected_cluster",
# )
neighbourhood_entropy
=
purity_vector
*
tf
.
gather
(
max_groups
,
tf
.
constant
(
random_idxs
)
)
self
.
add_metric
(
tf
.
shape
(
tf
.
unique
(
tf
.
squeeze
(
tf
.
gather
(
hard_groups
,
tf
.
where
(
max_groups
>=
self
.
min_confidence
)))
)
),
aggregation
=
"mean"
,
name
=
"number_of_populated_clusters"
,
)
self
.
add_metric
(
max_groups
,
aggregation
=
"mean"
,
name
=
"average_confidence_in_selected_cluster"
,
)
self
.
add_metric
(
neighbourhood_entropy
,
aggregation
=
"mean"
,
name
=
"neighbourhood_entropy"
...
...
deepof/models.py
View file @
a7080a5c
...
...
@@ -473,13 +473,12 @@ class GMVAE:
# Dummy layer with no parameters, to retrieve the previous tensor
z
=
tf
.
keras
.
layers
.
Lambda
(
lambda
t
:
t
,
name
=
"latent_distribution"
)(
z
)
if
self
.
overlap_loss
:
z
=
deepof
.
model_utils
.
ClusterOverlap
(
self
.
batch_size
,
self
.
ENCODING
,
self
.
number_of_components
,
loss_weight
=
self
.
overlap_loss
,
)([
z
,
z_cat
])
z
=
deepof
.
model_utils
.
ClusterOverlap
(
self
.
batch_size
,
self
.
ENCODING
,
self
.
number_of_components
,
loss_weight
=
self
.
overlap_loss
,
)([
z
,
z_cat
])
# Define and instantiate generator
g
=
Input
(
shape
=
self
.
ENCODING
)
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment