【问题标题】:' builtin_function_or_method ' , How to overcome this Error'builtin_function_or_method',如何克服这个错误
【发布时间】:2021-01-18 09:44:25
【问题描述】:
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

【问题讨论】:

  • 请使用完整的错误回溯更新您的问题。
  • 从最外层的调用中可以看到,reshape is a function

标签: python opencv machine-learning facial-identification


【解决方案1】:

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

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

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

【讨论】:

  • 是的,但是现在您又遇到了一个错误...那是因为您尝试将大小为 2747 的数组重新整形为 (2747, 48, 48, 1)...
  • 我该如何解决呢,我自己学习这个,遇到了这个错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-02-10
  • 1970-01-01
  • 2021-05-31
  • 1970-01-01
  • 2019-09-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多