Data provided by label_shapes don't match names specified by label_names ([] vs. ['softmax_label'])
I get the warning "Data provided by label_shapes don't match names specified by label_names ([] vs. ['softmax_label'])" when I bind a model for inference. The data iterator I use for inference has no labels. The model seems to have 'softmax_label' as one of the label names. Since, 'softmax_label' is not present in the iterator, I get the above mentioned warning.
I think if bind sets for_training=False, lack of label in the iterator should not generate a warning.
Error Message:
Data provided by label_shapes don't match names specified by label_names ([] vs. ['softmax_label'])
Minimum reproducible example
import mxnet as mx
mnist = mx.test_utils.get_mnist()
batch_size = 100
train_iter = mx.io.NDArrayIter(mnist['train_data'], mnist['train_label'], batch_size, shuffle=True)
val_iter = mx.io.NDArrayIter(mnist['test_data'], mnist['test_label'], batch_size)
data = mx.sym.var('data')
# Flatten the data from 4-D shape into 2-D (batch_size, num_channel*width*height)
data = mx.sym.flatten(data=data)
# The first fully-connected layer and the corresponding activation function
fc1 = mx.sym.FullyConnected(data=data, num_hidden=128)
act1 = mx.sym.Activation(data=fc1, act_type="relu")
# The second fully-connected layer and the corresponding activation function
fc2 = mx.sym.FullyConnected(data=act1, num_hidden = 64)
act2 = mx.sym.Activation(data=fc2, act_type="relu")
# MNIST has 10 classes
fc3 = mx.sym.FullyConnected(data=act2, num_hidden=10)
# Softmax with cross entropy loss
mlp = mx.sym.SoftmaxOutput(data=fc3, name='softmax')
import logging
logging.getLogger().setLevel(logging.DEBUG) # logging to stdout
# create a trainable module on CPU
mlp_model = mx.mod.Module(symbol=mlp, context=mx.cpu())
mlp_model.fit(train_iter, # train data
eval_data=val_iter, # validation data
optimizer='sgd', # use SGD to train
optimizer_params={'learning_rate':0.1}, # use fixed learning rate
eval_metric='acc', # report accuracy during training
batch_end_callback = mx.callback.Speedometer(batch_size, 100), # output progress for each 100 data batches
num_epoch=10) # train for at most 10 dataset passes
test_iter = mx.io.NDArrayIter(mnist['test_data'], None, batch_size)
mlp_model.bind(data_shapes=test_iter.provide_data, label_shapes=None,
force_rebind=True, for_training=False)
prob = mlp_model.predict(test_iter)
assert prob.shape == (10000, 10)
test_iter = mx.io.NDArrayIter(mnist['test_data'], mnist['test_label'], batch_size)
mlp_model.bind(data_shapes=test_iter.provide_data, label_shapes=test_iter.provide_label,
force_rebind=True, for_training=False)
# predict accuracy of mlp
acc = mx.metric.Accuracy()
mlp_model.score(test_iter, acc)
print(acc)
assert acc.get()[1] > 0.96
Steps to reproduce
Just run the above code.
Environment info
Ubuntu 16.04
Compiler: GCC
Package used (Python/R/Scala/Julia): Python
MXNet version:
Or if installed from source:
MXNet commit hash (git rev-parse HEAD):
202de02cd713eb17300404b842261f126b6e3c97
If you are using python package, please provide
Python version and distribution: Python 3.6.1 :: Anaconda 4.4.0 (64-bit)
If you are using R package, please provide
R sessionInfo():
This issue is closed due to lack of activity in the last 90 days. Feel free to ping me to reopen if this is still an active issue. Thanks!
Has anyone looked at the issue again?
You can check this https://stackoverflow.com/questions/44947104/mxnet-label-shapes-dont-match-names-specified-by-label-names