keras示例不起作用

编程入门 行业动态 更新时间:2024-10-27 08:31:16
本文介绍了keras示例不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试研究Keras库,并且尝试从 github/fchollet/keras/tree/master/examples

I am trying to study Keras library and I tried to run this example from github/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() modelpile(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])

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

and than I got this error docs.google/document/d/1bo24LXbfK-NzqOBmblqM5KL91P3L3FMD1Wzq-Z5VMq0/edit?usp=sharing

我正在使用最新版本的amd gpu,python 3.5和keras运行Windows 10 64bit

I'm running windows 10 64bit with amd gpu, python 3.5 and keras in the latest version

推荐答案

不幸的是,Keras和Theano在Windows上的Python 3上不能很好地工作.您遇到的问题与以下事实有关:您必须将libpython库添加到C ++ Windows编译器,并将其与Python安装连接,而在安装Python 3.5的情况下,这可能会非常困难.我建议您将其安装在Python 2上.在这里,您有确切的操作说明:

Unfortunately, Keras and Theano don't work well with Python 3 on Windows. The problem you have is connected with the fact that you have to add libpython libraries to your C++ Windows Compiler and connect it with your Python installation which could be quite harsh when you have Python 3.5 installed. I would rather advice you to install it on Python 2. Here you have an exact instruction how to do it :

如何进行在Windows的Anaconda Python中安装Keras和Theano吗?

更多推荐

keras示例不起作用

本文发布于:2023-11-15 07:07:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1592234.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:示例   不起作用   keras

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!