zhreshold / mxnet-ssd

MXNet port of SSD: Single Shot MultiBox Object Detector. Reimplementation of https://github.com/weiliu89/caffe/tree/ssd
MIT License
764 stars 337 forks source link

"simple_bind error" for mobilenet-ssd-512 model #208

Closed kobybibas closed 6 years ago

kobybibas commented 6 years ago

Hi,

I'm trying to use the trained mobilenet-ssd-512 model.

I've tried to load it as follow:

# User input- model
model_path = "./models/"
model_name = 'mobilenet-ssd-512'
input_size = 512

# Load the model
print('Start import model %s' % (model_path + model_name))
ctx = mx.cpu()
sym, arg_params, aux_params = mx.model.load_checkpoint(model_path+model_name, 0)
mod = mx.mod.Module(symbol=sym, context=ctx, label_names=None)
mod.bind(data_shapes=[('data', (1, 3, input_size, input_size))]) 
mod.set_params(arg_params, aux_params, allow_missing=True)
print('Finish import model %s' % (model_path + model_name))

However, got the following error:

Start import model ./models/mobilenet-ssd-512 [11:47:40] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v0.12.0. Attempting to upgrade... [11:47:40] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded! ... mxnet.base.MXNetError: Error in operator multibox_target: [11:47:40] src/operator/contrib/./multibox_target-inl.h:225: Check failed: lshape.ndim() == 3 (0 vs. 3) Label should be [batch-num_labels-(>=5)] tensor ... RuntimeError: simple_bind error. Arguments: data: (1, 3, 512, 512) Error in operator multibox_target: [11:47:40] src/operator/contrib/./multibox_target-inl.h:225: Check failed: lshape.ndim() == 3 (0 vs. 3) Label should be [batch-num_labels-(>=5)] tensor

Did i missed something?

zhreshold commented 6 years ago

You should use test symbol rather than the one used in training. You can import the symbol from the repo, or check out https://github.com/zhreshold/mxnet-ssd#convert-model-to-deploy-mode to convert your model to deploy mode.

kobybibas commented 6 years ago

Thanks @zhreshold it was very helpful. I needed to change the names of the following files:

  1. ssd_mobilenet_512-0001.params to ssd_mobilenet_300-0000.params
  2. ssd_mobilenet_512-symbol.json to ssd_mobilenet_300-symbol.json

And then running the following command: python demo.py --cpu --network mobilenet --data-shape 512