How to use Module API for prediction?
all examples of Module API show usage over training and validation data iterators, which also happen to have a label. For genuine prediction, data doesn’t come with label - finding the label is actually the reason we do a model in the first place : )
How to run a prediction on a new sample?
example:
SSD detection model instantiated with:
mod = mx.module.Module.load('model_algo_1', 0, False, label_names=['label'])
mod.bind(data_shapes=[( 'data', (1, 3, 500, 500))],
label_shapes=[('label', (1, 1, 350))],
for_training=False) # no idea if this is correct. I guessed that part based on pieces of documentation here and there
How to run a prediction? mod.predict(...)
?
predict seem to expect a DataIter. So should I do a DataIter without labels?
Here is some example code: https://github.com/zhreshold/mxnet-ssd/blob/master/evaluate/evaluate_net.py
You have to define a metric and then you can call mod.score(). This function is expecting a DataIter. You can use this function to create an iterator from a rec-file:
DetRecordIter(path_imgrec, batch_size, data_shape, path_imglist=path_imglist, **cfg.valid)
The full code looks like this:
sym, arg_params, aux_params = mx.model.load_checkpoint('model_algo_1', 0)
mod = mx.mod.Module(symbol=sym, context=mx.cpu(), label_names=['label'])
mod.bind(for_training=False, data_shapes=[('data', (1,3,500,500))], label_shapes=[('label', (1, 1, 350))])
mod.set_params(arg_params, aux_params, allow_missing=True)
metric = MApMetric( )
eval_iter = DetRecordIter(path_imgrec, batch_size, data_shape,
path_imglist=path_imglist, **cfg.valid)
results = mod.score(eval_iter, metric, num_batch=None,
batch_end_callback=mx.callback.Speedometer(batch_size, frequent=frequent, auto_reset=False))
mod.score() can get a metric result, like MAP. But if I want a boxes results, which I can use to plot the boxes in an image, how should I do ?