How to convert images color space in Keras?

前端 未结 2 572

I am feeding RGB color images to a Neural Network implemented with Keras. How can I have Keras convert the images to a different color space (e.g. YUV, Lab, or some grayscal

相关标签:
2条回答
  • 2020-12-20 21:36

    I was looking to use opencv in an preprocessing layer using Keras lambda layers to ensure that all the preprocessing done on my images are the same whether training, testing or predicting. However I found that you must use tensor operations on tensors. So you're limited to simple arithmetic operations in your lambda and whatever tensor-operations you can find in keras.backend.

    0 讨论(0)
  • 2020-12-20 21:44

    If you import tensorflow, you can use the tf.image.rgb_to_hsv() function in the lambda:

    def hsv_conversion(x):
        import tensorflow as tf    
        return tf.image.rgb_to_hsv(x)
    
    model.add(Lambda(hsv_conversion, input_shape=(160, 320, 3)))
    
    0 讨论(0)
提交回复
热议问题