在tensorflow 1中增加图像会导致返回一个张量
我想在不使用keras的情况下增强我的图像。我看到了那个网站:在tensorflow 1中增加图像会导致返回一个张量,tensorflow,Tensorflow,我想在不使用keras的情况下增强我的图像。我看到了那个网站: 问题是我将和图像作为输入,但将张量作为输出(使用keras imagegenerator时并非如此)。我该怎么处理呢?在增加数据后,我希望返回相同类型的对象。Tensorflow通过两种方式提供图像增强,一种是使用tf.keras预处理库,另一种是使用tf.image。 将以下示例代码用于tf.image执行图像增强 def augment(image_label, seed): image, label = image_lab
问题是我将和图像作为输入,但将张量作为输出(使用keras imagegenerator时并非如此)。我该怎么处理呢?在增加数据后,我希望返回相同类型的对象。Tensorflow通过两种方式提供图像增强,一种是使用tf.keras预处理库,另一种是使用tf.image。 将以下示例代码用于tf.image执行图像增强
def augment(image_label, seed):
image, label = image_label
image, label = resize_and_rescale(image, label)
image = tf.image.resize_with_crop_or_pad(image, IMG_SIZE + 6, IMG_SIZE + 6)
# Make a new seed
new_seed = tf.random.experimental.stateless_split(seed, num=1)[0, :]
# Random crop back to the original size
image = tf.image.stateless_random_crop(
image, size=[IMG_SIZE, IMG_SIZE, 3], seed=seed)
# Random brightness
image = tf.image.stateless_random_brightness(
image, max_delta=0.5, seed=new_seed)
image = tf.clip_by_value(image, 0, 1)
return image, label
按照教程获取信息。在增强图像后,只需使用
tf.data.Dataset.from\u tensor\u slices()
构建tf.data.Dataset
对象。使用此对象训练模型。