[英]InvalidArgumentError: cannot compute MatMul as input #0(zero-based) was expected to be a float tensor but is a double tensor [Op:MatMul]
[英]Tensorflow cannot compute Addv2 as input #1(zero-based) was expected to be a double tensor but it is a float tensor [Op:Addv]
错误信息:
tensorflow.python.framework.errors_impl.InvalidArgumentError:无法计算 AddV2 作为输入 #1(从零开始)应该是双张量,但它是浮点张量 [Op:AddV2]
在我的代码中,我创建了一个 tensorflow 分布 MixtureSameFamily object 并使用我的网络的 output 作为参数。 但是,当我尝试计算一系列值的概率以生成概率密度 function 时,我收到此错误。
我的代码:
gm = tfd.MixtureSameFamily(
mixture_distribution=tfd.Categorical(probs=alphas),
components_distribution=tfd.Normal(
loc=mus,
scale=sigmas
)
)
x = np.linspace(-2,2,int(1000), dtype=np.double)
print(x.dtype)
pyx = gm.prob(x)
print(x.dtype)
的结果是 "dtype: 'float'"
据我所知,tensorflow根据文档不支持浮点数据类型。
为此,我特别困惑。 任何帮助将不胜感激。
似乎是最新的 tensorflow-probability 模块中的一个错误。 它仅适用于float32
。
解决方法
将参数显式转换为float32
gm = tfd.MixtureSameFamily(
mixture_distribution=tfd.Categorical(probs=alphas.astype('float32')),
components_distribution=tfd.Normal(
loc=mus.astype('float32'),
scale=sigmas.astype('float32')
)
)
x = np.linspace(-2,2,int(1000), dtype='float32')
pyx = gm.prob(x)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.