python - AttributeError: 模块 'tensorflow' 没有属性 'log' 错误
问题描述
我使用竹算库来构建贝叶斯 lstm 单元。我使用了你论文中的代码:ZhuSuan: A Library for Bayesian Deep python。但我得到一个错误:
AttributeError: module 'tensorflow' has no attribute 'log' 有人可以帮我解决这个问题吗?
class BayesianLSTMCell(object):
def __init__(self, num_units, forget_bias=1.0):
self._forget_bias = forget_bias
w_mean = tf.zeros([2 * num_units + 1, 4 * num_units])
self._w = zs.Normal('w', w_mean, std=1., group_ndims=2)
def __call__(self, state, inputs):
c, h = state
batch_size = tf.shape(inputs)[0]
linear_in = tf.concat([inputs, h, tf.ones([batch_size, 1])], axis=1)
linear_out = tf.matmul(linear_in, self._w)
# i = input_gate, j = new_input, f = forget_gate, o = output_gate
i, j, f, o = tf.split(value=linear_out, num_or_size_splits=4, axis=1)
new_c = (c * tf.sigmoid(f + self._forget_bias) +
tf.sigmoid(i) * tf.tanh(j))
new_h = tf.tanh(new_c) * tf.sigmoid(o)
return new_c, new_h
def bayesian_rnn(cell, inputs, seq_len):
batch_size = tf.shape(inputs)[0]
initializer = (tf.zeros([batch_size, 128]), tf.zeros([batch_size, 128]))
c_list, h_list = tf.scan(cell, inputs, initializer=initializer)
relevant_outputs = tf.gather_nd(
h_list, tf.stack([seq_len - 1, tf.range(batch_size)], axis=1))
logits = tf.squeeze(tf.layers.dense(relevant_outputs, 1), -1)
return logits
seq_len=5
with zs.BayesianNet() as model:
cell = BayesianLSTMCell(128, forget_bias=0.)
logits = bayesian_rnn(cell, b, seq_len)
_ = zs.Bernoulli(Y, logits, dtype=tf.float32
解决方案
推荐阅读
- ansible - 如何将保险库(保险库变量)传递给角色本身具有多个依赖角色的多个角色?
- java - 如何为 SMS 模板使用速度
- angular - 提交带有条件的两个不同 Api 的表单
- sql - 如何对表中的所有列使用 REGEXP_LIKE?
- android - 在android中动态调整标签布局的高度
- php - 正则表达式:删除双
标签 - spring-boot - @EnableAutoConfiguration 在测试上下文中
- javascript - 无法将文件转换为二进制格式以使用 node.js 发送到 wit.ai api
- javascript - 我需要帮助对字符串数组中的特定数字进行排序以下降
- javascript - 为什么我不能复制函数的调用方法