简体   繁体   中英

cv2, keras, InternalError (see above for traceback): Blas GEMM launch failed

I get this Error:

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)]]

This is my code. I try to load a keras model. and predict the class of an image. But it always crashes when I want to predict the class of the image.

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)

If I write the same code and delete this part from the code:

#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)

then there is no Error. Here is the full code:

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)

Why is that so? Is the cv2 part using to much GPU? What is the difference?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM