[英]Error with keras using TensorFlow as backend
我正處於項目的開始階段,我剛剛導入了我需要的包:
from keras.models import Sequential
from keras.layers import Dense
顯然 TensorFlow 和 keras 都已經安裝好了。 無論如何,如果我運行代碼,我會收到此錯誤:
Using TensorFlow backend.
ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.
.
.
.
Traceback (most recent call last):
File "c:\users\franc\appdata\local\programs\python\python37\lib\site-
File "c:\users\franc\appdata\local\programs\python\python37\lib\site-packages\keras\backend\tensorflow_backend.py", line 6, in <module>
from tensorflow.python.eager import context
ImportError: cannot import name 'context' from 'tensorflow.python.eager' (C:\Users\franc\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\eager\__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\franc\appdata\local\programs\python\python37\lib\site-packages\IPython\core\interactiveshell.py", line 2040, in showtraceback
stb = value._render_traceback_()
AttributeError: 'ImportError' object has no attribute '_render_traceback_'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\franc\appdata\local\programs\python\python37\lib\site-packages\IPython\core\ultratb.py", line 1101, in get_records
return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
.
.
.
File "c:\users\franc\appdata\local\programs\python\python37\lib\site-packages\tensorflow_core\__init__.py", line 42, in <module>
from . _api.v2 import audio
ImportError: cannot import name 'audio' from 'tensorflow_core._api.v2' (C:\Users\franc\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\_api\v2\__init__.py)
我真的不知道如何解決這個問題,我檢查了許多網站以遵循兩個軟件包的正確安裝,但沒有結果。 我做了正確的安裝,但我仍然有這個錯誤。
您可能想嘗試 tensorflow 附帶的 keras。 此 keras 僅使用 tensorflow 作為后端,這正是您所需要的:
import tensorflow as tf
from tf.keras import Sequential
from tf.keras.layers import Dense
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.