简体   繁体   English

IndexError:索引 26 超出轴 0 的范围,大小为 26

[英]IndexError: index 26 is out of bounds for axis 0 with size 26

I can't show the 'Z' because of index error.由于索引错误,我无法显示“Z”。 before i have to make an cnn architecture with vgg-19, dense 26. because the classes on google drive is 26 classes (AZ)在我必须用 vgg-19 制作 cnn 架构之前,密集 26。因为谷歌驱动器上的类是 26 类(AZ)

#A= io.imread('/content/drive/MyDrive/Colab Notebooks/Proyek Akhir/datasetBISINDO/BISINDO Sign Language/X/IMG_1047.JPG') #X
#A= io.imread('/content/drive/MyDrive/Colab Notebooks/Proyek Akhir/datasetBISINDO/BISINDO Sign Language/Y/IMG_1057.JPG') #Y
A= io.imread('/content/drive/MyDrive/Colab Notebooks/Proyek Akhir/datasetBISINDO/BISINDO Sign Language/Z/IMG_1067.JPG') #Z

B= cv2.resize(A, (64, 64))
print(B.shape)
print(A.shape)

#plt.subplot(1, 2, 1),plt.imshow(A), plt.title("Original"), plt.axis('off')
#plt.subplot(1, 2, 2),plt.imshow(B), plt.title("Reshape"), plt.axis('off')
#===================================================
#img = image.load_img(A,target_size=(224,224))

img=B
img = np.asarray(img)
plt.imshow(img),plt.title("Predikted Result"), plt.axis('off')
img = np.expand_dims(img, axis=0)
from keras.models import load_model
saved_model = load_model(r"/content/drive/MyDrive/Colab Notebooks/VGG19PAbagas.h5")
output = saved_model.predict(img)
if output[0][0] > output[0][1]:
  print("A")

cont,续,

  print('X')
elif output[0][24] > output[0][25]:
  print('Y')
elif output[0][25] > output[0][26]:
  print('Z')
else:
  print('Tidak Terdefinisi')

the traceback,追溯,

IndexError                                Traceback (most recent call last)
<ipython-input-13-33700d0a695d> in <module>()
    106 elif output[0][24] > output[0][25]:
    107   print('Y')
--> 108 elif output[0][25] > output[0][26]:
    109   print('Z')
    110 else:

this is, how i made the vgg file这就是我如何制作 vgg 文件的

model = vgg.output
model = tf.keras.layers.GlobalMaxPooling2D()(model)
model = tf.keras.layers.Flatten()(model)
model = tf.keras.layers.Dense(512,activation='relu')(model)
model = tf.keras.layers.Dropout(rate=0.25)(model)
model = tf.keras.layers.Dense(26,activation='softmax')(model)#Ganti angka sesuai jumlah kelas
model = tf.keras.models.Model(inputs=vgg.input, outputs = model)

and, total classes in my drive is 26. (AZ), how can i made it to count until 27th?而且,我的驱动器中的总课程是 26。(AZ),我怎样才能算到 27 日? because i need to show the 'Z' element因为我需要显示“Z”元素

If you are trying to use index 26 and it is giving you the error, it is because the indexing starts at 0 and the program basically is trying to give you the 27th element, which is'nt present.如果您尝试使用索引 26 并且它给了您错误,那是因为索引从 0 开始并且程序基本上试图给您第 27 个元素,它不存在。 So, try returning the 25th index, it would give you the 26th character.所以,尝试返回第 25 个索引,它会给你第 26 个字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM