oarriaga/face_classification

ValueError: color_mode must be "grayscale", "rbg", or "rgba"

omkarhp opened this issue ยท 2 comments

While running image_emotion_gender_demo.py i'm getting error statement as ValueError: color_mode must be "grayscale", "rbg", or "rgba"

Like this:

C:\Users\o.hemant.pawaskar\Downloads\EMOTION_RECOGNITION_ALL_DATA\face_classification-master\src>python C:\Users\o.hemant.pawaskar\Downloads\EMOTION_RECOGNITION_ALL_DATA\face_classification-master\src\image_emotion_gender_demo.py C:\Users\o.hemant.pawaskar\Desktop\happy.jpg
Using TensorFlow backend.
2018-10-22 14:48:39.056701: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Traceback (most recent call last):
File "C:\Users\o.hemant.pawaskar\Downloads\EMOTION_RECOGNITION_ALL_DATA\face_classification-master\src\image_emotion_gender_demo.py", line 42, in
rgb_image = load_image(image_path, grayscale=False)
File "C:\Users\o.hemant.pawaskar\Downloads\EMOTION_RECOGNITION_ALL_DATA\face_classification-master\src\utils\inference.py", line 7, in load_image
pil_image = image.load_img(image_path, grayscale, target_size)
File "C:\Users\o.hemant.pawaskar\AppData\Local\Continuum\anaconda3\envs\py36\lib\site-packages\keras_preprocessing\image.py", line 509, in load_img
raise ValueError('color_mode must be "grayscale", "rbg", or "rgba"')
ValueError: color_mode must be "grayscale", "rbg", or "rgba"

Can somebody please help??
Thank you

hi @omkarhp

please add color_mode="rgb" in load_image() in inference.py file located in utils folder

def load_image(image_path, grayscale=False, color_mode='rgb', target_size=None):
pil_image = image.load_img(image_path, grayscale, color_mode, target_size, )
return image.img_to_array(pil_image)

change to these lines in inference.py to work with the latest keras:

def load_image(image_path, grayscale=False, target_size=None):
    color_mode = 'grayscale'
    if grayscale == False:
        color_mode = 'rgb'
    else:
        grayscale = False
    pil_image = image.load_img(image_path, grayscale, color_mode, target_size)
    return image.img_to_array(pil_image)