jpeg画像をA.Bファイルにいれて画像データをpythonデータ型に変更しました。
次にCNNの実装を行いましたが下記エラーが出ました。解決の方法をお願いします。
コードとエラーは下記です。よろしくお願いします。
from keras.models import Sequential
from keras.layers.convolutional import Conv2D, MaxPooling2D
from keras.layers import Activation, Dropout, Flatten, Dense
import numpy as np
# カテゴリの指定
categories = ["A","B"]
nb_classes = len(categories)
# 画像サイズを指定
image_w = 64
image_h = 64
# データをロード --- (※1)
X_train, X_test, y_train, y_test = np.load("./image/data.npy")
# データを正規化する
X_train = X_train.astype("float32") / 256
X_test = X_test.astype("float32") / 256
print('X_train shape:', X_train.shape)
# モデルを構築 --- (※2)
model = Sequential()
model.add(Conv2D(32, 3, 3, padding='same', input_shape=X_train.shape[1:]))
model.add(Activation('relu'))
model.add(Conv2D(32,3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Conv2D(64, 3, 3, padding='same'))
model.add(Activation('relu'))
model.add(Conv2D(64, 3, 3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten()) # --- (※3)
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(nb_classes)) # ---- (*3a)
model.add(Activation('softmax'))
model.compile(loss='binary_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
# モデルを訓練する --- (※4)
model.fit(X_train, y_train, batch_size=32, nb_epoch=50)
# モデルを評価する --- (※5)
score = model.evaluate(X_test, y_test)
print('loss=', score[0])
print('accuracy=', score[1])
ValueError Traceback (most recent call last)
<ipython-input-1-c8df3491520e> in <module>()
20 # モデルを構築 --- (※2)
21 model = Sequential()
---> 22 model.add(Conv2D(32, 3, 3, padding='same', input_shape=X_train.shape[1:]))
23 model.add(Activation('relu'))
24 model.add(Conv2D(32,3))
/anaconda/lib/python2.7/site-packages/keras/legacy/interfaces.pyc in wrapper(*args, **kwargs)
32 object_name = func.__name__
33 if preprocessor:
---> 34 args, kwargs, converted = preprocessor(args, kwargs)
35 else:
36 converted = []
/anaconda/lib/python2.7/site-packages/keras/legacy/interfaces.pyc in conv2d_args_preprocessor(args, kwargs)
276 if kwd in kwargs:
277 raise ValueError(
--> 278 'It seems that you are using the Keras 2 '
279 'and you are passing both `kernel_size` and `strides` '
280 'as integer positional arguments. For safety reasons, '
ValueError: It seems that you are using the Keras 2 and you are passing both `kernel_size` and `strides` as integer positional arguments. For safety reasons, this is disallowed. Pass `strides` as a keyword argument instead.