tensorflow-probability

Toy example of Logistic Regression with Tensorflow probability and the titanic dataset fails

怎甘沉沦 提交于 2021-01-29 20:00:18
问题 I am learning tensorflow-probability and this is a toy example of logistic regression with the titanic dataset. My model does not seem to learn and the loss is nan. I don't understand why. Below you will find three different implementations, all return the same results. One uses a sigmoid activation, the second uses a DistributionLambda Layer with a Bernoulli distribution and the third a DistributionLambda Layer with a Beta distribution. Are there any corrections I should make to this code?

How to create sum of different kernel objects in TensorFlow Probability?

给你一囗甜甜゛ 提交于 2021-01-29 06:18:13
问题 I have one question about specifying kernel function in Tensorflow-probability . Usually, if I want to create a kernel object, I will write import tensorflow as tf import tensorflow_probability as tfp tfp_kernels = tfp.positive_semidefinite_kernels kernel_obj = tfp_kernels.ExponentiateQuadratic(*args, **karwgs) I know that kernel object support batch broadcasting. But what if I want to build a kernel object that is the sum of several different kernel objects, like additive Gaussian processes?

No module named 'tensorflow_probability'

不打扰是莪最后的温柔 提交于 2020-12-30 02:27:46
问题 I need to use Tensorflow and Tensorflow_Probability. After installing it by these commands: conda install tensorflow-probability or pip install --upgrade tensorflow-probability , I ran it in the notebook: import tensorflow_probability as tfp but it returns this error: ModuleNotFoundError Traceback (most recent call last) <ipython-input-8-41494c8c96ff> in <module> ----> 1 import tensorflow_probability as tfp ModuleNotFoundError: No module named 'tensorflow_probability'. The results of pip list

TypeError: An op outside of the function building code is being passed a Graph tensor

我与影子孤独终老i 提交于 2020-06-11 17:36:19
问题 I am getting the following exception TypeError: An op outside of the function building code is being passed a "Graph" tensor. It is possible to have Graph tensors leak out of the function building context by including a tf.init_scope in your function building code. For example, the following function will fail: @tf.function def has_init_scope(): my_constant = tf.constant(1.) with tf.init_scope(): added = my_constant * 2 The graph tensor has name: conv2d_flipout/divergence_kernel:0 which also

Why does tf.executing_eagerly() return False in TensorFlow 2?

眉间皱痕 提交于 2020-05-16 22:03:42
问题 Let me explain my set up. I am using TensorFlow 2.1, the Keras version shipped with TF, and TensorFlow Probability 0.9. I have a function get_model that creates (with the functional API) and returns a model using Keras and custom layers. In the __init__ method of these custom layers A , I call a method A.m , which executes the statement print(tf.executing_eagerly()) , but it returns False . Why? To be more precise, this is roughly my setup def get_model(): inp = Input(...) x = A(...)(inp) x =

NotImplementedError: Cannot convert a symbolic Tensor (truediv_2:0) to a numpy array

南笙酒味 提交于 2020-05-14 13:40:06
问题 If you execute the following TensorFlow 2.1 code import tensorflow as tf import tensorflow_probability as tfp tf.config.experimental_run_functions_eagerly(True) def get_mnist_data(normalize=True, categorize=True): img_rows, img_cols = 28, 28 (x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data() if tf.keras.backend.image_data_format() == 'channels_first': x_train = x_train.reshape(x_train.shape[0], 1, img_rows, img_cols) x_test = x_test.reshape(x_test.shape[0], 1, img_rows

Specification of Multinomial model in Tensorflow Probability

纵然是瞬间 提交于 2020-04-17 23:46:13
问题 I am playing with a mixed multinomial discrete choice model in Tensorflow Probability. The function should take an input of a choice among 3 alternatives. The chosen alternative is specified by CHOSEN (a # observationsx3 tensor). I have a previous question but the code/question has changed quite a bit: Tensorflow Probability Error: OperatorNotAllowedInGraphError: iterating over `tf.Tensor` is not allowed Looking at the source code for Multinomial(), I should be able to give CHOSEN as an input

How to Decompose and Visualise Slope Component in Tensorflow Probability

不问归期 提交于 2020-03-05 00:32:39
问题 I'm running tensorflow 2.1 and tensorflow_probability 0.9. I have fit a Structural Time Series Model with a seasonal component. I am using code from the Tensorflow Probability Structural Time Series Probability example: Tensorflow Github. In the example there is a great plot where the decomposition is visualised: # Get the distributions over component outputs from the posterior marginals on # training data, and from the forecast model. component_dists = sts.decompose_by_component( demand

Keras Model using Tensorflow Distribution for loss fails with batch size > 1

那年仲夏 提交于 2020-01-24 12:16:57
问题 I'm trying to use a distribution from tensorflow_probability to define a custom loss function in Keras. More specifically, I'm trying to build a Mixture Density Network. My model works on a toy dataset when batch_size = 1 (it learns to predict the correct mixture distribution for y using x ). But it "fails" when batch_size > 1 (it predicts the same distribution for all y , ignoring x ). This makes me think my problem has to do with batch_shape vs. sample_shape. To reproduce: import random

Keras Model using Tensorflow Distribution for loss fails with batch size > 1

怎甘沉沦 提交于 2020-01-24 12:16:06
问题 I'm trying to use a distribution from tensorflow_probability to define a custom loss function in Keras. More specifically, I'm trying to build a Mixture Density Network. My model works on a toy dataset when batch_size = 1 (it learns to predict the correct mixture distribution for y using x ). But it "fails" when batch_size > 1 (it predicts the same distribution for all y , ignoring x ). This makes me think my problem has to do with batch_shape vs. sample_shape. To reproduce: import random