【问题标题】:Using your own dataset with tfds.load in google在谷歌中使用你自己的数据集和 tfds.load
【发布时间】:2021-04-19 20:05:49
【问题描述】:

总的来说,我是 Python 和 TensorFlow 的初学者,所以这是一个非常愚蠢的问题,但我仍然很困惑。我正在尝试创建一个图像分类器,但我不想使用 TensorFlow 已经拥有的数据集之一(在本例中为“bean”),而是想使用我自己的数据集。作为参考,这称为“花朵检测”,图像分为“训练”和“测试”。我已经将它上传到 Google Drive 并挂载了它,但我不知道如何在 tfds.load 中使用它。我正在学习教程,有没有办法可以更改下面的这行代码以使用我自己的数据集?

ds_test = tfds.load(name="beans", split="test")

如何将数据集从 Google Drive 导入 tfds.load?我是放入完整的文件夹,名称为“flower-detection”,还是分别放入“flower-detection/training”和“flower-detection/testing”?

我已经尝试过上网,但没有找到任何可行的方法。感谢您的帮助。

【问题讨论】:

    标签: python tensorflow image-processing keras google-colaboratory


    【解决方案1】:

    enter code here根据link,tfds 提供了即用型数据集。这意味着,没有任何规定可以上传您自己的并使用它。

    但是,这不是路的尽头,你可以从 tensorflow 关注这个tutorial。我将概述创建数据集时必须使用的重要代码。

    train_ds = tf.keras.preprocessing.image_dataset_from_directory(
      data_dir,
      subset="training",
      seed=123,
      image_size=(img_height, img_width),
      batch_size=batch_size)
    
    val_ds = tf.keras.preprocessing.image_dataset_from_directory(
      data_dir,
      subset="validation",
      seed=123,
      image_size=(img_height, img_width),
      batch_size=batch_size)
    

    这里根据你的训练和测试路径使用data_dir。

    然后你就可以用它来训练模型了。

    history = model.fit(
      train_ds,
      validation_data=val_ds,
      epochs=epochs
    )
    

    【讨论】:

    • 正如我在回答中所写的那样,data_dir 应该是您的训练和测试文件的路径。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    • 1970-01-01
    • 1970-01-01
    • 2022-12-15
    • 2016-06-04
    • 2017-10-26
    • 2015-03-17
    相关资源
    最近更新 更多