安装了tensorflow导入keras报错

代码1

from keras.models import Sequential
from keras.layers import Input, Dense, Activation, Conv2D, MaxPooling2D, Flatten
from keras.datasets import mnist

报错:

from keras.models import Sequential ModuleNotFoundError: No module named 'keras'

代码修改为

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Input, Dense, Activation, Conv2D, MaxPooling2D, Flatten
from tensorflow.keras.datasets import mnist

代码2

from tensorflow.keras.utils import np_utils

报错

ImportError: cannot import name 'np_utils' from 'tensorflow.keras.utils' 

代码修改为

from tensorflow.python.keras.utils.np_utils import to_categorical

你可能感兴趣的:(问题解决方案集锦,Tensorflow,tensorflow,keras,python)