TypeError:“元组”对象不能解释为整数

数据挖掘 深度学习 喀拉斯 张量流 opencv
2022-01-24 21:31:01

我有一张图片 (480,640,3),我正在尝试将其调整为 (150,150,1)。由于我的 Keras 模型已经接受了形状图像 (150,150,1) 的训练,不幸的是我似乎无法使用 PIL 库调整它的大小。对于如何解决这个问题,有任何的建议吗?

这是我现在使用的代码:

错误是在线引起的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)
1个回答

该问题的解决方案是使用openCV而不是使用PIL来调整大小并指定适当的像素宽度和高度。

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