for dataset in data_dir_list:
img_list=os.listdir(data_path+'/'+ dataset)
print ('Loaded the images of dataset-'+'{}\n'.format(dataset))
for img in img_list:
input_img=cv2.imread(data_path + '/'+ dataset + '/'+ img )
#input_img=cv2.cvtColor(input_img, cv2.COLOR_BGR2GRAY)
input_img_resize=cv2.resize(input_img,(48,48))
img_data_list.append(input_img_resize)
img_data = np.array(img_data_list)
#img_data = img_data.astype('float32')
img_data = img_data.astype('int32')
####################################################
#img_data = np.array(img_data_list)[img_data.astype('int32')]
################################################
img_data = img_data/255
img_data.shape
..
...
num_classes = 7
num_of_samples = img_data.shape[0]
labels = np.ones((num_of_samples,),dtype='int64')
labels[0:134]=0 #135
labels[135:188]=1 #54
labels[189:365]=2 #177
labels[366:440]=3 #75
labels[441:647]=4 #207
labels[648:731]=5 #84
labels[732:980]=6 #249
names = ['anger','contempt','disgust','fear','happy','sadness','surprise']
def getLabel(id):
return ['anger','contempt','disgust','fear','happy','sadness','surprise'][id]
..
..
..
score = model.evaluate(X_test, y_test, verbose=0)
print('Test Loss:', score[0])
print('Test accuracy:', score[1])
test_image = X_test[0:1]
print (test_image.shape)
####################################################
print(model.predict(test_image))
#################_____print(model.predict_classes(test_image))
print(np.argmax(model.predict(x_test), axis=1))
print(y_test[0:1])
#######################################################
res = model.predict(X_test[9:18])
plt.figure(figsize=(10, 10))
for i in range(0, 9):
plt.subplot(330 + 1 + i)
plt.imshow(x_test[i],cmap=plt.get_cmap('gray'))
plt.gca().get_xaxis().set_ticks([])
plt.gca().get_yaxis().set_ticks([])
plt.ylabel('prediction = %s' % getLabel(res[i]), fontsize=14)
# show the plot
plt.show()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/tmp/ipykernel_23/853380379.py in <module>
21 plt.gca().get_xaxis().set_ticks([])
22 plt.gca().get_yaxis().set_ticks([])
---> 23 plt.ylabel('prediction = %s' % getLabel(res[i]), fontsize=14)
24 # show the plot
25 plt.show()
/tmp/ipykernel_23/431880561.py in getLabel(id)
15
16 def getLabel(id):
---> 17 return ['anger','contempt','disgust','fear','happy','sadness','surprise'][id]
TypeError: only integer scalar arrays can be converted to a scalar index
What I have tried:
I want it to output[[1. 0. 0. 0. 0. 0. 0.]]
I try to show and save the resulting prediction images after training by CNN
but
but keep getting this error:
TypeError: only integer scalar arrays can be converted to a scalar index