ValueError: shared_buffer in simple_bind must be dict or None

Hi All,

I am new to MxNet, Just trained my yolo3 network and doing forward pass similar to below demo code

https://gluon-cv.mxnet.io/build/examples_detection/demo_yolo.html

======================================================
self.net = model_zoo.get_model(model_name, pretrained=False, classes=(“cat”, “dog”))
self.net.load_parameters(params)
self.net.collect_params().reset_ctx(ctx)

cls_ids, scores, bboxs = self.net(img_tensors)

=============================

Now I want to move it to TensorRt by going through

Now I am clueless on how to get below code working to get TensortRT executor to bind to my model

=============================================================================
executor = mx.contrib.tensorrt.tensorrt_bind(sym, ctx=mx.gpu(0), all_params=all_params,
data=batch_shape, grad_req=‘null’, force_rebind=True)


y_gen = executor.forward(is_train=False, data=input)

====================================================================

Missing parts in how to get the “sym”( The symbol configuration of computation network.) and all_params etc arguments to create the executor

One change I tried to do is as below

    self.executor = mx.contrib.tensorrt.tensorrt_bind(self.net, ctx=mx.gpu(0), all_params=params,
                                         data=(1,3,416,416), grad_req='null', force_rebind=True)

============================================

But got error
AttributeError: ‘YOLOV3’ object has no attribute ‘simple_bind’

Thanks for help !!!

Regards
Pallab Sarkar

tensorrt_bind is expecting a Symbol, but you give it a HybridBlock. If you want to use Gluon Model Zoo, then you have to convert the HybridBlock into a Symbol. E.g.:

self.net.export('model')
sym = mx.sym.load('model.json')

self.executor = mx.contrib.tensorrt.tensorrt_bind(sym, ctx=mx.gpu(0), all_params=params,
                                         data=(1,3,416,416), grad_req='null', force_rebind=True)

Apart from that: you also need to set the environment variable MXNET_USE_TENSORRT=1

1 Like

Thanks NRauschmayr,

I am successfully able to convert HybridBlock into a Symbol. by below code
self.net.export(self.model_name)
sym = mx.sym.load(self.model_name+"-symbol.json")
self.executor = mx.contrib.tensorrt.tensorrt_bind(sym, ctx=mx.gpu(0), all_params=self.params,data=(1,3,416,416), grad_req=‘null’, force_rebind=True)

But now getting one more new error as below
ValueError: shared_buffer in simple_bind must be dict or None

If anybody can guide me further on resolving the issue , It will really helpful.

Regards
Pallab Sarkar

Can you check if self.params is a dictionary containing your model parameters?

Hi ,
Thanks for your inputs,
In my case self.param is a string , which is path to my model.param file ,
I think I need to somehow extract param dictionary from this .param file and pass it to bind API call.
Please let me know your view on this !!

Regards

Ok that explains the error: self.param needs to be a dictionary of model parameters. You could use model.load_parameters('model.param') to load the parameters into your model and then model.get_parameters() to retrieve the dictionaries for arg_params and aux_params.
tensorrt_bind expects a merged dictionary, so can do the following:
all_params = dict([(k, v.as_in_context(mx.gpu(0))) for k, v in arg_params.items()])