Rainweic opened a new issue #17826: [quetions] Check failed: e == cudaSuccess: CUDA: initialization error URL: https://github.com/apache/incubator-mxnet/issues/17826 ubuntu16.04 python3.5 Project requirements are multiple processes ``` import numpy as np import cv2 as cv from gluoncv.model_zoo import get_model from multiprocessing import Process import multiprocessing as mp from gluoncv.data.transforms.presets import yolo class Walker(): from mxnet import nd from mxnet import cpu, gpu def __init__(self, weight_path=None, use_gpu=False): """ :param weight_path: 权重路径 :param use_gpu: 是否使用GPU """ if use_gpu: self.context = gpu() else: self.context = cpu() self.weight_path = weight_path self.net = None def pre_img(self, image): """ 预处理图片 :param image: numpy.ndarray 图片 :return: """ x = nd.array(image) x, img = yolo.transform_test(x, short=416) height_times, width_times = self.transform_coordinates(image, img) x = x.as_in_context(self.context) return x, height_times, width_times def load_model(self): """ 初始化模型(给self.net赋值) """ print("[INFO] Loading {}...".format(self.__class__.__name__)) self.net = get_model('yolo3_darknet53_coco', pretrained=True) self.net.reset_class(["person"], reuse_weights=['person']) if not self.weight_path is None: self.load_parameters(self.weight_path) self.net.collect_params().reset_ctx(self.context) self.net.hybridize() def predict(self, image_info): image = image_info['image'] x, height_times, width_times = self.pre_img(image) _, scores, bboxes = self.net(x) scores = scores.asnumpy()[0] bboxes = bboxes.asnumpy()[0] bboxes = self.fitter_bboxes(scores, bboxes, thresh=0.5) if len(bboxes) == 0: return image_info # 将bbox坐标缩放到原始大小 bboxes[:, 0::2] *= width_times bboxes[:, 1::2] *= height_times image_info['walker_bbox'] = bboxes.astype(int).tolist() return image_info def fitter_bboxes(self, scores, bboxes, thresh=0.9): # 提取出置信度大于thresh的bbox scores = scores > thresh index = list(zip(np.where(scores > 0)))[0][0] # 不超过置信度则退出 if len(index) == 0: return [] bboxes = np.take(bboxes, index, axis=0) return bboxes def transform_coordinates(self, ori_img, pre_img): ''' 计算原图和预处理后的图片缩放比例 args: ori_img(numpy): 原图 pre_img(numpy): 预处理后的图片 ''' ori_height, ori_width, _ = ori_img.shape pre_height, pre_width, _ = pre_img.shape height_times = ori_height / pre_height width_times = ori_width / pre_width return height_times, width_times def predict(net, image_info): print(net.predict(image_info)) if __name__ == "__main__": walker = Walker(use_gpu=True) # 加载数据 image_info = {"image": cv.imread("test.jpg")} # 加载模型 walker.load_model() for _ in range(10): p = Process(target=predict, args=(walker, image_info,)) p.start() p.join() ``` error : ``` terminate called after throwing an instance of 'dmlc::Error' what(): [17:57:11] /home/travis/build/dmlc/mxnet-distro/mxnet-build/3rdparty/mshadow/mshadow/./tensor_gpu-inl.h:35: Check failed: e == cudaSuccess: CUDA: initialization error Stack trace: [bt] (0) /home/bhyhrgzn/.local/lib/python3.5/site-packages/mxnet/libmxnet.so(+0x4b03ab) [0x7fbea0ac53ab] [bt] (1) /home/bhyhrgzn/.local/lib/python3.5/site-packages/mxnet/libmxnet.so(+0x25befc2) [0x7fbea2bd3fc2] [bt] (2) /home/bhyhrgzn/.local/lib/python3.5/site-packages/mxnet/libmxnet.so(+0x25c79e5) [0x7fbea2bdc9e5] [bt] (3) /home/bhyhrgzn/.local/lib/python3.5/site-packages/mxnet/libmxnet.so(+0x25c7d46) [0x7fbea2bdcd46] [bt] (4) /home/bhyhrgzn/.local/lib/python3.5/site-packages/mxnet/libmxnet.so(+0x25bfd64) [0x7fbea2bd4d64] [bt] (5) /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0xb8c80) [0x7fbed4b63c80] [bt] (6) /lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba) [0x7fbf125ad6ba] [bt] (7) /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7fbf122e341d] ```
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
