python - tensorflow 中的批量图像增强

标签 python tensorflow data-augmentation

我想做图像增强,例如,在 tensorflow 中旋转随机角度。在每个批处理中,我想为每个图像旋转不同的随机角度。我可以通过使用 tf.contrib.image.rotateimage_batch 并随机生成角度张量来实现:

radian = tf.random_uniform(
    (batch_size),  
    minval=-ROT_TH,
    maxval=ROT_TH,
    dtype=tf.float32,
    seed=None,
    name=None
)
rotated_batch = tf.contrib.image.rotate(image_batch, radian)

但是,如果我使用 allow_smaller_final_batch=True 构建批处理,则 batch_size 毫无用处,因为 image_batch 将没有固定的批处理大小。并且旋转会失败,因为弧度和image_batch的N维不一样。

如何修复它?

最佳答案

我没有批量旋转图像,而是对 image_queue.deque() 中的图像应用相同的旋转:

images = load_images(filenames, options)
radian = tf.random_uniform([len(images)], ...)
images =  tf.contrib.image.rotate(images, radian)

image_batch = tf.train.batch_join([images, filenames],
                                  enqueue_many=True, allow_smaller_final_batch=True,
                                  batch_size=WHATEVER)

关于python - tensorflow 中的批量图像增强,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52575674/

相关文章:

python - 与 sympy/pyqt python 的集成和区分

python - tensorflow 中的张量形状

python - PyTorch 中的数据增强

python - Keras:ImageDataGenerator 性能不佳

tensorflow - 可视化增强的火车图像 [tensorflow object detection api]

python - Pip 安装到较旧的 Python 版本

python - 如何将值合并到 discord.py 中的一条消息中

python - Pyplot,将2个数据集绘制成一张图,跳过部分y轴

python - 如何为binary_crossentropy、activation=sigmoid和activation=softmax指定model.compile?

python - 在 TensorFlow 模型中的每一行上使用 softmax 激活输出矩阵