我正在使用一组32x32x32灰度图像,我想在图像上应用随机旋转作为数据增强的一部分,同时通过tflearn + tensorflow训练CNN.我使用以下代码来执行此操作:
# Real-time data preprocessing
img_prep = ImagePreprocessing()
img_prep.add_featurewise_zero_center()
img_prep.add_featurewise_stdnorm()
# Real-time data augmentation
img_aug = ImageAugmentation()
img_aug.add_random_rotation(max_angle=360.)
# Input data
with tf.name_scope('Input'):
X = tf.placeholder(tf.float32, shape=(None, image_size,
image_size, image_size, num_channels), name='x-input')
Y = tf.placeholder(tf.float32, shape=(None, label_cnt), name='y-input')
# Convolutional network building
network = input_data(shape=[None, 32, 32, 32, 1],
placeholder = X,
data_preprocessing=img_prep,
data_augmentation=img_aug)
Run Code Online (Sandbox Code Playgroud)
(我正在使用tensorflow和tflearn的组合来使用两者的功能,所以请耐心等待.如果我使用占位符等方式出现问题,请告诉我.)
我发现使用add_random_rotation(它本身使用scipy.ndimage.interpolation.rotate)将我的灰度图像的第三维视为通道(如RGB通道),并通过围绕z轴的随机角度旋转第三维的所有32个图像(将我的3D图像视为具有32个通道的2D图像).但我希望图像在空间中旋转(围绕所有三个轴).你知道我怎么能这样做吗?是否有用于在空间中轻松旋转3D图像的功能或包装?!