You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/03/13 09:59:03 UTC

[GitHub] [incubator-mxnet] Rainweic opened a new issue #17826: [quetions] Check failed: e == cudaSuccess: CUDA: initialization error

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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] rondogency commented on issue #17826: [quetions] Check failed: e == cudaSuccess: CUDA: initialization error

Posted by GitBox <gi...@apache.org>.
rondogency commented on issue #17826: [quetions] Check failed: e == cudaSuccess: CUDA: initialization error
URL: https://github.com/apache/incubator-mxnet/issues/17826#issuecomment-598839521
 
 
   @Rainweic as far as I know, you cannot have a global model shared by multiple processes, each worker process needs to have its own copy of the model on gpu. It's because cuda doesn't support other processes sharing one chunk of memory in the main process where the model is loaded

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] rondogency commented on issue #17826: [quetions] Check failed: e == cudaSuccess: CUDA: initialization error

Posted by GitBox <gi...@apache.org>.
rondogency commented on issue #17826: [quetions] Check failed: e == cudaSuccess: CUDA: initialization error
URL: https://github.com/apache/incubator-mxnet/issues/17826#issuecomment-599008773
 
 
   forgot to mention, each process has to import mxnet individually. 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] r2d3 commented on issue #17826: [quetions] Check failed: e == cudaSuccess: CUDA: initialization error

Posted by GitBox <gi...@apache.org>.
r2d3 commented on issue #17826: [quetions] Check failed: e == cudaSuccess: CUDA: initialization error
URL: https://github.com/apache/incubator-mxnet/issues/17826#issuecomment-609056307
 
 
   HI @rondogency and @Rainweic,
   
   even with an "import mxnet" in each process, I got similar issue.
   
   For example: https://github.com/aws-samples/parallelize-ml-inference
   is creating `global model` in `init_worker`.
   It does not do `import mxnet` in each process. I modified the code to do the import in `init_worker` but still gets the CUDA error
   
   `  File "/home/ubuntu/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/symbol/symbol.py", line 1776, in simple_bind
       ctypes.byref(exe_handle)))
     File "/home/ubuntu/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/base.py", line 255, in check_call
       raise MXNetError(py_str(_LIB.MXGetLastError()))
   mxnet.base.MXNetError: [16:40:00] src/engine/./../common/cuda_utils.h:379: Check failed: e == cudaSuccess || e == cudaErrorCudartUnloading: CUDA: initialization error`
   
   https://github.com/aws-samples/parallelize-ml-inference/issues/3
   
   Regards
   
   David

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] Sunhil commented on issue #17826: [quetions] Check failed: e == cudaSuccess: CUDA: initialization error

Posted by GitBox <gi...@apache.org>.
Sunhil commented on issue #17826:
URL: https://github.com/apache/incubator-mxnet/issues/17826#issuecomment-655232370


   Have you solved the problem? If you have soled the problem, Clould you show the solution? I have the same question, Thanks a lot!


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-mxnet] r2d3 commented on issue #17826: [quetions] Check failed: e == cudaSuccess: CUDA: initialization error

Posted by GitBox <gi...@apache.org>.
r2d3 commented on issue #17826:
URL: https://github.com/apache/incubator-mxnet/issues/17826#issuecomment-657470785


   Hello @Sunhil 
   
   The solution is to do "import mxnet" ONLY in the forked process. I have made a PullRequest to show how to solve this problem
   
   https://github.com/aws-samples/parallelize-ml-inference/pull/4
   
   Regards
   
   David


----------------------------------------------------------------
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:
users@infra.apache.org