TypeError: 'tuple' object cannot be interpreted as an integer I have an image (480,640,3) and I am trying to resize it to (150,150,1). Since my Keras model has been trained on images of shape (150,150,1), unfortunately I cannot seem to resize it using the PIL library. Any suggestions on how to fix this?

This is the code I am using right now:

The error is caused on the line image5.resize()

    stream.seek(0)
    data = numpy.fromstring(stream.getvalue() , dtype = numpy.uint8)
    image5 = cv.imdecode(data , 1)
    print(image5.shape)
    #cv.imwrite('uhhu.png',image5)
    img = image5.resize((150,150,1 ), Image.ANTIALIAS)
    cv.imwrite('hhh.png',img)
    x = img_to_array(img)
    x = x.reshape((1,) + x.shape)
    x = x/255
    x = numpy.array(x)
    print(x.shape)
    #score = loaded_model.predict(img)
    #print(score)
The solution to the problem is to resize using openCV instead of using PIL and specifying the appropriate pixel width and height.

img = cv.resize(image5 , (150,150))