首页 > 解决方案 > 将 random_shear 增强应用于图像张量

问题描述

我正在尝试random_shear从 Keras 应用图像增强,但在此之后图像完全失真。

shape = inputs.shape #(32,512,512,3)

temp = np.empty(shape=(shape[0], shape[1],shape[2], shape[3]))

for i in range(shape[0]):
    array_inputs = tf.keras.preprocessing.image.img_to_array(inputs[i])
    sheared = tf.keras.preprocessing.image.random_shear(array_inputs, .2,
                                            row_axis=0, col_axis=1,
                                            channel_axis=2)
    temp[i]= sheared
return tf.convert_to_tensor(temp)

我不确定这里有什么问题。有人可以在这里帮助我吗?

标签: tensorflowkerastensor

解决方案


值得一提的是,这是我测试的代码:

import tensorflow as tf
import numpy as np
from PIL import Image 

inputs = [Image.open('./homersimpson.0.0.jpg')]
shape = (1,1400,1400,3)

temp = np.empty(shape=(shape[0], shape[1],shape[2], shape[3]))

for i in range(shape[0]):
    array_inputs = tf.keras.preprocessing.image.img_to_array(inputs[i])
    sheared = tf.keras.preprocessing.image.random_shear(array_inputs, 50,
                                            row_axis=0, col_axis=1,
                                            channel_axis=2)
    temp[i]= sheared

for i in range(shape[0]):
    tf.keras.preprocessing.image.array_to_img(temp[i]).show()

转动这个图像:

在此处输入图像描述

对此:

在此处输入图像描述


推荐阅读