gpt4 book ai didi

python-3.x - 索引错误 :Index 10 is out of bounds for axis 1 with size 10

转载 作者:行者123 更新时间:2023-12-05 07:33:16 24 4
gpt4 key购买 nike

我正在使用 CNN 将图像分为 30 个不同的类别,并且在运行 CNN 时,我得到以下回溯-

Traceback (most recent call last):
File "thapar.py", line 165, in <module>
Y = np_utils.to_categorical(labels, num_classes)
File "/home/rishav/anaconda3/envs/tensorflow/lib/python3.6/site-packages/keras/utils/np_utils.py", line 31, in to_categorical
categorical[np.arange(n), y] = 1
IndexError: index 10 is out of bounds for axis 1 with size 10

python 3.6Keras 2.1.5 使用 tensorflow 后端Ubuntu 16.04

我已经探索了其他类似的问题,但无法找到问题的相似之处。

如何解决这个问题?

编辑:

num_classes = 30
num_of_samples = img_data.shape[0]
labels = np.ones((num_of_samples,),dtype='int64')
labels[0:20]=0
labels[20:40]=1
labels[40:60]=2
labels[60:80]=3
labels[80:100]=4
labels[100:120]=5
labels[120:140]=6
labels[140:160]=7
labels[160:180]=8
labels[180:200]=9
labels[200:220]=10
labels[220:240]=11
labels[240:260]=12
labels[260:280]=13
labels[280:300]=14
labels[300:320]=15
labels[320:340]=16
labels[340:360]=17
labels[360:380]=18
labels[380:400]=19
labels[400:420]=20
labels[420:440]=21
labels[440:460]=22
labels[460:480]=23
labels[480:500]=24
labels[500:520]=25
labels[520:540]=26
labels[540:560]=27
labels[560:580]=28
labels[580:600]=29

names =

['bent','bowl','claw','fist','good','thumbs_up','A','B','C','D','E' ,'F','G','H','I','K','L','M','N','O','P','Q','R',' S','T','U','V','W','X','Y']

Y = np_utils.to_categorical(labels, num_classes)

最佳答案

最近,我遇到了同样的问题,然后我才知道它只在某些图像上出错,我删除了这些图像,然后它对我来说效果很好。

关于python-3.x - 索引错误 :Index 10 is out of bounds for axis 1 with size 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50694731/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com