-
Notifications
You must be signed in to change notification settings - Fork 6.8k
MXPredReshape bug: need to reshape softmax_label #12176
Conversation
In the inference stage, it's no need to use labels or SoftmaxOutput. |
You can write a script to deploy the symbol by replace SoftmaxOutput with SoftmaxActivate. |
@chinakook, To predict using the C API, you use |
Thanks for identifying the issue and filing this PR @chsin . |
bounce again @apeforest @anirudh2290 @eric-haibin-lin |
@apeforest @anirudh2290 @eric-haibin-lin ping for review |
@mxnet-label-bot [pr-awaiting-review] |
@@ -304,7 +304,8 @@ int MXPredReshape(mx_uint num_input_nodes, | |||
for (size_t i=0; i < arg_names.size(); ++i) { | |||
TShape newShape = arg_shapes[i]; | |||
NDArray &arr = p->arg_arrays[i]; | |||
if (new_shape.count(arg_names[i]) != 0) { | |||
if (new_shape.count(arg_names[i]) != 0 || | |||
strcmp("softmax_label", arg_names[i].c_str()) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still trying to understand the problem. But this hack is not acceptable purely from coding practice.
@chsin Can you please address review comments? Thanks! |
@chsin ping! Could you please address the comments? Thanks! |
@chsin Thanks for your contribution! We would like to take the process of merging this PR forward - could you please address comments above? |
@mxnet-label-bot update [pr-awaiting-response] |
adding @Vikas89 for review |
@chsin Thanks for the contribution, looks like our CI hanged, could trigger it by push an empty commit? |
@chsin - Can you please rebase and retrigger CI? |
@anirudh2290 Can you review this PR? |
@anirudh2290 ping for review @chsin could you rebase and retrigger CI thanks! |
@chsin - Thanks for your contributions. Like @apeforest mentioned, this change looks like not generalizable. What happens if name of last layer is not 'softmax_label' for example in Gluon case it will may be prefixed with name_scope. |
Description
The fix in #11493 allows reshape only for networks that don't use SoftmaxOutput, so none of the pretrained image classification networks, e.g. inception, can be reshaped. The current test did not catch this because it only used gluon blocks. The reason SoftmaxOutput is weird is because it requires the label "softmax_label" to be reshaped even though "softmax_label" is only used as an input for training and should not even be looked at for prediction, which has been mentioned in other context before. I don't know what's the best way to deal with SoftmaxOutput's label reshape requirement because I can't find a way to get the label names. I am sending this pull request with an edit that allows resnet and inception to be reshaped, along with a test that covers this edge case, but I hope someone can comment on a more robust solution.
I found this issue when I made the following edits to image-classification-predict.cc:223. Before this change, the following would print out -1 and I traced it to
c_predict_api.cc:304
wherenewShape.Size() != arr.shape().Size()
for whenarg_names[I]
issoftmax_label
:Checklist
Essentials
Please feel free to remove inapplicable items for your PR.