示例网络上使用Keras的低精度

时间:2017-05-16 07:55:47

标签: python tensorflow keras theano

我从#34;深度学习Python",Jason Brownlee,第10章"花种的多类分类"中运行了一个例子。我正在运行它未经修改,未修改的输入数据..

这本书声称95%的准确率,但是我对theano的收益率低于60%,而使用tenoflow则低于42%。我在Ubuntu 14.04 VM上使用最新的pip安装的keras和CPU运行它,因为我没有GPU可以训练。该代码包括修复numpy的随机种子。

以下是我的virtualenv中使用pip冻结的输出(使用python 2.7):

appdirs==1.4.3
cycler==0.10.0
funcsigs==1.0.2
functools32==3.2.3.post2
h5py==2.7.0
Keras==2.0.4
matplotlib==2.0.2
mock==2.0.0
numpy==1.12.1
packaging==16.8
pandas==0.20.1
pbr==3.0.0
protobuf==3.3.0
pyparsing==2.2.0
python-dateutil==2.6.0
pytz==2017.2
PyYAML==3.12
scikit-learn==0.18.1
scipy==0.19.0
six==1.10.0
subprocess32==3.2.7
tensorflow==1.1.0
Theano==0.9.0
Werkzeug==0.12.1

代码:

import numpy
import pandas
from keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasClassifier
from keras.utils import np_utils
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import KFold
from sklearn.preprocessing import LabelEncoder
from sklearn.pipeline import Pipeline

# fix random seed for reproducibility
seed = 7
numpy.random.seed(seed)
# load dataset
dataframe = pandas.read_csv("iris.csv", header=None)
dataset = dataframe.values
X = dataset[:, 0:4].astype(float)
Y = dataset[:, 4]
# encode class values as integers
encoder = LabelEncoder()
encoder.fit(Y)
encoded_Y = encoder.transform(Y)
# convert integers to dummy variables (i.e. one hot encoded)
dummy_y = np_utils.to_categorical(encoded_Y)
# define baseline model


def baseline_model():
    # create model
    model = Sequential()
    model.add(Dense(4, input_dim=4, init='normal', activation='relu'))
    model.add(Dense(3, init='normal', activation='sigmoid'))
    # Compile model
    model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
    return model


estimator = KerasClassifier(build_fn=baseline_model, nb_epoch=200, batch_size=5, verbose=0)
kfold = KFold(n_splits=10, shuffle=True, random_state=seed)
results = cross_val_score(estimator, X, dummy_y, cv=kfold)
print("Accuracy: %.2f%% (%.2f%%)" % (results.mean()*100, results.std()*100))

准确度低的原因是什么?

0 个答案:

没有答案