اذهب إلى المحتوى
  • 0

طهور الخطأ ValueError: Error when checking model target: the list of Numpy arrays that you are passing to your model is not the size the model expected في Keras أثناء محاولة استخدام fit_generator

Meezo ML

السؤال

ظهور الخطأ التالي عندما أحاول استخدام fit_generator مع نموذجي:

print(x_train.shape) # (15000, 100, 100, 3)
print(x_test.shape) # (8708, 100, 100, 3)
print(y_train.shape) # (15000, 119)
print(y_test.shape) # (8708, 119)
im=ImageDataGenerator()
data=im.flow(x_train, y_train, 16)
# النموذج
from keras.preprocessing.image import ImageDataGenerator
from keras.layers import AveragePooling2D, MaxPooling2D, Flatten, Conv2D, ZeroPadding2D,Input, Dense, Activation
from keras import layers
from keras.models import Model
x_input = Input((100,100,3))
x = Conv2D(128, (5,5))(x_input)
x = Activation('tanh')(x)
x = MaxPooling2D((3, 3))(x)
x = Conv2D(32, (5,5))(x)
x = Activation('tanh')(x)
x = MaxPooling2D((3, 3))(x)
x = Conv2D(100, (3,3))(x)
x = Activation('tanh')(x)
x = MaxPooling2D((3, 3))(x)
x = Flatten()(x)
x = Dense(256, activation='tanh')(x)
x = Dense(100, activation='tanh')(x)
x = Dense(100, activation='tanh')(x)
output1 = Dense(117, activation='softmax')(x)
output2 = Dense(2, activation='softmax')(x)
model = Model(inputs=x_input, outputs=[output1, output2])
model.compile(optimizer='rmsprop', metrics=['acc'],loss=['categorical_crossentropy'])
model.fit_generator(data, steps_per_epoch=len(x_train) / 16,
                    epochs=5, validation_data=(x_test, y_test))
-------------------------------------------------------------------------------------------------------
ValueError: Error when checking model target: the list of Numpy arrays that you are passing to your model is not the size the model expected.

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 2

لقد قمت بتعريف نموذجك مع مخرجين [output1, output2]، لذلك من المتوقع أن يتم عمل ال fitting مع مصفوفتين مختلفتين من ال label. واحدة بحجم (, 119) والأخرى (,2) وهذا مايتوافق مع طبقتي الإخراج Dense لديك. الحل:

g = ImageDataGenerator() 
def generate_data_generator(g, X, Y1, Y2):
    genX1 = generator.flow(X, Y1, seed=7)
    genX2 = generator.flow(X, Y2, seed=7)
    while True:
        X1i = genX1.next()
        X2i = genX2 .next()
        yield X1i[0], [X1i[1], X2i[1]]
model.fit_generator(generate_data_generator(generator, x_train, y_train, y_train_gender),
                    steps_per_epoch=len(x_train) / 16,
                    epochs=5)

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...