2017-03-15 20 views
8

テンソルフローとケラをインストールしました。そして、私は以下のように簡単なデモがあります。実装畳み込みニューラルネットワークのケラス

from keras.models import Sequential 
from keras.layers import Dense 
import numpy 
# fix random seed for reproducibility 
seed = 7 
numpy.random.seed(seed) 
# load pima indians dataset 
dataset = numpy.loadtxt("pima-indians-diabetes.csv", delimiter=",") 
# split into input (X) and output (Y) variables 
X = dataset[:,0:8] 
Y = dataset[:,8] 
# create model 
model = Sequential() 
model.add(Dense(12, input_dim=8, init='uniform', activation='relu')) 
model.add(Dense(8, init='uniform', activation='relu')) 
model.add(Dense(1, init='uniform', activation='sigmoid')) 
# Compile model 
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) 
# Fit the model 
model.fit(X, Y, nb_epoch=10, batch_size=10) 
# evaluate the model 
scores = model.evaluate(X, Y) 
print("%s: %.2f%%" % (model.metrics_names[1], scores[1]*100)) 

を、私はこの警告がありますので、

/usr/local/lib/python2.7/dist-packages/keras/legacy/interfaces.py:86: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(12, activation="relu", kernel_initializer="uniform", input_dim=8)` '` call to the Keras 2 API: ' + signature) 
/usr/local/lib/python2.7/dist-packages/keras/legacy/interfaces.py:86: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(8, activation="relu", kernel_initializer="uniform")` '` call to the Keras 2 API: ' + signature) 
/usr/local/lib/python2.7/dist-packages/keras/legacy/interfaces.py:86: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(1, activation="sigmoid", kernel_initializer="uniform")` '` call to the Keras 2 API: ' + signature) 
/usr/local/lib/python2.7/dist-packages/keras/models.py:826: UserWarning: The `nb_epoch` argument in `fit` has been renamed `epochs`. warnings.warn('The `nb_epoch` argument in `fit` ' 

を、どのように私はこれを処理することができますか?

+2

警告メッセージには、文字通り何を変更する必要があるかが記載されています。 –

答えて

17

Matiasがこのコメントで言ったように、これはかなり簡単です... Kerasは昨日APIを2.0にアップデートしました。明らかにあなたはそのバージョンをダウンロードしており、デモでは "古い" APIを使用しています。 "古い" APIはまだバージョン2.0で動作するように警告が作成されていますが、変更されると言っていますので、今から2.0 APIを使用してください。

API 2.0に自分のコードを適応させる方法は、「初期化」パラメータを変更することですfit()機能でDense()全ての層のための「kernel_initializer」と同様に「nb_epoch」を「エポック」へ。

from keras.models import Sequential 
from keras.layers import Dense 
import numpy 
# fix random seed for reproducibility 
seed = 7 
numpy.random.seed(seed) 
# load pima indians dataset 
dataset = numpy.loadtxt("pima-indians-diabetes.csv", delimiter=",") 
# split into input (X) and output (Y) variables 
X = dataset[:,0:8] 
Y = dataset[:,8] 
# create model 
model = Sequential() 
model.add(Dense(12, input_dim=8, kernel_initializer ='uniform', activation='relu')) 
model.add(Dense(8, kernel_initializer ='uniform', activation='relu')) 
model.add(Dense(1, kernel_initializer ='uniform', activation='sigmoid')) 
# Compile model 
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) 
# Fit the model 
model.fit(X, Y, epochs=10, batch_size=10) 
# evaluate the model 
scores = model.evaluate(X, Y) 
print("%s: %.2f%%" % (model.metrics_names[1], scores[1]*100)) 

警告は表示されません。コードのkeras 2.0バージョンです。

関連する問題