【2022年】解决tensorflow.python.framework.errors_impl.InternalError: Blas GEMM launch failed

报错截图:

在这里插入图片描述

原代码:

import cv2

from mtcnn import MTCNN

detector = MTCNN()

img = cv2.imread('./Lena3.jpg')

output = detector.detect_faces(img)

print(output)

在网上搜了半天,大部分是说GPU被占用,或者是向量维数不正确什么的。但是我的问题并不在这里。

解决方式:

加入Tensorflow显存设置。

import cv2
import tensorflow.compat.v1 as tf  
from mtcnn import MTCNN

config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.6
config.gpu_options.allow_growth=True
sess = tf.Session(config=config)

detector = MTCNN()

img = cv2.imread('./Lena3.jpg')

output = detector.detect_faces(img)

print(output)

结果:

加入显存设置后正常运行。

在这里插入图片描述
p.s.玩一玩MTCNN人脸检测

import cv2
import tensorflow.compat.v1 as tf
from mtcnn import MTCNN

config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.6
config.gpu_options.allow_growth=True
sess = tf.Session(config=config)

detector = MTCNN()
img = cv2.imread('./Lena3.jpg')
output = detector.detect_faces(img)
print(output)

x,y,width,height = output[0]['box']
left_eye_X,left_eye_Y = output[0]['keypoints']['left_eye']
right_eye_X,right_eye_Y = output[0]['keypoints']['right_eye']
nose_X,nose_Y = output[0]['keypoints']['nose']
mouth_left_X,mouth_left_Y = output[0]['keypoints']['mouth_left']
mouth_right_X,mouth_right_Y = output[0]['keypoints']['mouth_right']

# opencv的三色顺序为BGR (Blue,Green,Red)
cv2.rectangle(img,pt1=(x,y),pt2=(x+width,y+height),color=(0,255,0),thickness=2)
cv2.circle(img,center=(left_eye_X,left_eye_Y),color=(0,0,255),thickness=2,radius=1)
cv2.circle(img,center=(right_eye_X,right_eye_Y),color=(0,0,255),thickness=2,radius=1)
cv2.circle(img,center=(nose_X,nose_Y),color=(255,0,0),thickness=2,radius=1)
cv2.circle(img,center=(mouth_left_X,mouth_left_Y),color=(255,0,0),thickness=2,radius=1)
cv2.circle(img,center=(mouth_right_X,mouth_right_Y),color=(255,0,0),thickness=2,radius=1)
cv2.imshow('result',img)
# cv2.imwrite('./result.png',img)
cv2.waitKey(0)

在这里插入图片描述

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值