我正在使用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.6 Keras 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)