'why I got this ValueError: Shapes (None, 1) and (None, 5) are incompatible
I try to use the pre-trained ResNet model to bagging structure. when I reload the resnet model and use predict(x_test), the results' shape are 5. I don't know why. Can anyone help me? Many thanks!
x_train, y_train, x_test, y_test = train_images, train_labels_encoded, test_images, test_labels_encoded
x_train, x_test = x_train / 255.0, x_test / 255.0
len(x_test)
print(str(x_test.shape))
len(x_train)
print(str(x_train.shape))
print(str(y_test.shape))
print(str(y_train.shape))
from keras.models import load_model
resnet_model1 = load_model('/root/resnet_EB_Wall_mixclass/model/mix_model1.h5')
predict_result_1 = resnet_model1.predict(x_test,verbose=1)
print(predict_result_1)
print(predict_result_1.shape)
#print(predict_result_1)
score, acc = resnet_model1.evaluate(x_test, y_test, verbose=1)
print('Test score:', score) # loss function
print('Test accuracy:', acc) # accuracy
the above pic. is the result for data shape
above pic. is the result for predict_result_1 & predict_result_1.shape
ValueError: Shapes (None, 1) and (None, 5) are incompatible
Solution 1:[1]
Not an expert on how the library works but it would seem you have labels on y and probability of labels as output of predict (predict should return the labels afaik where did you get that model?) so you could convert the prob results to labels as a workaround:
y_pred = predict_result_1.argmax()
and then you could use:
precision_recall_fscore_support(y_test, y_pred)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tripparsugo |




