【发布时间】:2018-10-17 08:40:56
【问题描述】:
我正在尝试在 Python 中使用 Keras 来创建一个网络,该网络可以识别来自 MNIST 库的手写数字,用于类项目。
所以在上学期的编程课上,我们使用的是 IDLE,但我在股票 python 上安装 Tensorflow 时遇到问题,所以我下载了 Anaconda 并使用 conda 命令下载了 Keras 和 tensorflow-gpu,
在 Spyder 中一切正常,但是当我打开 .py 文件时,我遇到了一堆错误并且程序崩溃了。
我确认文件是使用 Anaconda 安装路径中的python.exe 打开的。我附上了我的代码和我得到的错误。
from keras.datasets import mnist
import matplotlib.pyplot as plt
import numpy
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Dropout
from keras.layers import Flatten
from keras.layers.convolutional import Conv2D
from keras.layers.convolutional import MaxPooling2D
from keras.utils import np_utils
from keras import backend as K
K.set_image_dim_ordering('th')
def small_CNN():
model = Sequential()
model.add(Conv2D(32, (5, 5), input_shape = (1, 28, 28), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dense(classes, activation='softmax'))
model.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
return model
def big_CNN():
model=Sequential()
model.add(Conv2D(30, (5,5), input_shape = (1, 28, 28), activation = 'relu'))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Conv2D(15, (3, 3), activation = 'relu'))
model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(128, activation = 'relu'))
model.add(Dense(50, activation = 'relu'))
model.add(Dense(classes, activation = 'softmax'))
model.compile(loss='categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
return model
numpy.random.seed(7)
(d_train, c_train), (d_test, c_test) = mnist.load_data()
d_train = d_train.reshape(d_train.shape[0], 1, 28, 28).astype('float32') / 255
d_test = d_test.reshape(d_test.shape[0], 1, 28, 28).astype('float32') / 255
c_train = np_utils.to_categorical(c_train)
c_test = np_utils.to_categorical(c_test)
classes = c_test.shape[1]
model = big_CNN()
model.fit(d_train, c_train, validation_data = (d_test, c_test), epochs = 5, batch_size = 200, verbose = 1)
scores2 = model.evaluate(d_test, c_test, verbose=0)
print(str(scores2[1]*100)+"%")
错误:
Using TensorFlow backend.
2018-05-07 17:14:42.643244: W c:\l\work\tensorflow-1.1.0\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations.
2018-05-07 17:14:42.646784: W c:\l\work\tensorflow-1.1.0\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE2 instructions, but these are available on your machine and could speed up CPU computations.
2018-05-07 17:14:42.650180: W c:\l\work\tensorflow-1.1.0\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
2018-05-07 17:14:42.653900: W c:\l\work\tensorflow-1.1.0\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2018-05-07 17:14:42.657146: W c:\l\work\tensorflow-1.1.0\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2018-05-07 17:14:42.660899: W c:\l\work\tensorflow-1.1.0\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2018-05-07 17:14:42.664397: W c:\l\work\tensorflow-1.1.0\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2018-05-07 17:14:42.667624: W c:\l\work\tensorflow-1.1.0\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
2018-05-07 17:14:42.961063: I c:\l\work\tensorflow-1.1.0\tensorflow\core\common_runtime\gpu\gpu_device.cc:887] Found device 0 with properties:
name: GeForce GTX 960
major: 5 minor: 2 memoryClockRate (GHz) 1.291
pciBusID 0000:01:00.0
Total memory: 2.00GiB
Free memory: 1.12GiB
2018-05-07 17:14:42.965514: I c:\l\work\tensorflow-1.1.0\tensorflow\core\common_runtime\gpu\gpu_device.cc:908] DMA: 0
2018-05-07 17:14:42.967183: I c:\l\work\tensorflow-1.1.0\tensorflow\core\common_runtime\gpu\gpu_device.cc:918] 0: Y
2018-05-07 17:14:42.969153: I c:\l\work\tensorflow-1.1.0\tensorflow\core\common_runtime\gpu\gpu_device.cc:977] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 960, pci bus id: 0000:01:00.0)
2018-05-07 17:14:43.781059: I c:\l\work\tensorflow-1.1.0\tensorflow\core\common_runtime\gpu\gpu_device.cc:977] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 960, pci bus id: 0000:01:00.0)
Train on 60000 samples, validate on 10000 samples
Epoch 1/5
2018-05-07 17:14:45.912647: E c:\l\work\tensorflow-1.1.0\tensorflow\stream_executor\cuda\cuda_dnn.cc:359] could not create cudnn handle: CUDNN_STATUS_NOT_INITIALIZED
2018-05-07 17:14:45.915318: E c:\l\work\tensorflow-1.1.0\tensorflow\stream_executor\cuda\cuda_dnn.cc:366] error retrieving driver version: Unimplemented: kernel reported driver version not implemented on Windows
2018-05-07 17:14:45.925473: E c:\l\work\tensorflow-1.1.0\tensorflow\stream_executor\cuda\cuda_dnn.cc:326] could not destroy cudnn handle: CUDNN_STATUS_BAD_PARAM
2018-05-07 17:14:45.928009: F c:\l\work\tensorflow-1.1.0\tensorflow\core\kernels\conv_ops.cc:659] Check failed: stream->parent()->GetConvolveAlgorithms(&algorithms)
【问题讨论】:
-
请复制/粘贴错误而不是图像 - ho,请把错误格式化为代码块
-
程序崩溃很快,但我会尝试
-
你不能保持窗口打开,只复制/粘贴输出吗? (我对Window一无所知:/)
-
当你说“在 Spyder 中一切正常”,你的意思是你可以在 spyder 中运行你的 keras 代码并到达终点吗?
-
你有没有用 anaconda 创建环境?
标签: python tensorflow keras anaconda spyder