Weighted softmax - test error


#1

I have been following this:

for weighted softmax, the training works fine but when I test it I get the following error:

src/executor/graph_executor.cc:456: InferShape pass cannot decide shapes for the following arguments (0s means unknown dimensions). Please consider providing them as inputs:

softmax26_label: [],

what do I need to do?


#2

This is how I test it:
ctx = mx.gpu()
mod = mx.mod.Module(symbol=sym, context=ctx,label_names=None)
mod.bind(for_training=False, data_shapes=[(‘data’, (1,3,224,224))])
mod.set_params(arg_params, aux_params, allow_missing=True)

pred_rec = pred_file.replace('.txt','.rec')

t0 = time.time()
test = mx.io.ImageRecordIter(
        path_imglist= pred_file,
        path_imgrec = pred_rec,
        mean_r      = 127.5,
        mean_g      = 127.5,
        mean_b      = 127.5,
        #mean_img    = mean_file,
        rand_crop   = False,
        rand_mirror = False,
        data_shape  = data_shape,
        batch_size  = 1,
        label_width = NUM_LABELS
        )
t1 = time.time()

#3

The symbol that you’re using as your network output is WeightedSoftmaxCrossEntropyLoss, which requires a label. You can either provide a dummy label (won’t be used because forward is simply calculating the softmax) or even better, replace your last layer with a simple softmax symbol so that your network doesn’t have a label dependency.


#4

Thanks for your reply. This is the original symbol.json file that I have (which should have the weights in it too)

{
“op”: “Custom”,
“name”: “softmax26”,
“attrs”: {
“class_weights”: “0.1,10”,
“op_type”: “weighted_softmax_ce_loss”
},
“inputs”: [[637, 0, 0], [638, 0, 0]]
},
{
“op”: “MakeLoss”,
“name”: “makeloss0”,
“inputs”: [[639, 0, 0]]
},
{
“op”: “_mul_scalar”,
“name”: “_mulscalar16”,
“attrs”: {“scalar”: “8”},
“inputs”: [[640, 0, 0]]
},
{
“op”: “null”,
“name”: “fc_t26_weight”,
“attrs”: {“num_hidden”: “2”},
“inputs”: []
},
{
“op”: “null”,
“name”: “fc_t26_bias”,
“attrs”: {“num_hidden”: “2”},
“inputs”: []
},

I have modified it to be like:

{
“op”: “SoftmaxOutput”,
“name”: “softmax26”,
“attrs”: {
},
“inputs”: [[637, 0, 0], [638, 0, 0]]
},
{
“op”: “MakeLoss”,
“name”: “makeloss0”,
“inputs”: [[639, 0, 0]]
},
{
“op”: “_mul_scalar”,
“name”: “_mulscalar16”,
“attrs”: {“scalar”: “8”},
“inputs”: [[640, 0, 0]]
},
{
“op”: “null”,
“name”: “fc_t26_weight”,
“attrs”: {“num_hidden”: “2”},
“inputs”: []
},
{
“op”: “null”,
“name”: “fc_t26_bias”,
“attrs”: {“num_hidden”: “2”},
“inputs”: []
},

is that what you meants?


#5

You shouldn’t need to modify your symbol file. Take a look at this example where for inference the last layer is modified to be a softmax:

An alternative would be to use Gluon and live a happy, stress-free life :slight_smile:


#6

thanks for the reply. I will move to Gluon soon :slight_smile: