Keras RandomRotation 层产生黑线?
Keras RandomRotation layer produces black lines?
我正在尝试使用 Keras RandomRotation 扩充我的图像数据集。这是代码:
data_augmentation = tf.keras.Sequential([
keras.layers.experimental.preprocessing.RandomRotation(
0.5,
fill_mode='reflect',
interpolation='bilinear')
])
im = data_augmentation(valid_images[0:1])[0]
plt.imshow(im)
plt.show()
很遗憾,生成的图像包含黑线。我喜欢反射填充模式,所以我想保留它。你能建议我可以摆脱黑线并产生更平滑的图像吗?可以用 Numpy 做同样的事情吗?我尝试设置插值='nearest',但这没有帮助。
使用scipy.ndimage.rotate
:
import tensorflow as tf
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import scipy
img = np.array(Image.open("s.jpg"))
im = scipy.ndimage.rotate(img, 30, mode='reflect', reshape=False)
plt.imshow(im)
plt.show()
输出:
我正在尝试使用 Keras RandomRotation 扩充我的图像数据集。这是代码:
data_augmentation = tf.keras.Sequential([
keras.layers.experimental.preprocessing.RandomRotation(
0.5,
fill_mode='reflect',
interpolation='bilinear')
])
im = data_augmentation(valid_images[0:1])[0]
plt.imshow(im)
plt.show()
很遗憾,生成的图像包含黑线。我喜欢反射填充模式,所以我想保留它。你能建议我可以摆脱黑线并产生更平滑的图像吗?可以用 Numpy 做同样的事情吗?我尝试设置插值='nearest',但这没有帮助。
使用scipy.ndimage.rotate
:
import tensorflow as tf
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import scipy
img = np.array(Image.open("s.jpg"))
im = scipy.ndimage.rotate(img, 30, mode='reflect', reshape=False)
plt.imshow(im)
plt.show()
输出: