【发布时间】:2020-04-06 10:24:03
【问题描述】:
正如标题中所说,我正在尝试使用 tensorflow 概率包创建多元正态分布的混合。
在我的原始项目中,我输入了神经网络输出的分类权重、位置和方差。但是在创建图表时,我收到以下错误:
components[0] 批次形状必须与 cat 形状和其他组件批次形状兼容
我使用占位符重现了同样的问题:
import tensorflow as tf
import tensorflow_probability as tfp # dist= tfp.distributions
tf.compat.v1.disable_eager_execution()
sess = tf.compat.v1.InteractiveSession()
l1 = tf.compat.v1.placeholder(dtype=tf.float32, shape=[None, 2], name='observations_1')
l2 = tf.compat.v1.placeholder(dtype=tf.float32, shape=[None, 2], name='observations_2')
log_std = tf.compat.v1.get_variable('log_std', [1, 2], dtype=tf.float32,
initializer=tf.constant_initializer(1.0),
trainable=True)
mix = tf.compat.v1.placeholder(dtype=tf.float32, shape=[None,1], name='weights')
cat = tfp.distributions.Categorical(probs=[mix, 1.-mix])
components = [
tfp.distributions.MultivariateNormalDiag(loc=l1, scale_diag=tf.exp(log_std)),
tfp.distributions.MultivariateNormalDiag(loc=l2, scale_diag=tf.exp(log_std)),
]
bimix_gauss = tfp.distributions.Mixture(
cat=cat,
components=components)
所以,我的问题是,我做错了什么?我查看了错误,似乎tensorshape_util.is_compatible_with 是引发错误的原因,但我不明白为什么。
谢谢!
【问题讨论】:
标签: python tensorflow2.0 mixture-model tensorflow-probability