opencv: ConvolutionDepthwise is even slower than Normal Convolution.
System information (version)
- OpenCV = 4.0.0
- Operating System / Platform = Windows 64 Bit
- Compiler = Visual Studio 2017
Detailed description
OpenCV dnn ConvolutionDepthwise
is slow than normal Convolution
.
settings:
net.setPreferableBackend(DNN_BACKEND_OPENCV);
net.setPreferableTarget(DNN_TARGET_CPU);
I made the following changes to my CNN model and found that it was slowing down!
```.prototxt
layer {
name: "conv2"
type: "Convolution" # change to "ConvolutionDepthwise"
bottom: "PReLU2"
top: "Convolution3"
convolution_param {
num_output: 16
pad: 0
kernel_size: 3
group: 1 # change to 16
stride: 1
}
}
Steps to reproduce
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace cv::dnn;
void benchmark(String network) {
Net net = readNet(format("models/%s.prototxt", network),
format("models/%s.caffemodel", network));
net.setPreferableBackend(DNN_BACKEND_OPENCV);
net.setPreferableTarget(DNN_TARGET_CPU);
net.enableFusion(true);
vector<String> out_names = net.getUnconnectedOutLayersNames();
cv::VideoCapture capture("data/single.mp4");
cv::Mat frame;
cv::TickMeter tm;
int frames = 0;
tm.reset();
int cnt = 0;
while (true) {
capture >> frame;
if (frame.empty())
break;
cnt++;
resize(frame, frame, Size(800, 600));
tm.start();
vector<cv::Mat> out_blobs;
net.setInput(blobFromImage(frame));
net.forward(out_blobs, out_names);
tm.stop();
if (cv::waitKey(1) == 'q')
break;
if (cnt == 100)
break;
}
std::cout << cv::format("%.2f ms", tm.getTimeMilli() / cnt) << std::endl;
}
int main() {
benchmark("cnn"); // 31.65 ms
benchmark("dw-cnn"); // 33.45 ms
return 0;
}
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (7 by maintainers)
Hi! Please take a look at https://github.com/opencv/opencv/pull/17858
@dkurt I tested the effect of channels on the efficiency of dwconv v.s. conv. when channels increases, the advantages of dwconv become more obvious. Maybe dwconv is suitable when channels ≥ 64。