繁体   English   中英

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

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

我收到此错误:

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吗? 有什么区别?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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