使用 tensorflow (anaconda) 的 LSTM 实现

数据挖掘 深度学习 张量流 rnn lstm
2022-03-01 09:15:35

我是TensorFlow的新手,目前我正在尝试实现一个LSTM使用 jupyter 笔记本。

但是当我运行以下代码段时,我遇到了一些错误并且找不到任何解决方案。

我该如何解决这个错误?

代码:

lstmCell = tf.contrib.rnn.BasicLSTMCell(lstmUnits)
lstmCell = tf.contrib.rnn.DropoutWrapper(cell=lstmCell, output_keep_prob=0.75)
value, _ = tf.nn.dynamic_rnn(lstmCell, data, dtype=tf.float32)

错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-29-db6a6fc2c55e> in <module>()
----> 1 lstmCell = tf.contrib.rnn.BasicLSTMCell(lstmUnits)
      2 lstmCell = tf.contrib.rnn.DropoutWrapper(cell=lstmCell, output_keep_prob=0.75)
      3 value, _ = tf.nn.dynamic_rnn(lstmCell, data, dtype=tf.float32)

C:\Anaconda3\lib\site-packages\tensorflow\python\util\lazy_loader.py in __getattr__(self, item)
     51 
     52   def __getattr__(self, item):
---> 53     module = self._load()
     54     return getattr(module, item)
     55 

C:\Anaconda3\lib\site-packages\tensorflow\python\util\lazy_loader.py in _load(self)
     40   def _load(self):
     41     # Import the target module and insert it into the parent's namespace
---> 42     module = importlib.import_module(self.__name__)
     43     self._parent_module_globals[self._local_name] = module
     44 

C:\Anaconda3\lib\importlib\__init__.py in import_module(name, package)
    124                 break
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 
    128 

C:\Anaconda3\lib\importlib\_bootstrap.py in _gcd_import(name, package, level)

C:\Anaconda3\lib\importlib\_bootstrap.py in _find_and_load(name, import_)

C:\Anaconda3\lib\importlib\_bootstrap.py in _find_and_load_unlocked(name, import_)

C:\Anaconda3\lib\importlib\_bootstrap.py in _load_unlocked(spec)

C:\Anaconda3\lib\importlib\_bootstrap_external.py in exec_module(self, module)

C:\Anaconda3\lib\importlib\_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

C:\Anaconda3\lib\site-packages\tensorflow\contrib\__init__.py in <module>()
     29 from tensorflow.contrib import data
     30 from tensorflow.contrib import deprecated
---> 31 from tensorflow.contrib import distributions
     32 from tensorflow.contrib import estimator
     33 from tensorflow.contrib import factorization

C:\Anaconda3\lib\site-packages\tensorflow\contrib\distributions\__init__.py in <module>()
     31 from tensorflow.contrib.distributions.python.ops.distribution_util import matrix_diag_transform
     32 from tensorflow.contrib.distributions.python.ops.distribution_util import softplus_inverse
---> 33 from tensorflow.contrib.distributions.python.ops.estimator import *
     34 from tensorflow.contrib.distributions.python.ops.geometric import *
     35 from tensorflow.contrib.distributions.python.ops.independent import *

C:\Anaconda3\lib\site-packages\tensorflow\contrib\distributions\python\ops\estimator.py in <module>()
     19 from __future__ import print_function
     20 
---> 21 from tensorflow.contrib.learn.python.learn.estimators.head import _compute_weighted_loss
     22 from tensorflow.contrib.learn.python.learn.estimators.head import _RegressionHead
     23 from tensorflow.python.framework import ops

C:\Anaconda3\lib\site-packages\tensorflow\contrib\learn\__init__.py in <module>()
     90 
     91 # pylint: disable=wildcard-import
---> 92 from tensorflow.contrib.learn.python.learn import *
     93 # pylint: enable=wildcard-import
     94 

C:\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\__init__.py in <module>()
     21 
     22 # pylint: disable=wildcard-import
---> 23 from tensorflow.contrib.learn.python.learn import *
     24 # pylint: enable=wildcard-import

