出现此问题是由于新版的Tensorflow将predict_classes删除了,新版只有predict
但两者返回值不同
prediction=model.predict_classes(x_Test)
prediction
原本目标得到结果应该为:
array([7, 2, 1, ..., 4, 5, 6], dtype=int64)
prediction=model.predict(x_Test)
prediction
得到结果:
array([[0., 0., 0., ..., 1., 0., 0.], [0., 0., 1., ..., 0., 0., 0.], [0., 1., 0., ..., 0., 0., 0.], ..., [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.]], dtype=float32)
此时,如下解决:
将prediction=model.predict_classes(x_Test)中等号右侧改为np.argmax(model.predict(x_Test),axis=1)
即
prediction=np.argmax(model.predict(x_Test),axis=1)
就可得出相同结果。