【发布时间】:2021-12-14 23:52:45
【问题描述】:
我有一个图像数据集
|-Train
| |-Defective
| |-images
| |-Not_Defective
| |-images
我使用以下函数对这些图像进行了预处理
dir='../input/railwaytrackv4/Dataset _ Railway Track Fault Detection-20210713T183411Z-001/Dataset _ Railway Track Fault Detection/Train'
train_data=tf.keras.utils.image_dataset_from_directory(directory=dir,
labels='inferred',
batch_size=32,
image_size=(256, 256))
它的输出为Found 1469 files belonging to 2 classes.
并且
type(train_data) = tensorflow.python.data.ops.dataset_ops.BatchDataset
如何将此train_data 转换为 numpy 数组?
更新:
我试过了
for x, y in train_data:
x = x.numpy()
y = y.numpy()
但它给出了以下输出
2021-11-01 08:48:15.079479: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:185] None of the MLIR Optimization Passes are enabled (registered 2)
2021-11-01 08:48:25.085070: I tensorflow/core/kernels/data/shuffle_dataset_op.cc:175] Filling up shuffle buffer (this may take a while): 250 of 11760
2021-11-01 08:48:35.132351: I tensorflow/core/kernels/data/shuffle_dataset_op.cc:175] Filling up shuffle buffer (this may take a while): 558 of 11760
2021-11-01 08:48:45.122079: I tensorflow/core/kernels/data/shuffle_dataset_op.cc:175] Filling up shuffle buffer (this may take a while): 843 of 11760
2021-11-01 08:48:55.135867: I tensorflow/core/kernels/data/shuffle_dataset_op.cc:175] Filling up shuffle buffer (this may take a while): 1160 of 11760
2021-11-01 08:49:05.080678: I tensorflow/core/kernels/data/shuffle_dataset_op.cc:175] Filling up shuffle buffer (this may take a while): 1455 of 11760
2021-11-01 08:49:05.657894: I tensorflow/core/kernels/data/shuffle_dataset_op.cc:228] Shuffle buffer filled.
2021-11-01 08:49:05.665031: W tensorflow/core/framework/cpu_allocator_impl.cc:80] Allocation of 1155268608 exceeds 10% of free system memory.
注意: 找到属于 2 个类的 1469 个文件。
【问题讨论】:
标签: python-3.x numpy keras tensorflow2.0 image-recognition