keras深度学习模型输入,输出向量的数组大小平衡

时间:2019-04-29 14:23:00

标签: image tensorflow keras deep-learning classification

我正在用Keras编码图像分类示例。它还关注连接的示例。 我希望错误大小为2的数组,但结果是大小为1的数组。 我不知道我哪里错了。

这是针对Linux 16.04,运行keras,tensorflow,带conda的python3.6,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...

实际学习应该很好,最终结果应该是准确性。

0 个答案:

没有答案