Closed ThierryO closed 4 years ago
Can you provide the output of reticulate::py_config())
and tensorflow::tf_config()
?
Also, is that the complete example necessary to produce that error? Otherwise, can you post the complete code?
Thanks for looking into this. This is the smallest model which reproduces the error on my machine. The actual model has more layers before the layer_dense()
but their output shape is 10L
.
keras_model_sequential() %>%
layer_dense(
input_shape = 10L,
units = params_size_multivariate_normal_tri_l(4L)
) %>%
layer_multivariate_normal_tri_l(event_size = 4L) %>%
layer_kl_divergence_add_loss(
distribution_b = tfd_independent(
tfd_normal(loc = c(0, 0), scale = 1),
reinterpreted_batch_ndims = 1
)
)
> reticulate::py_config()
python: /home/thierry/anaconda3/envs/r-reticulate/bin/python
libpython: /home/thierry/anaconda3/envs/r-reticulate/lib/libpython3.6m.so
pythonhome: /home/thierry/anaconda3/envs/r-reticulate:/home/thierry/anaconda3/envs/r-reticulate
version: 3.6.10 |Anaconda, Inc.| (default, Jan 7 2020, 21:14:29) [GCC 7.3.0]
numpy: /home/thierry/anaconda3/envs/r-reticulate/lib/python3.6/site-packages/numpy
numpy_version: 1.17.3
tensorflow_probability:/home/thierry/anaconda3/envs/r-reticulate/lib/python3.6/site-packages/tensorflow_probability
python versions found:
/home/thierry/.virtualenvs/r-reticulate/bin/python
/home/thierry/anaconda3/envs/r-reticulate/bin/python
/usr/bin/python3
/usr/bin/python
/home/thierry/anaconda3/bin/python
> tensorflow::tf_config()
TensorFlow v2.0.0 (~/anaconda3/envs/r-reticulate/lib/python3.6/site-packages/tensorflow_probability)
Python v3.6 (~/anaconda3/envs/r-reticulate/bin/python)
hi, I don't know how this could have worked before, but I think it's a problem with the dimensions. Judging from the KL divergence, the multivariate normal probably should have event size 2, right? Such that both are comparable.
This would work:
keras_model_sequential() %>%
layer_dense(
input_shape = 10L,
units = params_size_multivariate_normal_tri_l(2L)
) %>%
layer_multivariate_normal_tri_l(event_size = 2L) %>%
layer_kl_divergence_add_loss(
distribution_b = tfd_independent(
tfd_normal(loc = c(0, 0), scale = 1),
reinterpreted_batch_ndims = 1
)
)
Yes. That was the problem. Below is the more generic solution in case someone else has a similar problem.
encoded_size <- 4L
keras_model_sequential() %>%
layer_dense(
input_shape = 10L,
units = params_size_multivariate_normal_tri_l(encoded_size)
) %>%
layer_multivariate_normal_tri_l(event_size = encoded_size) %>%
layer_kl_divergence_add_loss(
distribution_b = tfd_independent(
tfd_normal(loc = rep(0, encoded_size), scale = 1),
reinterpreted_batch_ndims = 1
)
)
The layer below was working a few day ago.
Now I'm getting this error.
The only thing that changed was a started update of my Ubuntu system. I've tried to update
conda
, reinstallTensorflow
and upgrade the R packages.