My task is related to multi label classification, and data is imbalance. Therefore, I would like use class_weight.compute_class_weight to address this issues. However, when use it, it shows
AttributeError: 'DataFrameIterator' object has no attribute 'classes'
the current code is below.
test_generator=test_datagen.flow_from_dataframe(
dataframe=test,
directory="/content/hackathon",
x_col="filename",
batch_size=1,
seed=42,
shuffle=False,
class_mode=None,
target_size=(256,256))
#Class imbalance
from sklearn.utils import class_weight
import numpy as np
class_weights = class_weight.compute_class_weight(
'balanced',
np.unique(train_generator.classes),
train_generator.classes)
class_weights
I have searched in Stackoverflow and Google, and still not found yet (my source as follows).
- Google: How to fix"DataFrameIterator' object has no attribute 'num_classes'"?, but not related
- Stackoverflow: How to use flow_from_dataframe with compute_class_weight? << same issue, but not answered yet.