keras ImportError:无法导入名称“backend”

hmtdttj4  于 2023-04-06  发布在  其他
关注(0)|答案(3)|浏览(244)

在书面代码下面,

from __future__ import print_function
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from tensorflow.keras.layers import Conv2D
from tensorflow.keras.layers import MaxPooling2D
from keras.layers import backend as k

batch_size = 128
num_classes = 10
epochs = 12

及以下问题,

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-d1183f2cea73> in <module>
      8 from tensorflow.keras.layers import Conv2D
      9 from tensorflow.keras.layers import MaxPooling2D
---> 10 from keras.layers import backend as k
     11 
     12 

ImportError: cannot import name 'backend'

需要帮助解决此问题
注意:我使用的是Python 3.6.0

gopyfrb3

gopyfrb31#

您可以使用keras后端库

import keras.backend as k

或者直接从TensorFlow

from tensorflow.keras import backend as k
0pizxfdo

0pizxfdo2#

尝试卸载Tensor Flow和keras,并在站点包中删除它们的目录,然后重新安装它们。

t8e9dugd

t8e9dugd3#

pip install qiskit==0.31.0
试试这个。

相关问题