0
$\begingroup$

I am trying to use the xgboost classifier for a multi-label and multi-class image classification task. I have a list of images that can have up to 5 different labels in each of them. Before I use the classifier I want to also apply image augmentation.

import keras
from sklearn.model_selection import train_test_split
from keras.preprocessing.image import ImageDataGenerator
from xgboost.sklearn import XGBClassifier

train_idx, val_idx = train_test_split(mask_df.index,  test_size=0.2,random_state=28)

train_datagen=ImageDataGenerator(zoom_range=0.1,
                              fill_mode='constant',
                              rotation_range=10,
                              height_shift_range=0.1,
                              width_shift_range=0.1,
                              horizontal_flip=True,
                              vertical_flip=True,
                              rescale=1/255.)

train_generator=train_datagen.flow_from_dataframe(
                dataframe=mask_df.loc[train_idx],
                directory="home/DATA/train_images/",
                x_col="ImageId",
                y_col=columns,
                color_mode='grayscale',
                batch_size=32,
                seed=32,
                shuffle=True,
                class_mode="other",
                target_size=(100,100)) 

model = XGBClassifier()
history=model.fit_generator(generator=train_generator,
                steps_per_epoch=100,
                validation_data=validation_generator,
                validation_steps=100,
                epochs=5)

The last command gives me an error:

AttributeError                            Traceback (most recent call last)
<ipython-input-8-8c4c0504d559> in <module>
----> 1 history=model.fit_generator(generator=train_generator,
      2                     steps_per_epoch=100,
      3                     validation_data=validation_generator,
      4                     validation_steps=100,
      5                     epochs=5

AttributeError: 'XGBClassifier' object has no attribute 'fit_generator'

Does anyone have any advice on how to proceed since I can not use the fit_generator?

$\endgroup$
  • $\begingroup$ 'XGBClassifier' object has no attribute 'fit_generator'... it is exactly what it says. $\endgroup$ – Peter Nov 4 '19 at 6:41
  • $\begingroup$ I was hoping if someone knows how to use this classifier with the data augmentation, maybe another way. $\endgroup$ – AL B Nov 4 '19 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.