以下のようなCNN学習器作成でエラーが出ます。原因が良く分かりません。
どなかた詳しい方、ご指導をお願いいたします。
optimizers ="Adadelta" results = {} epochs = 200 model.compile(loss='categorical_crossentropy', optimizer=optimizers, metrics=['accuracy']) #x_train, y_train, batch_size=batch_size, epochs=epochs,erbose=1, validation_data=(x_test, y_test) results= model.fit(X_train, y_train, validation_split=0.2, epochs=epochs ) model_json_str = model.to_json() open('dokugyo_mlp_weights.json', 'w').write(model_json_str) model.save_weights('dokugyo_mlp_weights.h5');
以下、エラーメッセージ
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-26-71d4f9fdc3b9> in <module> 4 model.compile(loss='categorical_crossentropy', optimizer=optimizers, metrics=['accuracy']) 5 #x_train, y_train, batch_size=batch_size, epochs=epochs,erbose=1, validation_data=(x_test, y_test) ----> 6 results= model.fit(X_train, y_train, validation_split=0.2, epochs=epochs ) 7 8 model_json_str = model.to_json() ~\Anaconda3\lib\site-packages\keras\engine\training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs) 950 sample_weight=sample_weight, 951 class_weight=class_weight, --> 952 batch_size=batch_size) 953 # Prepare validation data. 954 do_validation = False ~\Anaconda3\lib\site-packages\keras\engine\training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_array_lengths, batch_size) 807 # using improper loss fns. 808 check_loss_and_target_compatibility( --> 809 y, self._feed_loss_fns, feed_output_shapes) 810 else: 811 y = [] ~\Anaconda3\lib\site-packages\keras\engine\training_utils.py in check_loss_and_target_compatibility(targets, loss_fns, output_shapes) 271 raise ValueError( 272 'You are passing a target array of shape ' + str(y.shape) + --> 273 ' while using as loss `categorical_crossentropy`. ' 274 '`categorical_crossentropy` expects ' 275 'targets to be binary matrices (1s and 0s) ' ValueError: You are passing a target array of shape (50, 1) while using as loss `categorical_crossentropy`. `categorical_crossentropy` expects targets to be binary matrices (1s and 0s) of shape (samples, classes). If your targets are integer classes, you can convert them to the expected format via: `` from keras.utils import to_categorical y_binary = to_categorical(y_int) `` Alternatively, you can use the loss function `sparse_categorical_crossentropy` instead, which does expect integer targets.
あなたの回答
tips
プレビュー