├── .gitignore ├── README.md ├── opencv_base_project.sln ├── opencv_base_project ├── ReadMe.txt ├── opencv_base_project.cpp ├── opencv_base_project.vcxproj └── opencv_base_project.vcxproj.filters └── x64 └── Release ├── 11.jpg ├── face_mask_detection.caffemodel └── face_mask_detection.prototxt /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FaceMaskDetection 2 | FaceMaskDetection Implementation with opencv C++ 3 | from https://github.com/AIZOOTech/FaceMaskDetection 4 | -------------------------------------------------------------------------------- /opencv_base_project.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opencv_base_project", "opencv_base_project\opencv_base_project.vcxproj", "{F451EC88-B092-4023-B887-4615A82A8288}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {F451EC88-B092-4023-B887-4615A82A8288}.Debug|x64.ActiveCfg = Debug|x64 17 | {F451EC88-B092-4023-B887-4615A82A8288}.Debug|x64.Build.0 = Debug|x64 18 | {F451EC88-B092-4023-B887-4615A82A8288}.Debug|x86.ActiveCfg = Debug|Win32 19 | {F451EC88-B092-4023-B887-4615A82A8288}.Debug|x86.Build.0 = Debug|Win32 20 | {F451EC88-B092-4023-B887-4615A82A8288}.Release|x64.ActiveCfg = Release|x64 21 | {F451EC88-B092-4023-B887-4615A82A8288}.Release|x64.Build.0 = Release|x64 22 | {F451EC88-B092-4023-B887-4615A82A8288}.Release|x86.ActiveCfg = Release|Win32 23 | {F451EC88-B092-4023-B887-4615A82A8288}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /opencv_base_project/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:opencv_base_project 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 opencv_base_project 应用程序。 6 | 7 | 本文件概要介绍组成 opencv_base_project 应用程序的每个文件的内容。 8 | 9 | 10 | opencv_base_project.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | opencv_base_project.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | opencv_base_project.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 opencv_base_project.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /opencv_base_project/opencv_base_project.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | #define RUN_TYPE_IMAGE 0 6 | #define RUN_TYPE_VIDEO 1 7 | 8 | #define USE_RUN_TYPE RUN_TYPE_IMAGE 9 | 10 | vector> generate_anchors(const vector &ratios, const vector &scales, vector &anchor_base) 11 | { 12 | vector> anchors; 13 | for (int idx = 0; idx < scales.size(); idx++) { 14 | vector bbox_coords; 15 | int s = scales[idx]; 16 | vector cxys; 17 | vector center_tiled; 18 | for (int i = 0; i < s; i++) { 19 | float x = (0.5 + i) / s; 20 | cxys.push_back(x); 21 | } 22 | 23 | for (int i = 0; i < s; i++) { 24 | float x = (0.5 + i) / s; 25 | for (int j = 0; j < s; j++) { 26 | for (int k = 0; k < 8; k++) { 27 | center_tiled.push_back(cxys[j]); 28 | center_tiled.push_back(x); 29 | //printf("%f %f ", cxys[j], x); 30 | } 31 | //printf("\n"); 32 | } 33 | //printf("\n"); 34 | } 35 | 36 | vector anchor_wh; 37 | for (int i = 0; i < anchor_base.size(); i++) { 38 | float scale = anchor_base[i] * pow(2, idx); 39 | anchor_wh.push_back(-scale / 2.0); 40 | anchor_wh.push_back(-scale / 2.0); 41 | anchor_wh.push_back(scale / 2.0); 42 | anchor_wh.push_back(scale / 2.0); 43 | //printf("%f %f %f %f\n", -scale / 2.0, -scale / 2.0, scale / 2.0, scale / 2.0); 44 | } 45 | 46 | for (int i = 0; i < anchor_base.size(); i++) { 47 | float s1 = anchor_base[0] * pow(2, idx); 48 | float ratio = ratios[i + 1]; 49 | float w = s1 * sqrt(ratio); 50 | float h = s1 / sqrt(ratio); 51 | anchor_wh.push_back(-w / 2.0); 52 | anchor_wh.push_back(-h / 2.0); 53 | anchor_wh.push_back(w / 2.0); 54 | anchor_wh.push_back(h / 2.0); 55 | //printf("s1:%f, ratio:%f w:%f h:%f\n", s1, ratio, w, h); 56 | //printf("%f %f %f %f\n", -w / 2.0, -h / 2.0, w / 2.0, h / 2.0); 57 | } 58 | 59 | int index = 0; 60 | //printf("\n"); 61 | for (float &a : center_tiled) { 62 | float c = a + anchor_wh[(index++) % anchor_wh.size()]; 63 | bbox_coords.push_back(c); 64 | //printf("%f ", c); 65 | } 66 | 67 | //printf("bbox_coords.size():%d\n", bbox_coords.size()); 68 | int anchors_size = bbox_coords.size() / 4; 69 | for (int i = 0; i < anchors_size; i++) { 70 | vector f; 71 | for (int j = 0; j < 4; j++) { 72 | f.push_back(bbox_coords[i * 4 + j]); 73 | } 74 | anchors.push_back(f); 75 | } 76 | } 77 | 78 | return anchors; 79 | } 80 | 81 | vector decode_bbox_classes(vector> &anchors, float *delta, int img_w, int img_h, float thresh, float *score, 82 | vector &out_classes, vector &out_scores) 83 | { 84 | vector rects; 85 | float v[4] = { 0.1, 0.1, 0.2, 0.2 }; 86 | for (int n = 0; n < anchors.size(); n++) { 87 | 88 | float m_score = max(score[2 * n], score[2 * n + 1]); 89 | if (m_score < thresh) { 90 | continue; 91 | } 92 | 93 | vector& k = anchors[n]; 94 | float acx = (k[0] + k[2]) / 2; 95 | float acy = (k[1] + k[3]) / 2; 96 | float acw = (k[2] - k[0]); 97 | float ach = (k[3] - k[1]); 98 | 99 | float r0 = delta[n * 4 + 0] * v[0]; 100 | float r1 = delta[n * 4 + 1] * v[1]; 101 | float r2 = delta[n * 4 + 2] * v[2]; 102 | float r3 = delta[n * 4 + 3] * v[3]; 103 | 104 | float centet_x = r0 * acw + acx; 105 | float centet_y = r1 * ach + acy; 106 | 107 | float w = exp(r2) * acw; 108 | float h = exp(r3) * ach; 109 | float x = (centet_x - w / 2) * img_w; 110 | float y = (centet_y - h / 2) * img_h; 111 | w *= img_w; 112 | h *= img_h; 113 | rects.push_back(cv::Rect(x, y, w, h)); 114 | 115 | int m_class = score[2 * n] > score[2 * n + 1] ? 0 : 1; 116 | out_classes.push_back(m_class); 117 | out_scores.push_back(m_score); 118 | 119 | } 120 | 121 | return rects; 122 | } 123 | 124 | int main() 125 | { 126 | float conf_thresh = 0.75; 127 | float iou_thresh = 0.7; 128 | vector anchor_base = { (float)0.04, (float)0.056 }; 129 | vector ratios = { (float)1.0, (float)0.62, (float)0.42 }; 130 | vector scales = { 33, 17, 9, 5, 3 }; 131 | vector> anchors = generate_anchors(ratios, scales, anchor_base); 132 | cv::dnn::Net net = cv::dnn::readNetFromCaffe("face_mask_detection.prototxt", "face_mask_detection.caffemodel"); 133 | 134 | #if (USE_RUN_TYPE == RUN_TYPE_IMAGE) 135 | cv::Mat img = cv::imread("11.jpg"); 136 | if (!img.data) { 137 | printf("!img.data\n"); 138 | return 0; 139 | } 140 | #endif 141 | 142 | #if (USE_RUN_TYPE == RUN_TYPE_VIDEO) 143 | cv::VideoCapture vc("demo.mp4"); 144 | cv::Mat img; 145 | while (1) 146 | { 147 | vc >> img; 148 | if (!img.data) { 149 | break; 150 | } 151 | #endif 152 | double time = static_cast(cv::getTickCount()); 153 | cv::Mat rgb_img; 154 | cvtColor(img, rgb_img, cv::COLOR_BGR2RGB); 155 | cv::Mat input_blob = cv::dnn::blobFromImage(rgb_img, 1 / 255.0, cv::Size(260, 260), cv::Scalar(0, 0, 0), false); 156 | 157 | net.setInput(input_blob, "data"); 158 | 159 | vector< cv::String > targets_node{ "loc_branch_concat","cls_branch_concat" }; 160 | vector< cv::Mat > targets_blobs; 161 | 162 | net.forward(targets_blobs, targets_node); 163 | 164 | cv::Mat feature_bboxes = targets_blobs[0]; 165 | cv::Mat feature_score = targets_blobs[1]; 166 | float *bboxes = (float*)feature_bboxes.data; 167 | float *confs = (float*)feature_score.data; 168 | vector classes; 169 | vector scores; 170 | vector rects = decode_bbox_classes(anchors, bboxes, rgb_img.cols, rgb_img.rows, conf_thresh, confs, classes, scores); 171 | vector keep_idxs; 172 | cv::dnn::NMSBoxes(rects, scores, conf_thresh, 1.0 - iou_thresh, keep_idxs); 173 | time = ((double)cv::getTickCount() - time) / cv::getTickFrequency() * 1000; 174 | 175 | char str[64]; 176 | for (int i : keep_idxs) { 177 | cv::Scalar str_coclr; 178 | if (classes[i] == 0) { 179 | snprintf(str, 64, "mask"); 180 | str_coclr = cv::Scalar(0, 255, 255); 181 | } 182 | else { 183 | snprintf(str, 64, "numask"); 184 | str_coclr = cv::Scalar(0, 0, 255); 185 | } 186 | 187 | cv::Rect &r = rects[i]; 188 | cv::putText(img, str, r.tl(), 1, 1.0, str_coclr); 189 | snprintf(str, 64, "%0.2f%%", scores[i] * 100); 190 | cv::putText(img, str, cv::Point(r.x, r.y + 10), 1, 0.8, cv::Scalar(255, 255, 255)); 191 | cv::rectangle(img, r, cv::Scalar(0, 255, 255)); 192 | } 193 | snprintf(str, 64, "fps:%d", 1000 / (int)time); 194 | cv::putText(img, str, cv::Point(0, 12), 1, 1.2, cv::Scalar(180, 180, 180)); 195 | cv::imshow("img", img); 196 | 197 | #if (USE_RUN_TYPE == RUN_TYPE_IMAGE) 198 | cv::waitKey(0); 199 | #endif 200 | 201 | #if (USE_RUN_TYPE == RUN_TYPE_VIDEO) 202 | if ('q' == cv::waitKey(1)) { 203 | break; 204 | } 205 | } 206 | #endif 207 | 208 | return 0; 209 | } 210 | -------------------------------------------------------------------------------- /opencv_base_project/opencv_base_project.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {F451EC88-B092-4023-B887-4615A82A8288} 23 | Win32Proj 24 | opencv_base_project 25 | 8.1 26 | 27 | 28 | 29 | Application 30 | true 31 | v140 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v140 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v140 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v140 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | D:\Program Files\opencv-4.0.0-rc\build\install\include;D:\Program Files\opencv-4.0.0-rc\build\install\include\opencv2;$(IncludePath) 84 | D:\Program Files\opencv-4.0.0-rc\build\install\x64\vc14\lib;$(LibraryPath) 85 | 86 | 87 | 88 | 89 | 90 | Level3 91 | Disabled 92 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 93 | 94 | 95 | Console 96 | true 97 | 98 | 99 | 100 | 101 | 102 | 103 | Level3 104 | Disabled 105 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 106 | 107 | 108 | Console 109 | true 110 | 111 | 112 | 113 | 114 | Level3 115 | 116 | 117 | MaxSpeed 118 | true 119 | true 120 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 121 | 122 | 123 | Console 124 | true 125 | true 126 | true 127 | 128 | 129 | 130 | 131 | Level3 132 | 133 | 134 | MaxSpeed 135 | true 136 | true 137 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 138 | 139 | 140 | Console 141 | true 142 | true 143 | true 144 | opencv_world400.lib;%(AdditionalDependencies) 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /opencv_base_project/opencv_base_project.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 源文件 23 | 24 | 25 | -------------------------------------------------------------------------------- /x64/Release/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcings/FaceMaskDetection/e1034e6f1c2f37aee9cc7f7d3bdbd988ba7e36bd/x64/Release/11.jpg -------------------------------------------------------------------------------- /x64/Release/face_mask_detection.caffemodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcings/FaceMaskDetection/e1034e6f1c2f37aee9cc7f7d3bdbd988ba7e36bd/x64/Release/face_mask_detection.caffemodel -------------------------------------------------------------------------------- /x64/Release/face_mask_detection.prototxt: -------------------------------------------------------------------------------- 1 | input: "data" 2 | input_dim: 1 3 | input_dim: 3 4 | input_dim: 260 5 | input_dim: 260 6 | layer { 7 | name: "conv2d_0" 8 | type: "Convolution" 9 | bottom: "data" 10 | top: "conv2d_0" 11 | convolution_param { 12 | num_output: 32 13 | bias_term: true 14 | pad: 1 15 | kernel_size: 3 16 | stride: 1 17 | } 18 | } 19 | layer { 20 | name: "conv2d_0_activation" 21 | type: "ReLU" 22 | bottom: "conv2d_0" 23 | top: "conv2d_0" 24 | } 25 | layer { 26 | name: "maxpool2d_0" 27 | type: "Pooling" 28 | bottom: "conv2d_0" 29 | top: "maxpool2d_0" 30 | pooling_param { 31 | pool: MAX 32 | kernel_size: 2 33 | stride: 2 34 | } 35 | } 36 | layer { 37 | name: "conv2d_1" 38 | type: "Convolution" 39 | bottom: "maxpool2d_0" 40 | top: "conv2d_1" 41 | convolution_param { 42 | num_output: 64 43 | bias_term: true 44 | pad: 1 45 | kernel_size: 3 46 | stride: 1 47 | } 48 | } 49 | layer { 50 | name: "conv2d_1_activation" 51 | type: "ReLU" 52 | bottom: "conv2d_1" 53 | top: "conv2d_1" 54 | } 55 | layer { 56 | name: "maxpool2d_1" 57 | type: "Pooling" 58 | bottom: "conv2d_1" 59 | top: "maxpool2d_1" 60 | pooling_param { 61 | pool: MAX 62 | kernel_size: 2 63 | stride: 2 64 | } 65 | } 66 | layer { 67 | name: "conv2d_2" 68 | type: "Convolution" 69 | bottom: "maxpool2d_1" 70 | top: "conv2d_2" 71 | convolution_param { 72 | num_output: 64 73 | bias_term: true 74 | pad: 1 75 | kernel_size: 3 76 | stride: 1 77 | } 78 | } 79 | layer { 80 | name: "conv2d_2_activation" 81 | type: "ReLU" 82 | bottom: "conv2d_2" 83 | top: "conv2d_2" 84 | } 85 | layer { 86 | name: "maxpool2d_2" 87 | type: "Pooling" 88 | bottom: "conv2d_2" 89 | top: "maxpool2d_2" 90 | pooling_param { 91 | pool: MAX 92 | kernel_size: 2 93 | stride: 2 94 | } 95 | } 96 | layer { 97 | name: "conv2d_3" 98 | type: "Convolution" 99 | bottom: "maxpool2d_2" 100 | top: "conv2d_3" 101 | convolution_param { 102 | num_output: 64 103 | bias_term: true 104 | pad: 1 105 | kernel_size: 3 106 | stride: 1 107 | } 108 | } 109 | layer { 110 | name: "conv2d_3_activation" 111 | type: "ReLU" 112 | bottom: "conv2d_3" 113 | top: "conv2d_3" 114 | } 115 | layer { 116 | name: "maxpool2d_3" 117 | type: "Pooling" 118 | bottom: "conv2d_3" 119 | top: "maxpool2d_3" 120 | pooling_param { 121 | pool: MAX 122 | kernel_size: 2 123 | stride: 2 124 | } 125 | } 126 | layer { 127 | name: "conv2d_4" 128 | type: "Convolution" 129 | bottom: "maxpool2d_3" 130 | top: "conv2d_4" 131 | convolution_param { 132 | num_output: 128 133 | bias_term: true 134 | pad: 1 135 | kernel_size: 3 136 | stride: 1 137 | } 138 | } 139 | layer { 140 | name: "conv2d_4_activation" 141 | type: "ReLU" 142 | bottom: "conv2d_4" 143 | top: "conv2d_4" 144 | } 145 | layer { 146 | name: "maxpool2d_4" 147 | type: "Pooling" 148 | bottom: "conv2d_4" 149 | top: "maxpool2d_4" 150 | pooling_param { 151 | pool: MAX 152 | kernel_size: 2 153 | stride: 2 154 | } 155 | } 156 | layer { 157 | name: "conv2d_5" 158 | type: "Convolution" 159 | bottom: "maxpool2d_4" 160 | top: "conv2d_5" 161 | convolution_param { 162 | num_output: 128 163 | bias_term: true 164 | pad: 1 165 | kernel_size: 3 166 | stride: 1 167 | } 168 | } 169 | layer { 170 | name: "conv2d_5_activation" 171 | type: "ReLU" 172 | bottom: "conv2d_5" 173 | top: "conv2d_5" 174 | } 175 | layer { 176 | name: "maxpool2d_5" 177 | type: "Pooling" 178 | bottom: "conv2d_5" 179 | top: "maxpool2d_5" 180 | pooling_param { 181 | pool: MAX 182 | kernel_size: 2 183 | stride: 2 184 | } 185 | } 186 | layer { 187 | name: "conv2d_6" 188 | type: "Convolution" 189 | bottom: "maxpool2d_5" 190 | top: "conv2d_6" 191 | convolution_param { 192 | num_output: 64 193 | bias_term: true 194 | pad: 1 195 | kernel_size: 3 196 | stride: 1 197 | } 198 | } 199 | layer { 200 | name: "conv2d_6_activation" 201 | type: "ReLU" 202 | bottom: "conv2d_6" 203 | top: "conv2d_6" 204 | } 205 | layer { 206 | name: "conv2d_7" 207 | type: "Convolution" 208 | bottom: "conv2d_6" 209 | top: "conv2d_7" 210 | convolution_param { 211 | num_output: 64 212 | bias_term: true 213 | kernel_size: 3 214 | stride: 1 215 | } 216 | } 217 | layer { 218 | name: "conv2d_7_activation" 219 | type: "ReLU" 220 | bottom: "conv2d_7" 221 | top: "conv2d_7" 222 | } 223 | layer { 224 | name: "cls_0_insert_conv2d" 225 | type: "Convolution" 226 | bottom: "conv2d_3" 227 | top: "cls_0_insert_conv2d" 228 | convolution_param { 229 | num_output: 64 230 | bias_term: true 231 | pad: 1 232 | kernel_size: 3 233 | stride: 1 234 | } 235 | } 236 | layer { 237 | name: "cls_1_insert_conv2d" 238 | type: "Convolution" 239 | bottom: "conv2d_4" 240 | top: "cls_1_insert_conv2d" 241 | convolution_param { 242 | num_output: 64 243 | bias_term: true 244 | pad: 1 245 | kernel_size: 3 246 | stride: 1 247 | } 248 | } 249 | layer { 250 | name: "cls_2_insert_conv2d" 251 | type: "Convolution" 252 | bottom: "conv2d_5" 253 | top: "cls_2_insert_conv2d" 254 | convolution_param { 255 | num_output: 64 256 | bias_term: true 257 | pad: 1 258 | kernel_size: 3 259 | stride: 1 260 | } 261 | } 262 | layer { 263 | name: "cls_3_insert_conv2d" 264 | type: "Convolution" 265 | bottom: "conv2d_6" 266 | top: "cls_3_insert_conv2d" 267 | convolution_param { 268 | num_output: 64 269 | bias_term: true 270 | pad: 1 271 | kernel_size: 3 272 | stride: 1 273 | } 274 | } 275 | layer { 276 | name: "cls_4_insert_conv2d" 277 | type: "Convolution" 278 | bottom: "conv2d_7" 279 | top: "cls_4_insert_conv2d" 280 | convolution_param { 281 | num_output: 64 282 | bias_term: true 283 | pad: 1 284 | kernel_size: 3 285 | stride: 1 286 | } 287 | } 288 | layer { 289 | name: "loc_0_insert_conv2d" 290 | type: "Convolution" 291 | bottom: "conv2d_3" 292 | top: "loc_0_insert_conv2d" 293 | convolution_param { 294 | num_output: 64 295 | bias_term: true 296 | pad: 1 297 | kernel_size: 3 298 | stride: 1 299 | } 300 | } 301 | layer { 302 | name: "loc_1_insert_conv2d" 303 | type: "Convolution" 304 | bottom: "conv2d_4" 305 | top: "loc_1_insert_conv2d" 306 | convolution_param { 307 | num_output: 64 308 | bias_term: true 309 | pad: 1 310 | kernel_size: 3 311 | stride: 1 312 | } 313 | } 314 | layer { 315 | name: "loc_2_insert_conv2d" 316 | type: "Convolution" 317 | bottom: "conv2d_5" 318 | top: "loc_2_insert_conv2d" 319 | convolution_param { 320 | num_output: 64 321 | bias_term: true 322 | pad: 1 323 | kernel_size: 3 324 | stride: 1 325 | } 326 | } 327 | layer { 328 | name: "loc_3_insert_conv2d" 329 | type: "Convolution" 330 | bottom: "conv2d_6" 331 | top: "loc_3_insert_conv2d" 332 | convolution_param { 333 | num_output: 64 334 | bias_term: true 335 | pad: 1 336 | kernel_size: 3 337 | stride: 1 338 | } 339 | } 340 | layer { 341 | name: "loc_4_insert_conv2d" 342 | type: "Convolution" 343 | bottom: "conv2d_7" 344 | top: "loc_4_insert_conv2d" 345 | convolution_param { 346 | num_output: 64 347 | bias_term: true 348 | pad: 1 349 | kernel_size: 3 350 | stride: 1 351 | } 352 | } 353 | layer { 354 | name: "cls_0_insert_conv2d_activation" 355 | type: "ReLU" 356 | bottom: "cls_0_insert_conv2d" 357 | top: "cls_0_insert_conv2d" 358 | } 359 | layer { 360 | name: "cls_1_insert_conv2d_activation" 361 | type: "ReLU" 362 | bottom: "cls_1_insert_conv2d" 363 | top: "cls_1_insert_conv2d" 364 | } 365 | layer { 366 | name: "cls_2_insert_conv2d_activation" 367 | type: "ReLU" 368 | bottom: "cls_2_insert_conv2d" 369 | top: "cls_2_insert_conv2d" 370 | } 371 | layer { 372 | name: "cls_3_insert_conv2d_activation" 373 | type: "ReLU" 374 | bottom: "cls_3_insert_conv2d" 375 | top: "cls_3_insert_conv2d" 376 | } 377 | layer { 378 | name: "cls_4_insert_conv2d_activation" 379 | type: "ReLU" 380 | bottom: "cls_4_insert_conv2d" 381 | top: "cls_4_insert_conv2d" 382 | } 383 | layer { 384 | name: "loc_0_insert_conv2d_activation" 385 | type: "ReLU" 386 | bottom: "loc_0_insert_conv2d" 387 | top: "loc_0_insert_conv2d" 388 | } 389 | layer { 390 | name: "loc_1_insert_conv2d_activation" 391 | type: "ReLU" 392 | bottom: "loc_1_insert_conv2d" 393 | top: "loc_1_insert_conv2d" 394 | } 395 | layer { 396 | name: "loc_2_insert_conv2d_activation" 397 | type: "ReLU" 398 | bottom: "loc_2_insert_conv2d" 399 | top: "loc_2_insert_conv2d" 400 | } 401 | layer { 402 | name: "loc_3_insert_conv2d_activation" 403 | type: "ReLU" 404 | bottom: "loc_3_insert_conv2d" 405 | top: "loc_3_insert_conv2d" 406 | } 407 | layer { 408 | name: "loc_4_insert_conv2d_activation" 409 | type: "ReLU" 410 | bottom: "loc_4_insert_conv2d" 411 | top: "loc_4_insert_conv2d" 412 | } 413 | layer { 414 | name: "cls_0_conv" 415 | type: "Convolution" 416 | bottom: "cls_0_insert_conv2d" 417 | top: "cls_0_conv" 418 | convolution_param { 419 | num_output: 8 420 | pad: 1 421 | kernel_size: 3 422 | stride: 1 423 | } 424 | } 425 | layer { 426 | name: "cls_1_conv" 427 | type: "Convolution" 428 | bottom: "cls_1_insert_conv2d" 429 | top: "cls_1_conv" 430 | convolution_param { 431 | num_output: 8 432 | pad: 1 433 | kernel_size: 3 434 | stride: 1 435 | } 436 | } 437 | layer { 438 | name: "cls_2_conv" 439 | type: "Convolution" 440 | bottom: "cls_2_insert_conv2d" 441 | top: "cls_2_conv" 442 | convolution_param { 443 | num_output: 8 444 | pad: 1 445 | kernel_size: 3 446 | stride: 1 447 | } 448 | } 449 | layer { 450 | name: "cls_3_conv" 451 | type: "Convolution" 452 | bottom: "cls_3_insert_conv2d" 453 | top: "cls_3_conv" 454 | convolution_param { 455 | num_output: 8 456 | pad: 1 457 | kernel_size: 3 458 | stride: 1 459 | } 460 | } 461 | layer { 462 | name: "cls_4_conv" 463 | type: "Convolution" 464 | bottom: "cls_4_insert_conv2d" 465 | top: "cls_4_conv" 466 | convolution_param { 467 | num_output: 8 468 | pad: 1 469 | kernel_size: 3 470 | stride: 1 471 | } 472 | } 473 | layer { 474 | name: "loc_0_conv" 475 | type: "Convolution" 476 | bottom: "loc_0_insert_conv2d" 477 | top: "loc_0_conv" 478 | convolution_param { 479 | num_output: 16 480 | pad: 1 481 | kernel_size: 3 482 | stride: 1 483 | } 484 | } 485 | layer { 486 | name: "loc_1_conv" 487 | type: "Convolution" 488 | bottom: "loc_1_insert_conv2d" 489 | top: "loc_1_conv" 490 | convolution_param { 491 | num_output: 16 492 | pad: 1 493 | kernel_size: 3 494 | stride: 1 495 | } 496 | } 497 | layer { 498 | name: "loc_2_conv" 499 | type: "Convolution" 500 | bottom: "loc_2_insert_conv2d" 501 | top: "loc_2_conv" 502 | convolution_param { 503 | num_output: 16 504 | pad: 1 505 | kernel_size: 3 506 | stride: 1 507 | } 508 | } 509 | layer { 510 | name: "loc_3_conv" 511 | type: "Convolution" 512 | bottom: "loc_3_insert_conv2d" 513 | top: "loc_3_conv" 514 | convolution_param { 515 | num_output: 16 516 | pad: 1 517 | kernel_size: 3 518 | stride: 1 519 | } 520 | } 521 | layer { 522 | name: "loc_4_conv" 523 | type: "Convolution" 524 | bottom: "loc_4_insert_conv2d" 525 | top: "loc_4_conv" 526 | convolution_param { 527 | num_output: 16 528 | pad: 1 529 | kernel_size: 3 530 | stride: 1 531 | } 532 | } 533 | layer { 534 | name: "cls_0_conv_permute" 535 | type: "Permute" 536 | bottom: "cls_0_conv" 537 | top: "cls_0_conv_permute" 538 | permute_param { 539 | order: 0 540 | order: 2 541 | order: 3 542 | order: 1 543 | } 544 | } 545 | layer { 546 | name: "cls_0_reshape" 547 | type: "Reshape" 548 | bottom: "cls_0_conv_permute" 549 | top: "cls_0_reshape" 550 | reshape_param { 551 | shape { 552 | dim: 0 553 | dim: -1 554 | dim: 2 555 | } 556 | } 557 | } 558 | layer { 559 | name: "cls_1_conv_permute" 560 | type: "Permute" 561 | bottom: "cls_1_conv" 562 | top: "cls_1_conv_permute" 563 | permute_param { 564 | order: 0 565 | order: 2 566 | order: 3 567 | order: 1 568 | } 569 | } 570 | layer { 571 | name: "cls_1_reshape" 572 | type: "Reshape" 573 | bottom: "cls_1_conv_permute" 574 | top: "cls_1_reshape" 575 | reshape_param { 576 | shape { 577 | dim: 0 578 | dim: -1 579 | dim: 2 580 | } 581 | } 582 | } 583 | layer { 584 | name: "cls_2_conv_permute" 585 | type: "Permute" 586 | bottom: "cls_2_conv" 587 | top: "cls_2_conv_permute" 588 | permute_param { 589 | order: 0 590 | order: 2 591 | order: 3 592 | order: 1 593 | } 594 | } 595 | layer { 596 | name: "cls_2_reshape" 597 | type: "Reshape" 598 | bottom: "cls_2_conv_permute" 599 | top: "cls_2_reshape" 600 | reshape_param { 601 | shape { 602 | dim: 0 603 | dim: -1 604 | dim: 2 605 | } 606 | } 607 | } 608 | layer { 609 | name: "cls_3_conv_permute" 610 | type: "Permute" 611 | bottom: "cls_3_conv" 612 | top: "cls_3_conv_permute" 613 | permute_param { 614 | order: 0 615 | order: 2 616 | order: 3 617 | order: 1 618 | } 619 | } 620 | layer { 621 | name: "cls_3_reshape" 622 | type: "Reshape" 623 | bottom: "cls_3_conv_permute" 624 | top: "cls_3_reshape" 625 | reshape_param { 626 | shape { 627 | dim: 0 628 | dim: -1 629 | dim: 2 630 | } 631 | } 632 | } 633 | layer { 634 | name: "cls_4_conv_permute" 635 | type: "Permute" 636 | bottom: "cls_4_conv" 637 | top: "cls_4_conv_permute" 638 | permute_param { 639 | order: 0 640 | order: 2 641 | order: 3 642 | order: 1 643 | } 644 | } 645 | layer { 646 | name: "cls_4_reshape" 647 | type: "Reshape" 648 | bottom: "cls_4_conv_permute" 649 | top: "cls_4_reshape" 650 | reshape_param { 651 | shape { 652 | dim: 0 653 | dim: -1 654 | dim: 2 655 | } 656 | } 657 | } 658 | layer { 659 | name: "loc_0_conv_permute" 660 | type: "Permute" 661 | bottom: "loc_0_conv" 662 | top: "loc_0_conv_permute" 663 | permute_param { 664 | order: 0 665 | order: 2 666 | order: 3 667 | order: 1 668 | } 669 | } 670 | layer { 671 | name: "loc_0_reshape" 672 | type: "Reshape" 673 | bottom: "loc_0_conv_permute" 674 | top: "loc_0_reshape" 675 | reshape_param { 676 | shape { 677 | dim: 0 678 | dim: -1 679 | dim: 4 680 | } 681 | } 682 | } 683 | layer { 684 | name: "loc_1_conv_permute" 685 | type: "Permute" 686 | bottom: "loc_1_conv" 687 | top: "loc_1_conv_permute" 688 | permute_param { 689 | order: 0 690 | order: 2 691 | order: 3 692 | order: 1 693 | } 694 | } 695 | layer { 696 | name: "loc_1_reshape" 697 | type: "Reshape" 698 | bottom: "loc_1_conv_permute" 699 | top: "loc_1_reshape" 700 | reshape_param { 701 | shape { 702 | dim: 0 703 | dim: -1 704 | dim: 4 705 | } 706 | } 707 | } 708 | layer { 709 | name: "loc_2_conv_permute" 710 | type: "Permute" 711 | bottom: "loc_2_conv" 712 | top: "loc_2_conv_permute" 713 | permute_param { 714 | order: 0 715 | order: 2 716 | order: 3 717 | order: 1 718 | } 719 | } 720 | layer { 721 | name: "loc_2_reshape" 722 | type: "Reshape" 723 | bottom: "loc_2_conv_permute" 724 | top: "loc_2_reshape" 725 | reshape_param { 726 | shape { 727 | dim: 0 728 | dim: -1 729 | dim: 4 730 | } 731 | } 732 | } 733 | layer { 734 | name: "loc_3_conv_permute" 735 | type: "Permute" 736 | bottom: "loc_3_conv" 737 | top: "loc_3_conv_permute" 738 | permute_param { 739 | order: 0 740 | order: 2 741 | order: 3 742 | order: 1 743 | } 744 | } 745 | layer { 746 | name: "loc_3_reshape" 747 | type: "Reshape" 748 | bottom: "loc_3_conv_permute" 749 | top: "loc_3_reshape" 750 | reshape_param { 751 | shape { 752 | dim: 0 753 | dim: -1 754 | dim: 4 755 | } 756 | } 757 | } 758 | layer { 759 | name: "loc_4_conv_permute" 760 | type: "Permute" 761 | bottom: "loc_4_conv" 762 | top: "loc_4_conv_permute" 763 | permute_param { 764 | order: 0 765 | order: 2 766 | order: 3 767 | order: 1 768 | } 769 | } 770 | layer { 771 | name: "loc_4_reshape" 772 | type: "Reshape" 773 | bottom: "loc_4_conv_permute" 774 | top: "loc_4_reshape" 775 | reshape_param { 776 | shape { 777 | dim: 0 778 | dim: -1 779 | dim: 4 780 | } 781 | } 782 | } 783 | layer { 784 | name: "cls_0_activation" 785 | type: "Sigmoid" 786 | bottom: "cls_0_reshape" 787 | top: "cls_0_reshape" 788 | } 789 | layer { 790 | name: "cls_1_activation" 791 | type: "Sigmoid" 792 | bottom: "cls_1_reshape" 793 | top: "cls_1_reshape" 794 | } 795 | layer { 796 | name: "cls_2_activation" 797 | type: "Sigmoid" 798 | bottom: "cls_2_reshape" 799 | top: "cls_2_reshape" 800 | } 801 | layer { 802 | name: "cls_3_activation" 803 | type: "Sigmoid" 804 | bottom: "cls_3_reshape" 805 | top: "cls_3_reshape" 806 | } 807 | layer { 808 | name: "cls_4_activation" 809 | type: "Sigmoid" 810 | bottom: "cls_4_reshape" 811 | top: "cls_4_reshape" 812 | } 813 | layer { 814 | name: "loc_branch_concat" 815 | type: "Concat" 816 | bottom: "loc_0_reshape" 817 | bottom: "loc_1_reshape" 818 | bottom: "loc_2_reshape" 819 | bottom: "loc_3_reshape" 820 | bottom: "loc_4_reshape" 821 | top: "loc_branch_concat" 822 | concat_param { 823 | axis: 1 824 | } 825 | } 826 | layer { 827 | name: "cls_branch_concat" 828 | type: "Concat" 829 | bottom: "cls_0_reshape" 830 | bottom: "cls_1_reshape" 831 | bottom: "cls_2_reshape" 832 | bottom: "cls_3_reshape" 833 | bottom: "cls_4_reshape" 834 | top: "cls_branch_concat" 835 | concat_param { 836 | axis: 1 837 | } 838 | } 839 | --------------------------------------------------------------------------------