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模型.并预测图像的类别.但是当我要预测图像的类别时,它总是崩溃.
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)
为什么会这样? cv2部分使用了很多GPU吗? 有什么区别?
Why is that so? Is the cv2 part using to much GPU? What is the difference?
推荐答案
从32x32(CIFAR10图片)到320x320图片,您的数据集大小增加了100.模型太大(比没有插值的第二个示例大100倍).
From 32x32 (CIFAR10 images) to 320x320 images you grow your dataset size by 100. What's happening there I think is that in the first example the data passed in your model are too big (100x bigger than the 2nd example without interpolation).
这篇关于cv2,keras,InternalError(请参阅上面的回溯):Blas GEMM启动失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!