Zheweiqiu commented on issue #16042: Error when calling get_backend_symbol
URL: 
https://github.com/apache/incubator-mxnet/issues/16042#issuecomment-529804310
 
 
   > @Zheweiqiu Can you show the whole process / script that you did for 
building MXNet ?
   
   I am using retinaface mxnet model and the code is basically from 
[github](https://github.com/deepinsight/insightface/blob/master/RetinaFace/retinaface.py).
 I want to speed up the reference using tensorrt, so I modify it a little bit.
   The whole scrip is too long so I only attach modification I make. Below is 
original code from line 113 to 138.
   
   `    sym, arg_params, aux_params = mx.model.load_checkpoint(prefix, epoch)
       if self.ctx_id>=0:
         self.ctx = mx.gpu(self.ctx_id)
         self.nms = gpu_nms_wrapper(self.nms_threshold, self.ctx_id)
       else:
         self.ctx = mx.cpu()
         self.nms = cpu_nms_wrapper(self.nms_threshold)
       self.pixel_means = np.array(pixel_means, dtype=np.float32)
       self.pixel_stds = np.array(pixel_stds, dtype=np.float32)
       self.pixel_scale = float(pixel_scale)
       print('means', self.pixel_means)
       self.use_landmarks = False
       if len(sym)//len(self._feat_stride_fpn)==3:
         self.use_landmarks = True
       print('use_landmarks', self.use_landmarks)
   
       if self.debug:
         c = len(sym)//len(self._feat_stride_fpn)
         sym = sym[(c*0):]
         self._feat_stride_fpn = [32,16,8]
       print('sym size:', len(sym))
   
       image_size = (640, 640)
       self.model = mx.mod.Module(symbol=sym, context=self.ctx, label_names = 
None)
       self.model.bind(data_shapes=[('data', (1, 3, image_size[0], 
image_size[1]))], for_training=False)
       self.model.set_params(arg_params, aux_params)`
   
   I change it to 
   
   `        if use_trt:
               os.environ['MXNET_USE_TENSORRT'] = '1' 
           sym, arg_params, aux_params = mx.model.load_checkpoint(prefix, epoch)
           if self.ctx_id>=0:
               self.ctx = mx.gpu(self.ctx_id)
               self.nms = gpu_nms_wrapper(self.nms_threshold, self.ctx_id)
           else:
               self.ctx = mx.cpu()
               self.nms = cpu_nms_wrapper(self.nms_threshold)
           self.pixel_means = np.array(pixel_means, dtype=np.float32)
           self.pixel_stds = np.array(pixel_stds, dtype=np.float32)
           self.pixel_scale = float(pixel_scale)
           #print('means', self.pixel_means)
           self.use_landmarks = False
           if len(sym)//len(self._feat_stride_fpn)==3:
               self.use_landmarks = True
           #print('use_landmarks', self.use_landmarks)
   
           if self.debug:
               c = len(sym)//len(self._feat_stride_fpn)
               sym = sym[(c*0):]
               self._feat_stride_fpn = [32,16,8]
           #print('sym size:', len(sym))
   
           image_size = (640, 640)
           if not use_trt:
               self.model = mx.mod.Module(symbol=sym, context=self.ctx, 
label_names = None)
               self.model.bind(data_shapes=[('data', (1, 3, image_size[0], 
image_size[1]))], for_training=False)
               self.model.set_params(arg_params, aux_params)
           else:
               print('------------ Using tensorrt for face detection 
--------------')
               #''' 
               trt_sym = sym.get_backend_symbol('TensorRT')
               mx.contrib.tensorrt.init_tensorrt_params(trt_sym, arg_params, 
aux_params)
               mx.contrib.tensorrt.set_use_fp16(False)
               self.model = trt_sym.simple_bind(ctx=self.ctx, data = 
(1,3,image_size[0], image_size[1]), grad_req='null', force_rebind=True)
               self.model.copy_params_from(arg_params, aux_params)
               '''
               arg_params.update(aux_params)
               all_params = dict([(k, v.as_in_context(self.ctx)) for k,v in 
arg_params.items()])
               self.model = mx.contrib.tensorrt.tensorrt_bind(sym, 
ctx=self.ctx, all_params=all_params, data=batch_shape, grad_req='null', 
force_rebind=True)
               '''
   `
   When I set use_trt=True, I get the following error:
   
   [32, 16, 8] {'32': {'SCALES': (32, 16), 'BASE_SIZE': 16, 'RATIOS': (1.0,), 
'ALLOWED_BORDER': 9999}, '16': {'SCALES': (8, 4), 'BASE_SIZE': 16, 'RATIOS': 
(1.0,), 'ALLOWED_BORDER': 9999}, '8': {'SCALES': (2, 1), 'BASE_SIZE': 16, 
'RATIOS': (1.0,), 'ALLOWED_BORDER': 9999}}
   [07:01:19] src/nnvm/legacy_json_util.cc:209: Loading symbol saved by 
previous version v1.3.0. Attempting to upgrade...
   [07:01:19] src/nnvm/legacy_json_util.cc:217: Symbol successfully upgraded!
   ------------ Using tensorrt for face detection --------------
   Traceback (most recent call last):
     File "test_server_flask_celebrity.py", line 32, in <module>
       celebrity = cm_model.CelebModel(args)
     File "/home/qiuzhewei/celeb_test/src/test_celeb_model.py", line 71, in 
__init__
       detector = RetinaFace(args.detectmodel, 0, args.gpu, 'net3')
     File "/home/qiuzhewei/celeb_test/RetinaFace/retinaface.py", line 227, in 
__init__
       trt_sym = sym.get_backend_symbol('TensorRT')
     File "/opt/conda/lib/python3.7/site-packages/mxnet/symbol/symbol.py", line 
2564, in get_backend_symbol
       check_call(_LIB.MXGenBackendSubgraph(self.handle, c_str(backend), 
ctypes.byref(out)))
     File "/opt/conda/lib/python3.7/site-packages/mxnet/base.py", line 253, in 
check_call
       raise MXNetError(py_str(_LIB.MXGetLastError()))
   mxnet.base.MXNetError: [07:01:19] 
src/c_api/../operator/subgraph/subgraph_property.h:367: Check failed: it != 
prop_ptr_map_.end(): SubgraphProperty TensorRT is not found in 
SubgraphPropertyRegistry
   Stack trace:
     [bt] (0) 
/opt/conda/lib/python3.7/site-packages/mxnet/libmxnet.so(+0x4a357b) 
[0x7f9b1a05d57b]
     [bt] (1) 
/opt/conda/lib/python3.7/site-packages/mxnet/libmxnet.so(MXGenBackendSubgraph+0x1ab)
 [0x7f9b1c1d15db]
     [bt] (2) 
/opt/conda/lib/python3.7/lib-dynload/../../libffi.so.6(ffi_call_unix64+0x4c) 
[0x7f9b53e81ec0]
     [bt] (3) 
/opt/conda/lib/python3.7/lib-dynload/../../libffi.so.6(ffi_call+0x22d) 
[0x7f9b53e8187d]
     [bt] (4) 
/opt/conda/lib/python3.7/lib-dynload/_ctypes.cpython-37m-x86_64-linux-gnu.so(_ctypes_callproc+0x2ce)
 [0x7f9b54300f7e]
     [bt] (5) 
/opt/conda/lib/python3.7/lib-dynload/_ctypes.cpython-37m-x86_64-linux-gnu.so(+0x139b4)
 [0x7f9b543019b4]
     [bt] (6) python(_PyObject_FastCallKeywords+0x49b) [0x55b7bc065d2b]
     [bt] (7) python(_PyEval_EvalFrameDefault+0x537e) [0x55b7bc0c17ae]
     [bt] (8) python(_PyFunction_FastCallKeywords+0xfb) [0x55b7bc06479b]
   
   And I have no idea how to solve it. Any help will be appreciate!
   

----------------------------------------------------------------
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

Reply via email to