简体   繁体   English

使用 CNN 进行多类图像分类的错误

[英]Errors in Multi class image classification using CNN

I'm fairly new to CNN and python and I'm trying to classify images consisting of 3 classes.我对 CNN 和 python 相当陌生,我正在尝试对由 3 个类组成的图像进行分类。 Whenever I try to train my model I get the error: TypeError: Cannot convert 0.6 to EagerTensor of dtype int64.每当我尝试训练我的模型时,我都会收到错误消息:TypeError:无法将 0.6 转换为 dtype int64 的 EagerTensor。 I'm not fully sure what to make of this or how to fix it and would appreciate any help.我不完全确定该怎么做或如何解决它,并希望得到任何帮助。

Here's the code :这是代码:

train_gen=ImageDataGenerator(rescale=1./255)

validation_gen=ImageDataGenerator(rescale=1./255)

train_generator=train_gen.flow_from_dataframe(
    train_df,
    "/Users/danieladegborioye/Documents/school/FIFTH YEAR/ENGR 418 Applied Machine learning /Lego_dataset_1/training/",
    x_col='filename',
    y_col='category',
    target_size=(150,150),
    class_mode="categorical",
    batch_size=32
)

validation_generator=validation_gen.flow_from_dataframe(
    validate_df,
    "/Users/danieladegborioye/Documents/school/FIFTH YEAR/ENGR 418 Applied Machine learning /Lego_dataset_1/training/",
    x_col='filename',
    y_col='category',
    target_size=(150,150),
    class_mode="categorical",
    batch_size=32
)


epochs=10
batch_size=10

history=modell.fit(
    train_generator,
    epochs=epochs,
    validation_data=validation_generator,
    validation_steps=total_validate/batch_size,
    steps_per_epoch=total_train/batch_size,
    callbacks=callbacks
)

如果batch_size大于total_validatetotal_train ,则steps_per_epoch将小于 1,这会导致此'TypeError: Cannot convert 0.6 to EagerTensor of dtype int64'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM