Я кодирую пример классификации изображений с помощью Keras.Он также фокусируется на примерах.Я ожидал бы массив с размером ошибки 2, но в результате получился массив размером 1. Я не знаю, где я был не прав.
Это для linux 16.04, работает keras, tenorflow, python3.6 с conda, графическая карта nvidia RTX 2080 Ti * 2, версия графического драйвера - 415.27, версия cuda - 10.0.
Это мой основной код.
train_datagen = ImageDataGenerator(rescale=1./255)
train_generator = train_datagen.flow_from_directory('./Train',
target_size = (640,480), batch_size = 3,
class_mode = 'categorical')
test_datagen = ImageDataGenerator(rescale=1./255)
test_generator = test_datagen.flow_from_directory('./Test',
target_size = (640,480), batch_size = 3,
class_mode = 'categorical')
svffn = models.create_svffn(640,480,3)
cvffn = models.create_cvffn(640,480,3)
combinedInput = concatenate([svffn.output, cvffn.output])
x = Dense(2, activation="softmax")(combinedInput)
model = Model(inputs = [svffn.input, cvffn.input], outputs = x)
opt = optimizers.SGD(lr=1e-5, momentum = 0.9, decay=1e-5 / 200)
model.compile(loss="categorical_crossentropy", optimizer=opt, metrics=
['accuracy'])
model.summary()
model.fit_generator(train_generator, steps_per_epoch = 15, epochs=80,
validation_data = test_generator, validation_steps = 5,
verbose=1)
print("-- Evaluate --")
scores = model.evaluate_generator(test_generator, steps=5)
print("%s: %.2f%%" %(model.metrics_names[1], scores[1]*100))
Этокод моей модели.
def create_svffn(width, height, depth):
inputShape = (height, width, depth)
inputs = Input(shape=inputShape)
x = GlobalMaxPooling2D()(inputs)
x = Dense(256)(x)
x = Activation("relu")(x)
x = Dense(128)(x)
x = Activation("relu")(x)
model = Model(inputs, x)
return model
def create_cvffn(width, height, depth):
inputShape = (height, width, depth)
inputs = Input(shape=inputShape)
x = Conv2D(64,(1,1), activation="relu")(inputs)
x = Flatten()(x)
x = Dense(256)(x)
x = Activation("relu")(x)
x = Dense(128)(x)
x = Activation("relu")(x)
model = Model(inputs, x)
return model
Это моя ошибка.
ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 2 array(s), but instead got the following list of 1 arrays: [array([[[[0.6784314 , 0.7607844 , 0.7843138 ],
[0.5019608 , 0.58431375, 0.65882355],
[0.35686275, 0.43921572, 0.5137255 ],
...,
[0.6627451 , 0.65882355, 0.69411767...
Фактическое обучение должно быть хорошим, а конечным результатом должна быть точность.