cv2,keras,InternalError(参见上面的回溯):Blas GEMM启动失败

时间:2017-11-01 03:19:48

标签: python keras cv2

我收到此错误:

InternalError (see above for traceback): Blas GEMM launch failed : a.shape=(1, 2304), b.shape=(2304, 512), m=1, n=512, k=2304
     [[Node: dense_1/MatMul = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false, _device="/job:localhost/replica:0/task:0/gpu:0"](flatten_1/Reshape, dense_1/kernel/read)]]

这是我的代码。我尝试加载keras模型。并预测图像的类别。但是当我想要预测图像的类时,它总会崩溃。

from __future__ import print_function
import keras
from keras.datasets import cifar10
from keras.models import load_model
import cv2
import numpy as np
from keras.preprocessing import image
import time
import os

num_classes = 10
save_dir = os.path.join(os.getcwd(), 'examples/saved_models')
model_name = 'keras_cifar10_trained_model.h5'
model = load_model(save_dir + '/' + model_name)

# The data, shuffled and split between train and test sets:
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
print('x_train shape:', x_train.shape)
print(x_train.shape[0], 'train samples')
print(x_test.shape[0], 'test samples')

# Convert class vectors to binary class matrices.
y_train = keras.utils.to_categorical(y_train, num_classes)
y_test = keras.utils.to_categorical(y_test, num_classes)

x_train_float = x_train.astype('float32')
x_test_float = x_test.astype('float32')
x_train_bin = x_train_float / 255
x_test_bin = x_test_float / 255

nr_pic = 0

# predicting images
img = image.load_img('apfel.jpg', target_size=(32, 32))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = x / 255

#while True:
image = x_test[nr_pic]
image = cv2.resize(image,(320, 320), interpolation = cv2.INTER_CUBIC)
image_bin = np.expand_dims(x_test_bin[nr_pic], axis=0)

classes = model.predict_classes(x, batch_size=10)
print(classes)

如果我编写相同的代码并从代码中删除此部分:

#while True:
image = x_test[nr_pic]
image = cv2.resize(image,(320, 320), interpolation = cv2.INTER_CUBIC)
image_bin = np.expand_dims(x_test_bin[nr_pic], axis=0)

然后没有错误。这是完整的代码:

from __future__ import print_function
import keras
from keras.datasets import cifar10
from keras.models import load_model
import cv2
import numpy as np
from keras.preprocessing import image
import time
import os

num_classes = 10
save_dir = os.path.join(os.getcwd(), 'examples/saved_models')
model_name = 'keras_cifar10_trained_model.h5'
model = load_model(save_dir + '/' + model_name)

# The data, shuffled and split between train and test sets:
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
print('x_train shape:', x_train.shape)
print(x_train.shape[0], 'train samples')
print(x_test.shape[0], 'test samples')

# Convert class vectors to binary class matrices.
y_train = keras.utils.to_categorical(y_train, num_classes)
y_test = keras.utils.to_categorical(y_test, num_classes)

x_train_float = x_train.astype('float32')
x_test_float = x_test.astype('float32')
x_train_bin = x_train_float / 255
x_test_bin = x_test_float / 255

nr_pic = 0

# predicting images
img = image.load_img('apfel.jpg', target_size=(32, 32))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = x / 255

classes = model.predict_classes(x, batch_size=10)
print(classes)

为什么会这样? cv2部分是否使用了很多GPU? 有什么区别?

1 个答案:

答案 0 :(得分:0)

从32x32(CIFAR10图像)到320x320图像,您的数据集大小增加100.我认为在那里发生的是在第一个示例中,模型中传递的数据太大(比没有插值的第二个示例大100倍)