tensorflow 可视化来自训练数据批的训练图像

ezykj2lf  于 2023-08-06  发布在  其他
关注(0)|答案(1)|浏览(132)

可视化训练数据批次中的训练图像train_images,train_labels = next(train_data.as_numpy_iterator())show_25_images(train_images,train_labels)

typeError Traceback(most recent call last)in 1 #可视化训练数据批次中的训练图像-> 2 train_images,train_labels = next(train_data.as_numpy_iterator())3 show_25_images(train_images,train_labels)
/usr/local/lib/python3.8/dist-packages/tensorflow/python/data/ops/dataset_ops.py in as_numpy_iterator(self)614 component_spec,615(tensor_spec.TensorSpec,ragged_tensor.RaggedTensorSpec)):--> 616 raise TypeError(617 f”tf.data.Dataset.as_numpy_iterator() is not supported for“618 f“datasets that produce values of type {component_spec.value_type}”)
TypeError:tf.data.Dataset.as_numpy_iterator()不支持生成<class 'tensorflow.python.data.util.structure. NoneTensor'>类型值的数据集
图像集

cnjp1d6j

cnjp1d6j1#

您需要将数据集传递给tf.data.Dataset.from_tensor_slices()tf.data.Dataset.from_tensors()以创建tf.data.Dataset

例如:

import tensorflow as tf
import numpy as np

(train_images, train_labels),(test_images, test_labels) = tf.keras.datasets.fashion_mnist.load_data()
train_images=train_images/255
test_images=test_images/255

train_dataset = tf.data.Dataset.from_tensor_slices((train_images, train_labels))
test_dataset = tf.data.Dataset.from_tensor_slices((test_images, test_labels))

字符串
然后可以通过as_numpy_iterator()迭代tf.data.dataset

train_dataset = tf.data.Dataset.from_tensor_slices((train_images, train_labels))
train_images, train_labels = next(train_dataset.as_numpy_iterator())


或者是

for train_images, train_labels in train_dataset.as_numpy_iterator():
    print(train_images, train_labels)

相关问题