ImportError:没有名为“ tensorflow.python”的模块
keras
neural-network
python
tensorflow
3
0

在这里我想运行此代码以尝试使用python进行神经网络:

from __future__ import print_function 
from keras.datasets import mnist from 
keras.models import Sequential from 
keras.layers import Activation, Dense 
from keras.utils import np_utils 
import tensorflow as tf


batch_size = 128 nb_classes = 10 nb_epoch = 12

#input image dimensions img_row, img_cols = 28, 28

#the data, Shuffled and split between train and test sets (X_train, y_train), (X_test, y_test) = mnist.load_data()


X_train = X_train.reshape(X_train.shape[0], img_rows * img_cols)

X_test = X_test.reshape(X_test.shape[0], img_row * img_cols)

X_train = X_train.astype('float32') X_test = X_test.astype('float32') X_train /= 255 X_text /= 255

print('X_train shape:', X_train.shape) print(X_train_shape[0], 'train samples') print(X_test_shape[0], 'test samples')

#convert class vectors to binary category

Y_train = np_utils.to_categorical(y_train, nb_classes)

Y_test = np_utils.to_categorical(y_test, nb_classes)

model = Sequential()

model.add(Dense(output_dim = 800, input_dim=X_train.shape[1])) model.add(Activation('sigmoid')) model.add(Dense(nb_classes)) model.add(Actiovation('softmax'))

model.compile(loss = 'categorical_crossentropy', optimizer='sgd', metrics=['accuracy']) #crossentropy fungsi galat atau fungsi error dipakai kalo class biner



#model.fit(X_train, Y_train, batch_size=batch_size, nb_epoch = nb_poch, verbose=1, validation_data=(X_test, Y_test))

score = model.evaluate(X_test, Y_test, verbose = 0) print('Test Score : ', score[0]) print('Test Accuracy : ', score[1])

一开始它必须安装keras,并成功。但是当尝试首先运行代码时,错误是:

ImportError:没有模块名称“ tensorflow”

然后我使用pip安装:

点安装tensorflow

安装后,我尝试再次运行代码,得到了另一条这样的消息:

ImportError:没有模块名称“ tensorflow.python”

消息错误我对错误一无所知

参考资料:
Stack Overflow
收藏
评论
共 1 个回答
高赞 时间 活跃

卸载tensorflow:

pip uninstall tensorflow

然后重新安装它:

pip install tensorflow
收藏
评论
新手导航
  • 社区规范
  • 提出问题
  • 进行投票
  • 个人资料
  • 优化问题
  • 回答问题

关于我们

常见问题

内容许可

联系我们

@2020 AskGo
京ICP备20001863号