-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add a test case for handling output_shape property for deconv layer. #582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a test case for handling output_shape property for deconv layer. #582
Conversation
|
@kohei-us, Please show us how these test files are generated. Add a modified https://github.com/opencv/opencv_extra/blob/master/testdata/dnn/onnx/generate_onnx_models.py |
|
@kurt I used Keras to create a model and then convert it to onnx. I noticed that the script uses PyTorch to generate models. Would a use of Keras be okay in that script, or is PyTorch required? |
|
@kohei-us, If it's possible to do all the conversions in python I'd like to suggest to add Keras model in this script. Please use |
|
I've now stumbled upon one major issue. Originally, I created a keras model and converted to onnx using an older version of onnxmltools, and that converter added the output_shape attribute to ConvTranspose, which is what this test case is designed to test. However, since then the onnxmltools has changed quite a bit, and when using their latest code (it's now been split into a separate project called keras-onnx), the converted onnx model no longer contains the output_shape attribute... :-( I have also tried using PyTorch to create an onnx model with ConvTranspose, but that one doesn't have output_shape either. Hmm... |
|
@kohei-us, May I ask you to add a line std::cout << layerParams << std::endl;So we can check all the parameters except |
|
@dkurt Sure thing. Here is the output for the new test data I've added:
|
|
@kohei-us, May I also ask you to specify which size has input blob for this layer? |
|
@dkurt Sure. It's (1, 1, 28, 28). |
|
@kohei-us, This way deconvolution layer uses the following formula to compute output shape: else if (padMode == "SAME")
{
outH = stride.height * (inpH - 1) + 1 + adjustPad.height;
outW = stride.width * (inpW - 1) + 1 + adjustPad.width;
}So However user specified output shape May I ask you to check how OpenCV manage it for TensorFlow models: https://github.com/opencv/opencv/blob/master/modules/dnn/src/tensorflow/tf_importer.cpp: const int outH = outShape.at<int>(1);
const int outW = outShape.at<int>(2);
if (layerParams.get<String>("pad_mode") == "SAME")
{
layerParams.set("adj_w", (outW - 1) % strideX);
layerParams.set("adj_h", (outH - 1) % strideY);
}
else if (layerParams.get<String>("pad_mode") == "VALID")
{
layerParams.set("adj_w", (outW - kernelW) % strideX);
layerParams.set("adj_h", (outH - kernelH) % strideY);
}So you can just read output shape and compute adjust padding: layerParams.set("adj_w", (83 - 1) % 3); // == 1
layerParams.set("adj_h", (83 - 1) % 3); |
…layer. This is related to opencv/opencv#13989.
50286a5 to
46f1cbd
Compare
This is related to opencv/opencv#13989.