1
Expressions={0:"Angry",1:"Disgust",2:"Fear",3:"Happy",4:"Sad",5:"Surprise",6:"Neutral"}
from keras.utils import to_categorical 
labels = to_categorical(labels,len(Expressions))
images = np.array([np.fromstring(pixel, dtype=int,sep=" ")for pixel in pixels])
images = images/255.00
images = images.reshape(images.reshape[0],48,48,1).astype('float32')

我在将灰度图像转换为 48x48 时遇到了这个错误,所以任何人都可以给我一个很好的回应。

在代码中出现此错误;

  1 images = np.array([np.fromstring(pixel, dtype=int, sep=" ")for pixel in pixels])
  2 images = images/255.00
----> 3 images = images.reshape(images.reshape[0],48,48,1).astype('float32')

TypeError: 'builtin_function_or_method' object is not subscriptable

在此处输入图像描述

4

1 回答 1

1

reshape是一个函数。您必须将其更改为:

images = images.reshape(images.shape[0],48,48,1).astype('float32')

第一个 arg 是images.shape[0]而不是images.reshape[0]

于 2021-01-18T09:56:08.577 回答