【发布时间】:2019-12-06 10:44:02
【问题描述】:
我想将我的一些代码移至 tensorflow 发行版,并且正在学习 colab 上的教程。在运行时请求tensorflow 2.x版本后,官方示例代码不再起作用。
你可以find the colab notebook here,我最开始加了如下代码:
try:
# %tensorflow_version only exists in Colab.
%tensorflow_version 2.x
except Exception:
pass
我只在 colab 上运行过代码,但我不认为它是特定于它的。如果您想尝试在本地 tensorflow 安装上重现该问题,这应该是相关代码:
import tensorflow as tf
import tensorflow_probability as tfp
tfd = tfp.distributions
nd = tfd.MultivariateNormalDiag(loc=[0., 10.], scale_diag=[1., 4.])
nd.sample()
最后一行,从nd 采样,创建以下错误消息:
TypeError: Tensor is unhashable if Tensor equality is enabled. Instead, use tensor.experimental_ref() as the key.
Tensorflow 概率是 0.7.0 版本,tensorflow 是 2.0.0 版本。
【问题讨论】:
标签: python tensorflow google-colaboratory tensorflow-probability