Keras导入错误Tensorflow后端

Keras导入错误Tensorflow后端

本文介绍了Keras导入错误Tensorflow后端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    ---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/Users/CJL/anaconda3/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py in <module>()
      4 try:
----> 5     from tensorflow.python.ops import ctc_ops as ctc
      6 except ImportError:

ImportError: cannot import name 'ctc_ops'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-10-c74e2bd4ca71> in <module>()
----> 1 import keras

/Users/CJL/anaconda3/lib/python3.5/site-packages/keras/__init__.py in <module>()
      1 from __future__ import absolute_import
----> 2 from . import backend
      3 from . import datasets
      4 from . import engine
      5 from . import layers

/Users/CJL/anaconda3/lib/python3.5/site-packages/keras/backend/__init__.py in <module>()
     67 elif _BACKEND == 'tensorflow':
     68     sys.stderr.write('Using TensorFlow backend.\n')
---> 69     from .tensorflow_backend import *
     70 else:
     71     raise Exception('Unknown backend: ' + str(_BACKEND))

/Users/CJL/anaconda3/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py in <module>()
      5     from tensorflow.python.ops import ctc_ops as ctc
      6 except ImportError:
----> 7     import tensorflow.contrib.ctc as ctc
      8
      9 import numpy as np

ImportError: No module named 'tensorflow.contrib.ctc'

根据此帖子在此处输入链接说明我想知道这个问题是否已经解决?

Seems like is an problem with Keras and not Tensorflow according to this post enter link description hereI was wondering if this has been fixed yet?

推荐答案

这是Keras和tensorflow之间的问题.您应该将此修复更改为使用类似的

This is a problem between Keras and tensorflow. You should change this fix to use something like

if hasattr(tf.contrib, 'ctc'):
  ctc = tf.contrib.ctc  # old version
else:
  ctc = tf.nn  # New official version.

访问ctc操作的当前官方"方式位于tf.nn中,例如tf.nn.ctc_loss.

The current "official" way to access the ctc operations are in tf.nn, for instance, tf.nn.ctc_loss.

这篇关于Keras导入错误Tensorflow后端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 18:54