Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lucas Miranda
deepOF
Commits
70724ab8
Commit
70724ab8
authored
Jul 13, 2020
by
lucas_miranda
Browse files
Modified LSTMs to work with cuDNN implementation
parent
93fa64b0
Changes
2
Hide whitespace changes
Inline
Side-by-side
source/model_utils.py
View file @
70724ab8
...
...
@@ -5,6 +5,7 @@ from keras import backend as K
from
sklearn.metrics
import
silhouette_score
from
tensorflow.keras.constraints
import
Constraint
from
tensorflow.keras.layers
import
Layer
import
numpy
as
np
import
tensorflow
as
tf
import
tensorflow_probability
as
tfp
...
...
@@ -12,6 +13,22 @@ tfd = tfp.distributions
tfpl
=
tfp
.
layers
# Helper functions
def
far_away_uniform_initialiser
(
shape
,
minval
=
0
,
maxval
=
15
,
iters
=
1000000
):
"""
Returns a uniformly initialised matrix in which the columns are as far as possible
"""
init_dist
=
0
for
i
in
range
(
iters
):
temp
=
np
.
random
.
uniform
(
minval
,
maxval
,
shape
)
dist
=
np
.
abs
(
np
.
linalg
.
norm
(
np
.
diff
(
temp
)))
if
dist
>
init_dist
:
init_dist
=
dist
init
=
temp
return
init
.
astype
(
np
.
float32
)
def
compute_kernel
(
x
,
y
):
x_size
=
K
.
shape
(
x
)[
0
]
y_size
=
K
.
shape
(
y
)[
0
]
...
...
source/models.py
View file @
70724ab8
...
...
@@ -193,21 +193,21 @@ class SEQ_2_SEQ_GMVAE:
self
.
overlap_loss
=
overlap_loss
if
self
.
prior
==
"standard_normal"
:
init_means
=
far_away_uniform_initialiser
(
[
self
.
number_of_components
,
self
.
ENCODING
],
minval
=
0
,
maxval
=
15
)
self
.
prior
=
tfd
.
mixture
.
Mixture
(
cat
=
tfd
.
categorical
.
Categorical
(
probs
=
tf
.
ones
(
self
.
number_of_components
)
/
self
.
number_of_components
),
components
=
[
tfd
.
Independent
(
tfd
.
Normal
(
loc
=
tf
.
random
.
uniform
(
shape
=
[
self
.
ENCODING
],
minval
=
0
,
maxval
=
15
),
scale
=
1
,
),
tfd
.
Normal
(
loc
=
init_means
[
k
],
scale
=
1
,),
reinterpreted_batch_ndims
=
1
,
)
for
_
in
range
(
self
.
number_of_components
)
for
k
in
range
(
self
.
number_of_components
)
],
)
...
...
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