【发布时间】: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