【问题标题】:Changing a TF Dataset from classified to numeric/regression data将 TF 数据集从分类数据更改为数值/回归数据
【发布时间】:2021-05-14 15:39:39
【问题描述】:

这是我第一次尝试从现成的数据集和模型扩展到我自己拼凑的东西。使用 tensorflow,我正在尝试加载图像数据集,其中每个图像都分配了一个标准化的数值,以便我可以尝试在其上构建回归 CNN。 对我来说不幸的是,tf.keras.preprocessing.image_dataset_from_directory 期望数据集是离散分类的。 有没有一种直接的方法将 BatchDataset 对象转换为数字标签?

为了进一步澄清,如果我要做dir(my_dataset) 或my_dataset.__dict__,我想知道标签在哪里。

【问题讨论】:

  • 如果你得到错误然后显示它有问题。始终将有问题的完整错误消息(从“Traceback”一词开始)(不是评论)作为文本(不是屏幕截图,不是指向外部门户的链接)。还有其他有用的信息。
  • 我不明白是什么问题。加载它,对其进行预处理,然后将标签转换为数字 (LabelEncoding),您可以将其与回归一起使用。
  • 如果我的问题听起来像是投诉,我深表歉意。我不是在调试错误,而是在询问有关 DataSet 数据结构的更多信息。我会阅读更多关于LabelEncoder 谢谢的信息。

标签: python tensorflow conv-neural-network tensorflow2.0


【解决方案1】:

我可以在从tf.keras.preprocessing.image_dataset_from_directory 返回的BatchDataSet 对象上多花点时间来回答这个问题

因为这些对象是非常专业的迭代器,所以访问单个“行”并不简单。 以下是我如何从 BatchDataSet 直接访问此信息所在的位置。

training_ds = tf.keras.preprocessing.image_dataset_from_directory(
    "assets/",
    validation_split=0.2,
    subset="training",
    seed=123,
    color_mode="rgb",
    image_size=(IMG_SIZE, IMG_SIZE),
    batch_size=32)
# pull one batch from the BatchDataSet
one_batch = training_ds.take(1)
# transform the TakeDataset into a python iterator and then pull one batch using next()
training_data, labels = next(iter(batch))
# labels is a numpy array of int32 where each integer is the index of the class inside training_ds.class_names 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-24
    • 2016-06-26
    • 1970-01-01
    • 1970-01-01
    • 2019-09-29
    • 2017-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多