来自 numpy 数组的 Keras 自定义数据生成器

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 生成器进行模型训练?在此先感谢您的帮助。


catspeake
浏览 89回答 1
1回答

慕容3067478

如果您愿意对图像进行一些小的更改,则可以轻松完成此操作。基本上,您需要向(通道维度)添加一维images。import numpy as npimport tensorflow as tfimages = 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 生成器的数据并删除该维度来进行后处理并删除该维度。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python