Search code examples
pythonkerasface-recognitiondata-augmentation

not able to pass Keras Generator image to face recognition


I am using Keras to generate pictures to feed face_recognition package.

the following code I used to read and prepare the picture to be passed to the generator

image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

image = np.expand_dims(image, axis=0)
imageGen = aug.flow(image, batch_size=1)

then for the generated image is used as follow:

for gimage in imageGen:
   face_recognition.face_locations(gimage, 'cnn')

RuntimeError: Unsupported image type, must be 8bit gray or RGB image.

I tried to solve the issue by using squeeze before passing the generated picture; but also it did not work

gimage = np.squeeze(gimage, axis=0)

Solution

  • You should check gimage ndarray's value dtype. It should be uint8 and as per the error it looks like currently it is float32