Ошибка - форма выходного слоя в нейронной сети, не может определить ошибку в размерах - PullRequest
0 голосов
/ 15 мая 2018

Я начинаю с нейронных сетей. Я построил модель и обучил ее в своем учебном наборе данных. Но когда я пытаюсь оценить модель, я получаю ошибку несоответствия размеров: ValueError: Error when checking target: expected dense_16 to have shape (3,) but got array with shape (1,). Что касается меня, я не могу понять, откуда в определении модели он возникает. Любая помощь приветствуется.

Определение модели: enter image description here

Обучение: enter image description here

Оценка (ошибка): enter image description here

Код:

# Building a model - build a simple feedforward neural network for this problem.

# Specify all the parameters we will be using in our network
input_num_units = (32, 32, 3)
hidden_num_units = 1000
output_num_units = 3

epochs = 10
batch_size = 128

from keras.models import Sequential
from keras.layers import Dense, Flatten, InputLayer



# Define the network/model
model = Sequential([
  InputLayer(input_shape=input_num_units),
  Flatten(),
  Dense(units=hidden_num_units, activation='relu'),
  Dense(units=output_num_units, activation='softmax'),
])



model.summary()


# Compile our network and let it train for a while, with cross validation

model.compile(optimizer='sgd', loss='categorical_crossentropy', metrics=['accuracy'])
model.fit(train_x, train_y, batch_size=batch_size,epochs=epochs,verbose=1, validation_split=0.2)


score = model.evaluate(test_x, test_y, verbose=0)
print('Test loss:', score[0])
print('Test accuracy:', score[1])

1 Ответ

0 голосов
/ 15 мая 2018

Возможно, я ошибаюсь, но вы также использовали to_categorical в своих тестовых данных, которые вы пытаетесь оценить?

y_test = to_categorical(y_test,num_classes)
...