diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d407622ac..549fba3a4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -135,11 +135,8 @@ ncnn_add_layer(ExpandDims) ncnn_add_layer(Normalize) ncnn_add_layer(Permute) ncnn_add_layer(PriorBox) -ncnn_add_layer(ConcatV2) -ncnn_add_layer(SoftmaxV2) ncnn_add_layer(DetectionOutput) ncnn_add_layer(Interp) -ncnn_add_layer(DropoutV2) add_library(ncnn STATIC ${ncnn_SRCS}) diff --git a/src/layer/arm/softmax_arm.cpp b/src/layer/arm/softmax_arm.cpp index 09ed21a78..1340c7812 100644 --- a/src/layer/arm/softmax_arm.cpp +++ b/src/layer/arm/softmax_arm.cpp @@ -27,6 +27,9 @@ DEFINE_LAYER_CREATOR(Softmax_arm) int Softmax_arm::forward(const Mat& bottom_blob, Mat& top_blob) const { + if (axis != 0) + return Softmax::forward(bottom_blob, top_blob); + // value = exp( value - global max value ) // sum all value // value = value / sum @@ -156,6 +159,9 @@ int Softmax_arm::forward(const Mat& bottom_blob, Mat& top_blob) const int Softmax_arm::forward_inplace(Mat& bottom_top_blob) const { + if (axis != 0) + return Softmax::forward_inplace(bottom_top_blob); + // value = exp( value - global max value ) // sum all value // value = value / sum diff --git a/src/layer/concat.cpp b/src/layer/concat.cpp index 526d7a7ea..995688c28 100644 --- a/src/layer/concat.cpp +++ b/src/layer/concat.cpp @@ -20,13 +20,22 @@ DEFINE_LAYER_CREATOR(Concat) Concat::Concat() { + one_blob_only = false; + support_inplace = false; +} + +int Concat::load_param(const ParamDict& pd) +{ + axis = pd.get(0, 0); + + return 0; } int Concat::forward(const std::vector& bottom_blobs, std::vector& top_blobs) const { int dims = bottom_blobs[0].dims; - if (dims == 1) + if (dims == 1) // axis == 0 { // concat vector // total length @@ -61,7 +70,7 @@ int Concat::forward(const std::vector& bottom_blobs, std::vector& top_ return 0; } - if (dims == 2) + if (dims == 2 && axis == 0) { // concat image int w = bottom_blobs[0].w; @@ -98,38 +107,168 @@ int Concat::forward(const std::vector& bottom_blobs, std::vector& top_ return 0; } - int w = bottom_blobs[0].w; - int h = bottom_blobs[0].h; + if (dims == 2 && axis == 1) + { + // interleave image row + int h = bottom_blobs[0].h; + + // total width + int top_w = 0; + for (size_t b=0; b& bottom_blobs, std::vector& top_blobs) const; public: + int axis; }; } // namespace ncnn diff --git a/src/layer/concatv2.cpp b/src/layer/concatv2.cpp deleted file mode 100644 index 008e281e0..000000000 --- a/src/layer/concatv2.cpp +++ /dev/null @@ -1,277 +0,0 @@ -// Tencent is pleased to support the open source community by making ncnn available. -// -// Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. -// -// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except -// in compliance with the License. You may obtain a copy of the License at -// -// https://opensource.org/licenses/BSD-3-Clause -// -// Unless required by applicable law or agreed to in writing, software distributed -// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, either express or implied. See the License for the -// specific language governing permissions and limitations under the License. - -#include "concatv2.h" - -namespace ncnn { - -DEFINE_LAYER_CREATOR(ConcatV2) - -ConcatV2::ConcatV2() -{ - one_blob_only = false; - support_inplace = false; -} - -int ConcatV2::load_param(const ParamDict& pd) -{ - axis = pd.get(0, 0); - - return 0; -} - -int ConcatV2::forward(const std::vector& bottom_blobs, std::vector& top_blobs) const -{ - int dims = bottom_blobs[0].dims; - - if (dims == 1) // axis == 0 - { - // concat vector - // total length - int top_w = 0; - for (size_t b=0; b& bottom_blobs, std::vector& top_blobs) const; - -public: - int axis; -}; - -} // namespace ncnn - -#endif // LAYER_CONCATV2_H diff --git a/src/layer/dropout.cpp b/src/layer/dropout.cpp index d5faff336..72db4756c 100644 --- a/src/layer/dropout.cpp +++ b/src/layer/dropout.cpp @@ -24,14 +24,68 @@ Dropout::Dropout() support_inplace = true; } +int Dropout::load_param(const ParamDict& pd) +{ + scale = pd.get(0, 1.f); + + return 0; +} + int Dropout::forward(const Mat& bottom_blob, Mat& top_blob) const { - top_blob = bottom_blob; + if (scale == 1.f) + { + top_blob = bottom_blob; + return 0; + } + + int w = bottom_blob.w; + int h = bottom_blob.h; + int channels = bottom_blob.c; + int size = w * h; + + top_blob.create(w, h, channels); + if (top_blob.empty()) + return -100; + + #pragma omp parallel for + for (int q=0; q -#include -#include - -namespace ncnn { - -DEFINE_LAYER_CREATOR(SoftmaxV2) - -SoftmaxV2::SoftmaxV2() -{ - one_blob_only = true; - support_inplace = false; -} - -int SoftmaxV2::load_param(const ParamDict& pd) -{ - axis = pd.get(0, 0); - - return 0; -} - -int SoftmaxV2::forward(const Mat& bottom_blob, Mat& top_blob) const -{ - // value = exp( value - global max value ) - // sum all value - // value = value / sum - - if (axis == 0) - { - int w = bottom_blob.w; - int h = bottom_blob.h; - int channels = bottom_blob.c; - int size = w * h; - - top_blob.create(w, h, channels); - if (top_blob.empty()) - return -100; - - Mat max; - max.create(w, h); - if (max.empty()) - return -100; - max.fill(-FLT_MAX); - for (int q=0; q= 1 ? concat_param.axis() - 1 : 0; - fprintf(pp, " 0=%d", dim); - } + int dim = concat_param.axis() - 1; + fprintf(pp, " 0=%d", dim); } else if (layer.type() == "Convolution") { @@ -604,11 +577,8 @@ int main(int argc, char** argv) else if (layer.type() == "Dropout") { const caffe::DropoutParameter& dropout_param = layer.dropout_param(); - if (!dropout_param.scale_train()) - { - float scale = 1.f - dropout_param.dropout_ratio(); - fprintf(pp, " 0=%f", scale); - } + float scale = 1.f - dropout_param.dropout_ratio(); + fprintf(pp, " 0=%f", scale); } else if (layer.type() == "Eltwise") { @@ -1013,11 +983,8 @@ int main(int argc, char** argv) else if (layer.type() == "Softmax") { const caffe::SoftmaxParameter& softmax_param = layer.softmax_param(); - if (softmax_param.axis() != 1) - { - int dim = softmax_param.axis() >= 1 ? softmax_param.axis() - 1 : 0; - fprintf(pp, " 0=%d", dim); - } + int dim = softmax_param.axis() - 1; + fprintf(pp, " 0=%d", dim); } else if (layer.type() == "Threshold") {