Voting classifier doesnt allow multi class

12 views Asked by At

i have created a a models using inceptionV3, MobileNet for image classification. Those are like this.

base_model = InceptionV3(weights='imagenet', include_top=False, input_shape=(img_height, img_width, 3))

# Freeze the pre-trained layers
base_model.trainable = False

# Create a new model on top of the InceptionV3 base
model = Sequential([
    data_augmentation,
    layers.Rescaling(1./255),
    base_model,
    layers.GlobalAveragePooling2D(),
    layers.Dense(200, activation='relu'),  # Increased units in the dense layer
    layers.BatchNormalization(),
    layers.Dropout(0.3),  # Increased dropout rate
    layers.Dense(100, activation='relu'),  # Adding another dense layer
    layers.BatchNormalization(),
    layers.Dropout(0.3),  # Adding dropout for regularization
    layers.Dense(50, activation='relu'),  # Adding another dense layer
    layers.BatchNormalization(),
    layers.Dense(num_classes, activation='softmax')  # Changed activation to softmax for classification
])

# Compile the model
base_learning_rate = 0.08
model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=base_learning_rate),
              loss=tf.keras.losses.CategoricalCrossentropy(),
              metrics=['accuracy'])

# Train the model
epochs = 10
history = model.fit(
    X_train, 
    y_train,
    validation_data=(X_test, y_test),
    epochs=epochs,
    verbose=1
)

then i input those models into voting classifier and it says

NotImplementedError: Multilabel and multi-output classification is not supported.

My voting classifier code looks like this.

labels = ['InceptionV3', 'MobileNet']
voting_clf_hard = VotingClassifier(
    estimators=[
        (labels[0], model),  
        (labels[1], modelMo),  
    ],
    voting='soft'  
)```



and my data looks like this.

X_train shape: (1890, 224, 224, 3)
y_train shape: (1890, 6)
X_test shape: (472, 224, 224, 3)
y_test shape: (472, 6)




Can you explain why this happens?
0

There are 0 answers