python - 我收到错误此错误:“张量”对象没有属性“log_prob”
问题描述
我收到此错误
AttributeError:“张量”对象没有属性“log_prob”
同时使用 TensorFlow Probability 实现变分自动编码器。
def dense_layers(sizes):
return tfk.Sequential([tfkl.Dense(size, activation=tf.nn.leaky_relu) for size in sizes])
encoder = tfk.Sequential([
tfkl.InputLayer(input_shape=input_shape, name='encoder_input'),
dense_layers(intermediary_dims),
tfkl.Dense(latent_dim, activation = tf.nn.leaky_relu),
tfkl.Dense(tfpl.MultivariateNormalTriL.params_size(latent_dim), activation=None),
tfpl.MultivariateNormalTriL(latent_dim,activity_regularizer=tfpl.KLDivergenceRegularizer(prior)),
], name='encoder')
encoder.summary()
plot_model(encoder, to_file='vae_mlp_encoder.png', show_shapes=True)
decoder = tfk.Sequential([
tfkl.InputLayer(input_shape=[latent_dim]),
dense_layers(reversed(intermediary_dims)),
tfkl.Dense(tfpl.IndependentNormal.params_size(original_dim), activation=None),
tfpl.IndependentNormal(original_dim),
], name='decoder')
decoder.summary()
plot_model(decoder, to_file='vae_mlp_decoder.png', show_shapes=True)
vae = tfk.Model(inputs=encoder.inputs,
outputs=decoder(encoder.outputs[0]),
name='vae_mlp') # fitting the model
negloglik = lambda x, rv_x: -rv_x.log_prob(x)
vae.compile(optimizer=tf.keras.optimizers.Nadam(),
loss=negloglik)
vae.summary() # summary
plot_model(vae,
to_file='vae_mlp.png',
show_shapes=True) #plotting the model
#I was expecting the Vae.summary
解决方案
我找到了解决方案。我安装了最新版本的 Tensorflow Probability:
! pip install --upgrade tfp-nightly
! pip install tf_nightly
! pip install tf_estimator_nightly
推荐阅读
- laravel - 如何使用动态组件在 Laravel 中的组件之间导航
- r - 在 R 的 choropleth 包中为离散数据创建超过 9 个中断
- struct - 如何在 Solidity 中返回结构的多个实例?
- flutter - 在 Text 中列表的两个元素后添加空格 - Flutter
- date - Tableau 中不可用的域信息
- r - ggplot geom_line - 设置线条颜色不起作用?
- android - 屏幕大小的 PopupWindow 应该是一个新的活动吗?(安卓)
- wkwebview - Swift WkWebView createWebArchiveData 对返回类型感到困惑
- python - 如何从一列中选择相似(相同或接近)的值?
- python - 我怎样才能只写文件名而不是写整个路径?