C:\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\__init__.py in <module>()
     23 from tensorflow.contrib.learn.python.learn import basic_session_run_hooks
     24 from tensorflow.contrib.learn.python.learn import datasets
---> 25 from tensorflow.contrib.learn.python.learn import estimators
     26 from tensorflow.contrib.learn.python.learn import graph_actions
     27 from tensorflow.contrib.learn.python.learn import learn_io as io

C:\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\__init__.py in <module>()
    295 from tensorflow.contrib.learn.python.learn.estimators._sklearn import NotFittedError
    296 from tensorflow.contrib.learn.python.learn.estimators.constants import ProblemType
--> 297 from tensorflow.contrib.learn.python.learn.estimators.dnn import DNNClassifier
    298 from tensorflow.contrib.learn.python.learn.estimators.dnn import DNNEstimator
    299 from tensorflow.contrib.learn.python.learn.estimators.dnn import DNNRegressor

C:\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\dnn.py in <module>()
     28 from tensorflow.contrib.layers.python.layers import optimizers
     29 from tensorflow.contrib.learn.python.learn import metric_spec
---> 30 from tensorflow.contrib.learn.python.learn.estimators import dnn_linear_combined
     31 from tensorflow.contrib.learn.python.learn.estimators import estimator
     32 from tensorflow.contrib.learn.python.learn.estimators import head as head_lib

C:\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\dnn_linear_combined.py in <module>()
     29 from tensorflow.contrib.layers.python.layers import optimizers
     30 from tensorflow.contrib.learn.python.learn import metric_spec
---> 31 from tensorflow.contrib.learn.python.learn.estimators import estimator
     32 from tensorflow.contrib.learn.python.learn.estimators import head as head_lib
     33 from tensorflow.contrib.learn.python.learn.estimators import model_fn

C:\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\estimator.py in <module>()
     47 from tensorflow.contrib.learn.python.learn.estimators import tensor_signature
     48 from tensorflow.contrib.learn.python.learn.estimators._sklearn import NotFittedError
---> 49 from tensorflow.contrib.learn.python.learn.learn_io import data_feeder
     50 from tensorflow.contrib.learn.python.learn.utils import export
     51 from tensorflow.contrib.learn.python.learn.utils import saved_model_export_utils

C:\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\learn_io\__init__.py in <module>()
     19 from __future__ import print_function
     20 
---> 21 from tensorflow.contrib.learn.python.learn.learn_io.dask_io import extract_dask_data
     22 from tensorflow.contrib.learn.python.learn.learn_io.dask_io import extract_dask_labels
     23 from tensorflow.contrib.learn.python.learn.learn_io.dask_io import HAS_DASK

C:\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\learn_io\dask_io.py in <module>()
     24 try:
     25   # pylint: disable=g-import-not-at-top
---> 26   import dask.dataframe as dd
     27   allowed_classes = (dd.Series, dd.DataFrame)
     28   HAS_DASK = True

C:\Anaconda3\lib\site-packages\dask\dataframe\__init__.py in <module>()
      1 from __future__ import print_function, division, absolute_import
      2 
----> 3 from .core import (DataFrame, Series, Index, _Frame, map_partitions,
      4                    repartition, to_delayed, to_datetime, to_timedelta)
      5 from .groupby import Aggregation

C:\Anaconda3\lib\site-packages\dask\dataframe\core.py in <module>()
     38 if PANDAS_VERSION >= '0.20.0':
     39     from pandas.util import cache_readonly
---> 40     pd.core.computation.expressions.set_use_numexpr(False)
     41 else:
     42     from pandas.util.decorators import cache_readonly

AttributeError: module 'pandas.core.computation' has no attribute 'expressions'
  • TensorFlow 版本 - '1.4.0'
  • Python 版本 - 3.6.3:: Anaconda, Inc.
1个回答

根据此处的解决方案,您有不同的选择:

最简单的解决方案是恢复到Pandas 0.19.2. 为此,请在命令行或终端中使用以下命令。

conda install pandas=0.19.2