tensorflow2.0中的旋转图像及其关键点标签

时间:2019-07-30 11:18:58

标签: tensorflow2.0 data-augmentation

我正在尝试将旋转添加到标签具有某些面部关键点的图像数据集中。从tensorflow 2.0中删除了tf.contrib,并且像我使用tf.data.Dataset一样,其他任何库(如PIL)也无法正常工作。

我需要将角度旋转为随机角度,同时还要对图像及其关键点标签应用相同的旋转角度。在tensorflow 2.0中有办法做到这一点吗?

以下是我使用的功能:

def preprocess_data(image, angle):
    image = tf.image.decode_jpeg(image, channels=3)
    image = tf.image.resize(image, [input_size, input_size])
    image = tf.image.rgb_to_grayscale(image)

    image = Image.fromarray(np.array(tf.squeeze(image)))
    rotated = Image.Image.rotate(image, angle)

    image = tf.convert_to_tensor(np.array(rotated))
    image = tf.expand_dims(image, -1)
    return image

def load_and_preprocess_data(path):
    image = tf.io.read_file(path)
    rotation = tf.random.uniform([1,1], minval=-60, maxval=60, seed=0)
    return preprocess_data(image, rotation)

在这里我使用了PIL,但是当我尝试将包含图像路径的tf.data.Dataset映射到load_and_preprocess_data函数时,它不起作用。

0 个答案:

没有答案