image and label我有两个分别包含数据的 numpy 变量。500 labeled image每种形状都有image is 240 x 240.import numpy as np
images = np.random.randint(4, size=(500,240,240))
labels = np.random.rand(500,240,240)如何使用 Keras 生成器进行模型训练?在此先感谢您的帮助。
1 回答
慕容3067478
TA贡献1773条经验 获得超3个赞
如果您愿意对图像进行一些小的更改,则可以轻松完成此操作。基本上,您需要向(通道维度)添加一维images。
import numpy as np
import tensorflow as tf
images = np.expand_dims(np.random.randint(4, size=(500,240,240)),-1)
labels = np.random.rand(500,240,240)
gen = tf.keras.preprocessing.image.ImageDataGenerator()
res = gen.flow(images, labels)
x, y = next(res)
您可以通过创建另一个生成器生成 Keras 生成器的数据并删除该维度来进行后处理并删除该维度。
添加回答
举报
0/150
提交
取消