我仍在学习 tensorflow 和 keras,我怀疑这个问题有一个非常简单的答案,我只是因为不熟悉而错过了。
我有一个PrefetchDataset对象:
> print(tf_test)
$ <PrefetchDataset shapes: ((None, 99), (None,)), types: (tf.float32, tf.int64)>
Run Code Online (Sandbox Code Playgroud)
...由特征和目标组成。我可以使用for循环遍历它:
> for example in tf_test:
> print(example[0].numpy())
> print(example[1].numpy())
> exit()
$ [[-0.31 -0.94 -1.12 ... 0.18 -0.27]
[-0.22 -0.54 -0.14 ... 0.33 -0.55]
[-0.60 -0.02 -1.41 ... 0.21 -0.63]
...
[-0.03 -0.91 -0.12 ... 0.77 -0.23]
[-0.76 -1.48 -0.15 ... 0.38 -0.35]
[-0.55 -0.08 -0.69 ... 0.44 -0.36]]
[0 0 1 0 1 0 0 0 1 0 …Run Code Online (Sandbox Code Playgroud) 如果我有一个数据集
dataset = tf.keras.preprocessing.image_dataset_from_directory(
directory,
labels="inferred",
label_mode="int",
class_names=None,
color_mode="rgb",
batch_size=32,
image_size=(32, 32),
shuffle=True,
seed=None,
validation_split=None,
subset=None,
interpolation="bilinear",
follow_links=False,
)
Run Code Online (Sandbox Code Playgroud)
如何将其分成 x 和 y 数组?x 数组将是 IMG 数组,y 数组将包含每个 img 的类别。
在tensorflow 1.12中有Dataset.zip功能:在此处记录。
但是,我想知道是否存在一个数据集解压缩函数,该函数将返回原始的两个数据集。
# NOTE: The following examples use `{ ... }` to represent the
# contents of a dataset.
a = { 1, 2, 3 }
b = { 4, 5, 6 }
c = { (7, 8), (9, 10), (11, 12) }
d = { 13, 14 }
# The nested structure of the `datasets` argument determines the
# structure of elements in the resulting dataset.
Dataset.zip((a, b)) == { (1, 4), (2, 5), …Run Code Online (Sandbox Code Playgroud)