Skip to content
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

dnn(darknet-importer): add grouped convolutions, sigmoid, swish, scale_channels #16436

Merged
merged 6 commits into from
Mar 10, 2020

Conversation

YashasSamaga
Copy link
Contributor

@YashasSamaga YashasSamaga commented Jan 26, 2020

resolves #15987

Merge with extra: opencv/opencv_extra#711

This pull request changes

  • adds support for grouped convolutions
  • adds new activations
    • sigmoid
    • swish
  • adds support for scale channels

Prediction using OpenCV CPU backend:

Screenshot from 2020-03-01 22-47-12

Darknet Reference:

tvmonitor: 44%
dog: 78%
cat: 27%
bicycle: 58%
truck: 89%
car: 33%

predictions

force_builders=Custom,Custom Win,Custom Mac
build_image:Custom=ubuntu-openvino-2020.1.0:16.04
build_image:Custom Win=openvino-2020.1.0
build_image:Custom Mac=openvino-2020.1.0

test_modules:Custom=dnn,python2,python3,java
test_modules:Custom Win=dnn,python2,python3,java
test_modules:Custom Mac=dnn,python2,python3,java

buildworker:Custom=linux-1
# disabled due high memory usage: test_opencl:Custom=ON
test_opencl:Custom=OFF
test_bigdata:Custom=1
test_filter:Custom=*

@dkurt
Copy link
Member

dkurt commented Jan 26, 2020

Please add single layer tests for each of newly added layers. You may take a look at #16358 as a reference.

find out why darknet output doesn't match with OCV CPU output

What about input image resolution? Have you used RGB or BGR input?

@dkurt dkurt added the pr: needs test New functionality requires minimal tests set label Feb 3, 2020
@YashasSamaga YashasSamaga changed the title dnn(darknet-importer): add grouped convolutions, sigmoid, swish, dropout, scale_channels dnn(darknet-importer): add grouped convolutions, sigmoid, swish, scale_channels Feb 8, 2020
@YashasSamaga
Copy link
Contributor Author

@dkurt For the convolution and activation tests, should I create a new cfg files for swish, logistic and grouped convolution OR add more layers to existing convolutional.cfg?

@dkurt
Copy link
Member

dkurt commented Feb 8, 2020

@YashasSamaga, I think the best way if to check existing tests and replace some of duplicated activation to new ones.

@YashasSamaga
Copy link
Contributor Author

scale_channels does not work with batches.

// There is a mode when we multiply a first blob by a second one
// instead of trainable weights.
Mat weights = blobs.empty() ? inputs[1] : (hasWeights ? blobs[0] : Mat());
Mat bias = hasBias ? blobs.back().reshape(1, 1) : Mat();
if (!weights.empty())
weights = weights.reshape(1, 1);
MatShape inpShape = shape(inpBlob);
const int numWeights = !weights.empty() ? weights.total() : bias.total();
CV_Assert(numWeights != 0);

weights is reshaped (assuming that batch size is one?).

int endAxis;
for (endAxis = axis + 1; endAxis <= inpBlob.dims; ++endAxis)
{
if (total(inpShape, axis, endAxis) == numWeights)
break;
}
CV_Assert(total(inpShape, axis, endAxis) == numWeights);

This code ignores the batch dimension and tries to match numWeights (i.e. weights.total()) to a subrange in the input tensor.

Example:

input shape: 2 3 3 3
weights input: 2 3 1 1

weights is reshaped to 6 1. The matching code tries to look for a subrange in the input (2 3 3 3) which totals to 6 but it fails to find any.

I can tweak the ScaleLayer to make it behave like Darknet's scale channels but I fear that it would break things and other backends may not be setup to behave like Darknet's scale channels.

Or I can add a new layer which behaves like Darknet's scale channels.

@dkurt
Copy link
Member

dkurt commented Feb 13, 2020

@YashasSamaga, let's open a new issue for that observation. So for Scale layer there will be a new test with batch size 1 but for Swish and Logistic - let's try to include them to existing ones.

@YashasSamaga
Copy link
Contributor Author

I have used a different branch name in opencv_extra PR. How can the CI be informed about it?

@alalek
Copy link
Member

alalek commented Mar 6, 2020

Need to adjust Inference Engine checks.
@l-bat Please suggest required changes.

@l-bat
Copy link
Contributor

l-bat commented Mar 10, 2020

Please, rebase with updated 3.4. PR #16738 fixed your tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature-request: EfficientNet as backbone for Yolo v3 Detector:
5 participants