Python 低级Tensorflow,dataset.as_numpy_迭代器()返回dict而不是numpy数组

Python 低级Tensorflow,dataset.as_numpy_迭代器()返回dict而不是numpy数组,python,tensorflow,dataset,mnist,low-level,Python,Tensorflow,Dataset,Mnist,Low Level,当我尝试使用中的方法导入和批处理数据集时 当我使用dataset.as_numpy_iterator()时,迭代的对象是dict,即使我应该得到一堆numpy数组。 我的代码如下所示: dataset = tfds.load('mnist', split='train') dataset.batch(batch_size, drop_remainder=False) for i in dataset.as_numpy_iterator(): print(type(i)) # print

当我尝试使用
中的方法导入和批处理数据集时 当我使用dataset.as_numpy_iterator()时,迭代的对象是dict,即使我应该得到一堆numpy数组。
我的代码如下所示:

dataset = tfds.load('mnist', split='train')
dataset.batch(batch_size, drop_remainder=False)
for i in dataset.as_numpy_iterator():
    print(type(i))  # prints <class 'dict'>
dataset=tfds.load('mnist',split='train')
dataset.batch(批大小,drop\u余数=False)
对于dataset.as_numpy_iterator()中的i:
打印(类型(i))#打印

为什么会发生这种情况?

使用as\u supervised=True

import tensorflow_datasets as tfds
dataset = tfds.load('mnist', split='train', as_supervised=True)
dataset.batch(10, drop_remainder=False)
for image, label in tfds.as_numpy(dataset):
    print(type(image), type(label), label)
根据TensorFlow文档,如果as_supervised为False,您将获得字典值。
检查文档

按监管方式使用=真

import tensorflow_datasets as tfds
dataset = tfds.load('mnist', split='train', as_supervised=True)
dataset.batch(10, drop_remainder=False)
for image, label in tfds.as_numpy(dataset):
    print(type(image), type(label), label)
根据TensorFlow文档,如果as_supervised为False,您将获得字典值。 检查文件