alibaba / MNN

MNN is a blazing fast, lightweight deep learning framework, battle-tested by business-critical use cases in Alibaba
http://www.mnn.zone/
8.69k stars 1.66k forks source link

Convert CRNN -> MNN, inference fit dimensions assert. #147

Closed chrisYooh closed 5 years ago

chrisYooh commented 5 years ago

Crash We want to run ocr-detect model(The model use CRNN) with MNN. The convert passed(pytorch->onyx->mnn), but the inference createSession crashed. Could you please give me some suggestion to solve the problem? Thanks.

Information

image image

Model Reference GitHub: https://github.com/Sierkinhane/crnn_chinese_characters_rec ModelFile: models/crnn.py WeightFile: trained_models/mixed_second_finetune_acc97p7.pth

chrisYooh commented 5 years ago

1 Tip I found some more information, perhaps it will do some help to locate the problem.

2 Net structure fragment Our net has a sequence block like this:

....
OpType_Squeeze
OpType_Permute
OpType_Shape
...

3 Crash FLow 3.1 Before [Session::resize() --> iter->prepare()] (iter is a Pipeline)

....
OpType_Squeeze   mInputs[0].mBuffer.dimensions = 4,  mOutputs[0].mBuffer.dimensions = 4
OpType_Permute   input_dim = 4, output_dim = 4
OpType_Shape      input_dim = 4, output_dim = 4
...

3.2 After [Session::resize() --> iter->prepare()] (iter is a Pipeline) (Every Unit item run SizeComputer::computeOutputSize(mOriginOp, mInputs, mOutputs) in function Pipeline::Unit::prepare(Backend bn, Backend cpuBn))

....
OpType_Squeeze   input_dim = 4, output_dim = 3
OpType_Permute   input_dim = 3, output_dim = 3
OpType_Shape      input_dim = 3, output_dim = 1
...

3.3 Dimension fitting error When operation CPUShape run onExecute, it fit the assert. ErrorCode CPUShape::onExecute(const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs)

4 Guess

  1. Perhaps OpType_Squeeze need not decrease the dimensions? (ShapeSqueeze.cpp 65L: ob.dimensions = ib.dimensions - squeezeDimSize;)
  2. Perhaps OpType_Shape need access Tensor with dimensions != 4?
  3. Perhaps the operations cooperation need do some thing more?

Hope to solve the problem and expect your reply. Thanks very very much. And I will continue debugging it.

li-qing commented 5 years ago

pull latest codes plz, the assert have been removed.

chrisYooh commented 5 years ago

Thanks, we have try another way to solve our problem and successed. (That means I will not do some test about the update) So if your team have pass the related test, I think the issue could be closed.

lebronjdw commented 5 years ago

Thanks, we have try another way to solve our problem and successed. (That means I will not do some test about the update) So if your team have pass the related test, I think the issue could be closed.

Hi,Can you show me how you make it work in MNN with your crnn project?