我是tensorflow和Keras的新手,下面是我的代码
import numpy as np
np.random.seed(123) # for reproducibility
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Convolution2D, MaxPooling2D
from keras.utils import np_utils
from keras.datasets import mnist
(X_train, y_train), (X_test, y_test) = mnist.load_data()
# 5. Preprocess input data
X_train = X_train.reshape(X_train.shape[0], 28, 28, 1)
X_test = X_test.reshape(X_test.shape[0], 28, 28, 1)
X_train = X_train.astype('float32')
X_test = X_test.astype('float32')
X_train /= 255
X_test /= 255
# 6. Preprocess class labels
Y_train = np_utils.to_categorical(y_train, 10)
Y_test = np_utils.to_categorical(y_test, 10)
# 7. Define model architecture
model = Sequential()
model.add(Convolution2D(32, 3, 3, activation='relu', input_shape=
(28,28,1)))
model.add(Convolution2D(32, 3, 3, activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(10, activation='softmax'))
# 8. Compile model
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
# 9. Fit model on training data
model.fit(X_train, Y_train,
batch_size=32, nb_epoch=10, verbose=1)
# 10. Evaluate model on test data
score = model.evaluate(X_test, Y_test, verbose=0)
运行此代码后,我不断收到以下错误
2018-07-31 19:25:45.099850:IC:\ users \ nwani_bazel_nwani \ mmtm6wb6 \ execroot \ org_tensorflow \ tensorflow \ core \ platform \ cpu_feature_guard.cc:140]您的CPU支持未编译此TensorFlow二进制文件的指令使用:AVX AVX2 2018-07-31 19:25:45.711357:I C:\ users \ nwani_bazel_nwani \ mmtm6wb6 \ execroot \ org_tensorflow \ tensorflow \ core \ common_runtime \ gpu \ gpu_device.cc:1356]找到了 设备0具有以下属性: 名称:GeForce 840M主要:5次要:0 memoryClockRate(GHz):1.124 pciBusID:0000:04:00.0 totalMemory:2.00GiB空闲内存:1.66GiB 2018-07-31 19:25:45.718218:I C:\ users \ nwani_bazel_nwani \ mmtm6wb6 \ execroot \ org_tensorflow \ tensorflow \ core \ common_runtime \ gpu \ gpu_device.cc:1435]添加可见的gpu设备:0 2018-07-31 19:25:45.722718:E C:\ users \ nwani_bazel_nwani \ mmtm6wb6 \ execroot \ org_tensorflow \ tensorflow \ core \ common_runtime \ direct_session.cc:154]内部:cudaGetDevice()失败。状态:CUDA驱动程序版本不足于CUDA运行时版本 追溯(最近一次通话): 文件“ c:\ Users \ Seth Siva \ Documents \ mnist digitognir.py”,第44行,在 batch_size = 32,nb_epoch = 10,详细= 1) 文件“ C:\ Users \ Seth Siva \ anaconda \ lib \ site-packages \ keras \ engine \ training.py”,行1042,适合 validate_steps = validation_steps) 在Fit_loop的第199行中,文件“ C:\ Users \ Seth Siva \ anaconda \ lib \ site-packages \ keras \ engine \ training_arrays.py” outs = f(ins_batch) 在调用中的文件“ C:\ Users \ Seth Siva \ anaconda \ lib \ site-packages \ keras \ backend \ tensorflow_backend.py”,第2653行 如果hasattr(get_session(),'_make_callable_from_options'): get_session中的文件“ C:\ Users \ Seth Siva \ anaconda \ lib \ site-packages \ keras \ backend \ tensorflow_backend.py”,第183行 _SESSION = tf.Session(config = config) init 中的文件“ C:\ Users \ Seth Siva \ anaconda \ lib \ site-packages \ tensorflow \ python \ client \ session.py”,第1560行 超级(会话,自我)。初始化(目标,图形,配置=配置) init 中的文件“ C:\ Users \ Seth Siva \ anaconda \ lib \ site-packages \ tensorflow \ python \ client \ session.py”,第633行 self._session = tf_session.TF_NewSession(self._graph._c_graph,选择) tensorflow.python.framework.errors_impl.InternalError:无法创建会话。