使用 TensorFlow 遍历目录并拍摄我想用于训练神经网络的图像。
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
wk_dir,
labels="inferred",
label_mode="int",
class_names=None,
color_mode="grayscale",
batch_size=batches,
image_size=image_dim,
shuffle=True,
seed=1968,
validation_split=0.2,
subset="training",
interpolation="bilinear",
follow_links=False,
)
Run Code Online (Sandbox Code Playgroud)
找到属于 3 个类别的 127561 个文件。使用102049个文件进行训练。
结果 - 它有效......现在我正在尝试使用它输入到模型中,但不知道如何管理它......
print(train_ds)
<BatchDataset shapes: ((None, 576, 432, None), (None,)), types: (tf.float32, tf.int32)>
Run Code Online (Sandbox Code Playgroud)
那么我在数组中有 2 个元素吗?第一个有 4 个元素,其中 2 个为空,第二个元素是其分类?
我尝试拆分 BatchDatashape 并收到错误TypeError: 'BatchDataset' object is not subscriptable
如何操作对象类型 python.data.ops.dataset_ops.BatchDataset 的 TF ?