gpt4 book ai didi

python - keras 示例不起作用

转载 作者:行者123 更新时间:2023-11-28 21:47:05 25 4
gpt4 key购买 nike

我正在尝试研究 Keras 库,并尝试从 https://github.com/fchollet/keras/tree/master/examples 运行这个示例

'''Trains a simple deep NN on the MNIST dataset.
Gets to 98.40% test accuracy after 20 epochs
(there is *a lot* of margin for parameter tuning).
2 seconds per epoch on a K520 GPU.
'''

from __future__ import print_function
import numpy as np
np.random.seed(1337) # for reproducibility

from keras.datasets import mnist
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation
from keras.optimizers import SGD, Adam, RMSprop
from keras.utils import np_utils


batch_size = 128
nb_classes = 10
nb_epoch = 20

# 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(60000, 784)
X_test = X_test.reshape(10000, 784)
X_train = X_train.astype('float32')
X_test = X_test.astype('float32')
X_train /= 255
X_test /= 255
print(X_train.shape[0], 'train samples')
print(X_test.shape[0], 'test samples')

# convert class vectors to binary class matrices
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(512, input_shape=(784,)))
model.add(Activation('relu'))
model.add(Dropout(0.2))
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dropout(0.2))
model.add(Dense(10))
model.add(Activation('softmax'))

model.summary()

model.compile(loss='categorical_crossentropy',
optimizer=RMSprop(),
metrics=['accuracy'])

history = model.fit(X_train, Y_train,
batch_size=batch_size, nb_epoch=nb_epoch,
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])

然后我得到了这个错误 https://docs.google.com/document/d/1bo24LXbfK-NzqOBmblqM5KL91P3L3FMD1Wzq-Z5VMq0/edit?usp=sharing

我正在运行带有 amd gpu、python 3.5 和 keras 的最新版本的 windows 10 64bit

最佳答案

不幸的是,Keras 和 Theano 不能很好地与 Windows 上的 Python 3 配合使用。您遇到的问题与您必须将 libpython 库添加到您的 C++ Windows 编译器并将其与您的 Python 安装连接这一事实有关,这在您安装了 Python 3.5 时可能会非常苛刻。我宁愿建议你在 Python 2 上安装它。这里有一个具体的安装说明:

How do I install Keras and Theano in Anaconda Python on Windows?

关于python - keras 示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37053219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com