“如何修复”;DataFrameIterator';对象没有属性';num#u类'&引用;?

“如何修复”;DataFrameIterator';对象没有属性';num#u类'&引用;?,dataframe,keras,tf.keras,Dataframe,Keras,Tf.keras,我正在使用tf.keras.preprocessing.image.ImageDataGenerator类加载训练图像。我选择使用flow_from_dataframe函数。但是,当我尝试使用num_类创建一个层时,出现了错误:AttributeError:'DataFrameIterator'对象没有属性'num_类' datagen=tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255.) image_data

我正在使用tf.keras.preprocessing.image.ImageDataGenerator类加载训练图像。我选择使用flow_from_dataframe函数。但是,当我尝试使用num_类创建一个层时,出现了错误:AttributeError:'DataFrameIterator'对象没有属性'num_类'

    datagen=tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255.)

image_data=datagen.flow_from_dataframe(
dataframe=df[:1700],
directory='/tf/notebooks/2222/Face Images',
x_col="Filename",
y_col="Race",
batch_size=32,
#seed=42,
shuffle=True,
class_mode="categorical",
target_size=(224,224))

model = tf.keras.Sequential([
  feature_extractor_layer,
  layers.Dense(image_data.num_classes, activation='softmax')
])

model.summary()

您需要使用另一种方法从数据帧获取
flow\u情况下的类数:

例如:
len(列车发电机等级索引)

因此,您的代码应该如下所示:

model = tf.keras.Sequential([
  feature_extractor_layer,
  layers.Dense(len(image_data.class_indices), activation='softmax')
])