Keras 加载的模型不工作

Keras loaded model is Not working

我用 Keras 训练了一个模型,使用 model.save() 保存了它,从 Keras Documentation 开始,我不需要保存任何其他东西或在加载后编译模型。

当我加载它以在不同的图像上对其进行测试时,出现此错误:

totalMemory: 5.93GiB freeMemory: 5.41GiB 2018-05-17 10:10:53.265572: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 1060 with Max-Q Design, pci bus id: 0000:01:00.0, compute capability: 6.1)

2018-05-17 10:10:55.939415: E tensorflow/stream_executor/cuda/cuda_dnn.cc:385] could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR

2018-05-17 10:10:55.939452: E tensorflow/stream_executor/cuda/cuda_dnn.cc:352] could not destroy cudnn handle: CUDNN_STATUS_BAD_PARAM

2018-05-17 10:10:55.939459: F tensorflow/core/kernels/conv_ops.cc:667] Check failed: stream->parent()->GetConvolveAlgorithms( conv_parameters.ShouldIncludeWinogradNonfusedAlgo(), &algorithms)

Aborted (core dumped)

这是我使用的代码:

num_classes = 17
model = load_model('model.h5')


img1 = cv2.resize(cv2.cvtColor(cv2.imread("s_0.jpg"), cv2.COLOR_BGR2RGB), (24,24))
img2 = cv2.resize(cv2.cvtColor(cv2.imread("s_f.jpg"), cv2.COLOR_BGR2RGB), (24,24))
img3 = cv2.resize(cv2.cvtColor(cv2.imread("s_2.jpg"), cv2.COLOR_BGR2RGB), (24,24))

X_test = np.array([img1,img2,img3])
Y_test = to_categorical(np.array([0,12,2]), num_classes)

Y_predict = model.predict(X_test)
print np.argmax(Y_predict,axis = 1)

当我在训练后使用准确的代码进行测试时(模型可用但未加载),它工作正常。

看来你的 CUDA 坏了。通过禁用 GPU export CUDA_VISIBLE_DEVICES=-1.

对其进行测试