roy*_*yco 5 python machine-learning neural-network deep-learning keras
我想用Keras的ImageDataGenerator扩展我的数据集,以与model.fit_generator()一起使用。我看到我可以随机翻转图像。对于翻转的图像,我需要修改相应的标签。我怎样才能做到这一点?
编辑:我正在做回归,而不是分类,所以如果图像被翻转,我需要调整标签。实际图像来自自动驾驶汽车模拟器,标签为转向角。如果我水平翻转图像,则需要取消转向角。
你可能会这样做:
import numpy
def fliping_gen(image_generator, flip_p=0.5):
for x, y in image_generator:
flip_selector = numpy.random.binomial(1, flip_p, size=x.shape[0]) == 1
x[flip_selector,:,:,:] = x[flip_selector,:,::-1,:]
y[flip_selector] = (-1) * y[flip_selector]
yield x, y
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
767 次 |
| 最近记录: |