keras-team / keras-applications

Reference implementations of popular deep learning models.
Other
2k stars 910 forks source link

Expected to see 2 array(s), but instead got the following list of 1 arrays #87

Closed StephenLouis closed 5 years ago

StephenLouis commented 5 years ago

I want to create a model that receive one image and compute the image by two Softmax(two output). The code is:

base_model = InceptionV3(include_top=False) x = base_model.output x = GlobalAveragePooling2D()(x)

first Softmax

x_1 = Dense(1024, activation='relu')(x) predictions_1 = Dense(4, activation='softmax')(x_1)

second Softmax

x_2 = Dense(1024, activation='relu')(x) predictions_2 = Dense(4, activation='softmax')(x_2)

my_model = Model(inputs=base_model.input, outputs=[predictions_1,predictions_2])

train

my_model.compile(...) my_model.fit_generator(...)

When training, I got error:

ValueError: Expected to see 2 array(s), but instead got the following list of 1 arrays: [array([[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 1., 0., 0.], [1., 0., 0., 0.], [0., 1., 0., 0.], [0., 1., 0., 0.], [0., 1., 0., 0.],...

3Q~

goodyduru commented 5 years ago

The problem should be with your y parameter in your generator function. When your model produces an output containing a list of two arrays, then your y parameter in your generator function has to be a list of two arrays.

taehoonlee commented 5 years ago

@StephenLouis, You should pass parameters like fit(x, [y1, y2]) where x is (n, 299, 299, 3) and y1, y2 are (n, 4). In case of fit_generator, a generator should yield x, [y1, y2].