【问题标题】:Attribute error when using tensorflow with elu将 tensorflow 与 elu 一起使用时出现属性错误
【发布时间】:2020-03-01 00:12:05
【问题描述】:

尝试使用 tensorflow 库时出现属性错误输出

TF 版本:

Name: tensorflow
Version: 2.0.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: packages@tensorflow.org
License: Apache 2.0
Location: c:\users\vinhalivinhali\appdata\local\programs\python\python35\lib\site-packages
Requires: tensorboard, wrapt, keras-preprocessing, protobuf, wheel, numpy, gast, tensorflow-estimator, termcolor, google-pasta, grpcio, absl-py, keras-applications, astor, opt-einsum, six
Required-by:

Python 版本

Python 3.5.0

进口

import tensorflow as tf # for Deep Learning
import pandas as pd # for data manipulation
import numpy as np # for matrix manipulation
from matplotlib import pyplot as plt # for graphics

脚本

X0 = X[:, 0, :] # get the data in the first time period
Ht = tf.elu(tf.matmul(X0, Wx_h) + b) # uses X0 to initiate the hidden state
y = [] # list to be populated with outputs every time period

输出

Traceback (most recent call last):
  File "rnrs.py", line 40, in <module>
    Ht = tf.elu(tf.matmul(X0, Wx_h) + b) # uses X0 to initiate the hidden state
AttributeError: module 'tensorflow' has no attribute 'elu'

【问题讨论】:

  • 改用tf.nn.elu
  • 回溯(最近一次调用最后):文件“rnrs.py”,第 40 行,在 Ht = tf.nn.elu(tf.matmul(X0, Wx_h) + b) NameError : 名称“Wx_h”未定义
  • 有以下出口@MihailBurduja
  • 你没有定义Wx_h。您应该将其声明为 Wx_h = tf.Variable(tf.random.normal((200, X0.shape[0])))b 变量。我建议你考虑使用 TF Keras,因为它更简单,层次更高

标签: tensorflow python-3.5


【解决方案1】:

elu 函数在tf.nn 模块中,参见documentation

【讨论】:

  • 我测试过但得到以下输出: Traceback (last recent call last): File "rnrs.py", line 40, in Ht = tf.nn.elu(tf.matmul( X0, Wx_h) + b) NameError: name 'Wx_h' is not defined
猜你喜欢
  • 1970-01-01
  • 2019-07-13
  • 2016-04-03
  • 1970-01-01
  • 2021-07-01
  • 2021-06-25
  • 2018-06-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多