【问题标题】:Split dataset Cats_vs_dogs to train and val with tf 2.3.0拆分数据集 Cats_vs_dogs 以使用 tf 2.3.0 进行训练和验证
【发布时间】:2020-10-13 08:39:36
【问题描述】:

我尝试使用 split 函数拆分 Cats_vs_dogs 数据集,但我无法检查它是否有效。当我在 train_info 和 val_info 上调用 num_example 时,我得到了相同的数字 23262。为什么?

    dataset, info = tfds.load('cats_vs_dogs',
                              split='train',
                              shuffle_files=True,
                              as_supervised=True,
                              with_info=True
                              )                                                                                            
    ds_train, train_info = tfds.load(
                            'cats_vs_dogs',
                            split='train[:80%]',
                            shuffle_files=True,
                            as_supervised=True,
                            with_info=True
                            )
    ds_val, val_info= tfds.load(
                        'cats_vs_dogs',
                        split='train[-20%:]',
                        shuffle_files=True,
                        as_supervised=True,
                        with_info=True
                        )

    print(train_info.splits['train'].num_examples)
    print(train_info.splits['train'].num_shards)
    print(val_info.splits['train'].num_examples)
    print(val_info.splits['train'].num_shards)

我从 train_info、info 和 val_info 中获得了 23262 个示例!

【问题讨论】:

    标签: python tensorflow tensorflow2.0 tensorflow-datasets


    【解决方案1】:

    因此,要从每个拆分中获取示例数量,我们必须要求 train_info.splits['train[:80%]'].num_examples 和 val_info.splits['train[-20%:]'].num_examples

    更适合拆分数据集,使用 tf.keras.preprocessing.image_dataset_from_directory 对我来说效果更好。

    【讨论】:

      猜你喜欢
      • 2020-05-11
      • 1970-01-01
      • 2019-04-22
      • 1970-01-01
      • 2019-05-01
      • 2019-03-15
      • 2016-09-13
      • 2017-11-05
      • 2021-01-08
      相关资源
      最近更新 更多