[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/pythonmjs/opencv/master/modules/dnn/test/test_halide_layers.cpp [Back]  [Original]

// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2017, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.

// This tests doesn't require any external data. They just compare outputs of
// layers using different computation backends. Input and parameters are random.

#include "test_precomp.hpp"

namespace opencv_test { namespace {

using namespace cv;
using namespace cv::dnn;
using namespace testing;

static void test(Mat& input, Net& net, int backendId, int targetId)
{
    DNNTestLayer::checkBackend(backendId, targetId);
    randu(input, -1.0f, 1.0f);

    net.setInput(input);
    net.setPreferableBackend(DNN_BACKEND_OPENCV);
    Mat outputDefault = net.forward().clone();

    net.setPreferableBackend(backendId);
    net.setPreferableTarget(targetId);
    Mat outputHalide = net.forward().clone();

    double l1, lInf;
    DNNTestLayer::getDefaultThresholds(backendId, targetId, &l1, &lInf);
    normAssert(outputDefault, outputHalide, "", l1, lInf);
}

static void test(LayerParams& params, Mat& input, int backendId, int targetId)
{
    Net net;
    net.addLayerToPrev(params.name, params.type, params);
    test(input, net, backendId, targetId);
}

static testing::internal::ParamGenerator dnnBackendsAndTargetsWithHalide()
{
    static const tuple testCases[] = {
#ifdef HAVE_HALIDE
        tuple(DNN_BACKEND_HALIDE, DNN_TARGET_CPU),
        tuple(DNN_BACKEND_HALIDE, DNN_TARGET_OPENCL),
#endif
#ifdef HAVE_INF_ENGINE
        tuple(DNN_BACKEND_INFERENCE_ENGINE, DNN_TARGET_CPU),
        tuple(DNN_BACKEND_INFERENCE_ENGINE, DNN_TARGET_OPENCL),
        tuple(DNN_BACKEND_INFERENCE_ENGINE, DNN_TARGET_OPENCL_FP16),
        tuple(DNN_BACKEND_INFERENCE_ENGINE, DNN_TARGET_MYRIAD),
#endif
        tuple(DNN_BACKEND_OPENCV, DNN_TARGET_OPENCL),
        tuple(DNN_BACKEND_OPENCV, DNN_TARGET_OPENCL_FP16)
    };
    return testing::ValuesIn(testCases);
}

class Test_Halide_layers : public DNNTestLayer {};

////////////////////////////////////////////////////////////////////////////////
// Padding
////////////////////////////////////////////////////////////////////////////////
TEST_P(Test_Halide_layers, Padding)
{
    static const int kNumRuns = 10;
    std::vector paddings(8);
    cv::RNG& rng = cv::theRNG();
    for (int t = 0; t < kNumRuns; ++t)
    {
        for (int i = 0; i < paddings.size(); ++i)
            paddings[i] = rng(5);

        LayerParams lp;
        lp.set("paddings", DictValue::arrayInt(&paddings[0], paddings.size()));
        lp.type = "Padding";
        lp.name = "testLayer";

        int sz[] = {1 + (int)rng(10), 1 + (int)rng(10), 1 + (int)rng(10), 1 + (int)rng(10)};
        Mat input(4, &sz[0], CV_32F);
        test(lp, input, backend, target);
    }
}

////////////////////////////////////////////////////////////////////////////////
// Convolution
////////////////////////////////////////////////////////////////////////////////
typedef TestWithParam Convolution;
TEST_P(Convolution, Accuracy)
{
    int inChannels = get(GetParam())[0];
    int outChannels = get(GetParam())[1];
    int group = get(GetParam())[2];
    Size inSize = get(GetParam());
    Size kernel = get(GetParam());
    Size stride = get(GetParam());
    Size pad = get(GetParam());
    Size dilation = get(GetParam());
    bool hasBias = get(GetParam());
    int backendId = get(get(GetParam()));
    int targetId = get(get(GetParam()));

    if (backendId == DNN_BACKEND_INFERENCE_ENGINE && targetId == DNN_TARGET_MYRIAD)
        throw SkipTestException("");

    // TODO: unstable test cases
    if (backendId == DNN_BACKEND_OPENCV && (targetId == DNN_TARGET_OPENCL || targetId == DNN_TARGET_OPENCL_FP16) &&
        inChannels == 6 && outChannels == 9 && group == 1 && inSize == Size(5, 6) &&
        kernel == Size(3, 1) && stride == Size(1, 1) && pad == Size(0, 1) && dilation == Size(1, 1) &&
        hasBias)
        throw SkipTestException("");

    int sz[] = {outChannels, inChannels / group, kernel.height, kernel.width};
    Mat weights(4, &sz[0], CV_32F);
    randu(weights, -1.0f, 1.0f);

    LayerParams lp;
    lp.set("kernel_w", kernel.width);
    lp.set("kernel_h", kernel.height);
    lp.set("pad_w", pad.width);
    lp.set("pad_h", pad.height);
    lp.set("stride_w", stride.width);
    lp.set("stride_h", stride.height);
    lp.set("dilation_w", dilation.width);
    lp.set("dilation_h", dilation.height);
    lp.set("num_output", outChannels);
    lp.set("group", group);
    lp.set("bias_term", hasBias);
    lp.type = "Convolution";
    lp.name = "testLayer";
    lp.blobs.push_back(weights);
    if (hasBias)
    {
        Mat bias(1, outChannels, CV_32F);
        randu(bias, -1.0f, 1.0f);
        lp.blobs.push_back(bias);
    }
    int inpSz[] = {1, inChannels, inSize.height, inSize.width};
    Mat input(4, &inpSz[0], CV_32F);
    test(lp, input, backendId, targetId);
}

INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, Convolution, Combine(
/*in channels, out channels, group*/
             Values(Vec3i(6, 4, 1), Vec3i(6, 9, 1),
                    Vec3i(6, 4, 2), Vec3i(6, 9, 3)),
/*in size*/  Values(Size(5, 6)),
/*kernel*/   Values(Size(3, 1), Size(1, 3)),
/*stride*/   Values(Size(1, 1), Size(2, 2)),
/*pad*/      Values(Size(1, 0), Size(0, 1)),
/*dilation*/ Values(Size(1, 1), Size(2, 2)),
/*has bias*/ Bool(),
             dnnBackendsAndTargetsWithHalide()
));

////////////////////////////////////////////////////////////////////////////////
// Deconvolution
////////////////////////////////////////////////////////////////////////////////
typedef TestWithParam Deconvolution;
TEST_P(Deconvolution, Accuracy)
{
    int inChannels = get(GetParam())[0];
    int outChannels = get(GetParam())[1];
    int group = get(GetParam())[2];
    Size inSize = get(GetParam());
    Size kernel = get(GetParam());
    Size pad = get(GetParam());
    Size dilation = get(GetParam());
    Size stride = Size(get(GetParam())[0], get(GetParam())[1]);
    Size adjPad = Size(get(GetParam())[2], get(GetParam())[3]);
    bool hasBias = get(GetParam());
    int backendId = get(get(GetParam()));
    int targetId = get(get(GetParam()));
    if (backendId == DNN_BACKEND_INFERENCE_ENGINE && targetId == DNN_TARGET_CPU &&
        dilation.width == 2 && dilation.height == 2)
        throw SkipTestException("");

    int sz[] = {inChannels, outChannels / group, kernel.height, kernel.width};
    Mat weights(4, &sz[0], CV_32F);
    randu(weights, -1.0f, 1.0f);

    LayerParams lp;
    lp.set("kernel_w", kernel.width);
    lp.set("kernel_h", kernel.height);
    lp.set("pad_w", pad.width);
    lp.set("pad_h", pad.height);
    lp.set("stride_w", stride.width);
    lp.set("stride_h", stride.height);
    lp.set("dilation_w", dilation.width);
    lp.set("dilation_h", dilation.height);
    lp.set("adj_w", adjPad.width);
    lp.set("adj_h", adjPad.height);
    lp.set("num_output", outChannels);
    lp.set("group", group);
    lp.set("bias_term", hasBias);
    lp.type = "Deconvolution";
    lp.name = "testLayer";
    lp.blobs.push_back(weights);
    if (hasBias)
    {
        Mat bias(1, outChannels, CV_32F);
        randu(bias, -1.0f, 1.0f);
        lp.blobs.push_back(bias);
    }
    int inpSz[] = {1, inChannels, inSize.height, inSize.width};
    Mat input(4, &inpSz[0], CV_32F);
    test(lp, input, backendId, targetId);
}

INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, Deconvolution, Combine(
/*in channels, out channels, group*/
             Values(Vec3i(6, 4, 1), Vec3i(6, 9, 3)),
/*in size*/  Values(Size(5, 6)),
/*kernel*/   Values(Size(3, 1), Size(1, 3)),
/*pad*/      Values(Size(1, 0), Size(0, 1)),
/*dilation*/ Values(Size(1, 1), Size(2, 2)),
/*stride, adj. pad*/ Values(Vec4i(1,1, 0,0), Vec4i(2,2, 1,0), Vec4i(1,2, 0,1)),
/*has bias*/ Bool(),
             dnnBackendsAndTargetsWithHalide()
));

////////////////////////////////////////////////////////////////////////////////
// LRN
////////////////////////////////////////////////////////////////////////////////
typedef TestWithParam LRN;
TEST_P(LRN, Accuracy)
{
    int inChannels = get(GetParam())[0];
    Size inSize = Size(get(GetParam())[1], get(GetParam())[2]);
    int localSize = get(GetParam());
    float alpha = get(GetParam())[0];
    float beta = get(GetParam())[1];
    float bias = get(GetParam())[2];
    bool normBySize = get(GetParam());
    std::string nrmType = get(GetParam());
    int backendId = get(get(GetParam()));
    int targetId = get(get(GetParam()));
    if (backendId == DNN_BACKEND_INFERENCE_ENGINE)
        throw SkipTestException("");

    LayerParams lp;
    lp.set("norm_region", nrmType);
    lp.set("local_size", localSize);
    lp.set("alpha", alpha);
    lp.set("beta", beta);
    lp.set("bias", bias);
    lp.set("norm_by_size", normBySize);
    lp.type = "LRN";
    lp.name = "testLayer";

    int sz[] = {1, inChannels, inSize.height, inSize.width};
    Mat input(4, &sz[0], CV_32F);
    test(lp, input, backendId, targetId);
}

INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, LRN, Combine(
/*input ch,w,h*/ Values(Vec3i(6, 5, 8), Vec3i(7, 11, 6)),
/*local size*/   Values(3, 5),
                 Values(Vec3f(0.9f, 1.0f, 1.1f), Vec3f(0.9f, 1.1f, 1.0f),
/*alpha, beta,*/        Vec3f(1.0f, 0.9f, 1.1f), Vec3f(1.0f, 1.1f, 0.9f),
/*bias */               Vec3f(1.1f, 0.9f, 1.0f), Vec3f(1.1f, 1.0f, 0.9f)),
/*norm_by_size*/ Bool(),
/*norm_type*/    Values("ACROSS_CHANNELS", "WITHIN_CHANNEL"),
                 dnnBackendsAndTargetsWithHalide()
));

////////////////////////////////////////////////////////////////////////////////
// Average pooling
////////////////////////////////////////////////////////////////////////////////
typedef TestWithParam AvePooling;
TEST_P(AvePooling, Accuracy)
{
    int inChannels = get(GetParam());
    Size outSize = get(GetParam());;  // Input size will be computed from parameters.
    Size kernel = get(GetParam());
    Size stride = get(GetParam());
    int backendId = get(get(GetParam()));
    int targetId = get(get(GetParam()));
    if (backendId == DNN_BACKEND_INFERENCE_ENGINE && targetId == DNN_TARGET_MYRIAD)
        throw SkipTestException("");

    const int inWidth = (outSize.width - 1) * stride.width + kernel.width;
    const int inHeight = (outSize.height - 1) * stride.height + kernel.height;

    LayerParams lp;
    lp.set("pool", "ave");
    lp.set("kernel_w", kernel.width);
    lp.set("kernel_h", kernel.height);
    lp.set("stride_w", stride.width);
    lp.set("stride_h", stride.height);
    lp.type = "Pooling";
    lp.name = "testLayer";

    int sz[] = {1, inChannels, inHeight, inWidth};
    Mat input(4, &sz[0], CV_32F);
    test(lp, input, backendId, targetId);
}

INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, AvePooling, Combine(
/*in channels*/ Values(3, 4),
/*out size*/    Values(Size(1, 1), Size(2, 2), Size(3, 2), Size(4, 7)),
/*kernel*/      Values(Size(1, 1), Size(2, 2), Size(3, 3), Size(3, 2)),
/*stride*/      Values(Size(1, 1), Size(2, 2), Size(3, 2)),
                dnnBackendsAndTargetsWithHalide()
));

////////////////////////////////////////////////////////////////////////////////
// Maximum pooling
////////////////////////////////////////////////////////////////////////////////
typedef TestWithParam MaxPooling;
TEST_P(MaxPooling, Accuracy)
{
    int inChannels = get(GetParam());
    Size inSize = get(GetParam());
    Size kernel = get(GetParam());
    Size stride = get(GetParam());
    Size pad = get(GetParam());
    int backendId = get(get(GetParam()));
    int targetId = get(get(GetParam()));

    LayerParams lp;
    lp.set("pool", "max");
    lp.set("kernel_w", kernel.width);
    lp.set("kernel_h", kernel.height);
    lp.set("stride_w", stride.width);
    lp.set("stride_h", stride.height);
    lp.set("pad_w", pad.width);
    lp.set("pad_h", pad.height);
    lp.type = "Pooling";
    lp.name = "testLayer";

    int sz[] = {1, inChannels, inSize.height, inSize.width};
    Mat input(4, &sz[0], CV_32F);
    test(lp, input, backendId, targetId);
}

INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, MaxPooling, Combine(
/*in channels*/ Values(3, 4),
/*in size*/     Values(Size(5, 5), Size(7, 6)),
/*kernel*/      Values(Size(2, 2), Size(3, 3), Size(3, 2)),
/*stride*/      Values(Size(1, 1), Size(2, 2), Size(3, 2)),
/*pad*/         Values(Size(0, 0), Size(1, 1), Size(0, 1)),
                dnnBackendsAndTargetsWithHalide()
));

////////////////////////////////////////////////////////////////////////////////
// Fully-connected
////////////////////////////////////////////////////////////////////////////////
typedef TestWithParam FullyConnected;
TEST_P(FullyConnected, Accuracy)
{
    int inChannels = get(GetParam());
    Size inSize = get(GetParam());
    int outChannels = get(GetParam());
    bool hasBias = get(GetParam());
    int backendId = get(get(GetParam()));
    int targetId = get(get(GetParam()));
    if (backendId == DNN_BACKEND_INFERENCE_ENGINE)
        throw SkipTestException("");

    Mat weights(outChannels, inChannels * inSize.height * inSize.width, CV_32F);
    randu(weights, -1.0f, 1.0f);

    Mat bias(1, outChannels, CV_32F);
    randu(bias, -1.0f, 1.0f);

    LayerParams lp;
    lp.set("num_output", outChannels);
    lp.set("bias_term", hasBias);
    lp.blobs.push_back(weights);
    lp.blobs.push_back(bias);
    lp.type = "InnerProduct";
    lp.name = "testLayer";

    int sz[] = {1, inChannels, inSize.height, inSize.width};
    Mat input(4, &sz[0], CV_32F);
    test(lp, input, backendId, targetId);
}

INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, FullyConnected, Combine(
/*in channels*/  Values(3, 4),
/*in size*/      Values(Size(5, 4), Size(4, 5), Size(1, 1)),
/*out channels*/ Values(3, 4),
/*has bias*/     Bool(),
                 dnnBackendsAndTargetsWithHalide()
));

////////////////////////////////////////////////////////////////////////////////
// SoftMax
////////////////////////////////////////////////////////////////////////////////
typedef TestWithParam SoftMax;
TEST_P(SoftMax, Accuracy)
{
    int inChannels = get(GetParam());
    int backendId = get(get(GetParam()));
    int targetId = get(get(GetParam()));
    LayerParams lp;
    lp.type = "SoftMax";
    lp.name = "testLayer";

    int sz[] = {1, inChannels, 1, 1};
    Mat input(4, &sz[0], CV_32F);
    test(lp, input, backendId, targetId);
}

INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, SoftMax, Combine(
    Values(3, 4, 5, 1024),
    dnnBackendsAndTargetsWithHalide()
));

//////////////////////////////////////////////////////////////////////////////
// Max pooling - unpooling
//////////////////////////////////////////////////////////////////////////////
TEST_P(Test_Halide_layers, MaxPoolUnpool)
{
    if (backend == DNN_BACKEND_INFERENCE_ENGINE)
        throw SkipTestException("");

    LayerParams pool;
    pool.set("pool", "max");
    pool.set("kernel_w", 2);
    pool.set("kernel_h", 2);
    pool.set("stride_w", 2);
    pool.set("stride_h", 2);
    pool.set("pad_w", 0);
    pool.set("pad_h", 0);
    pool.type = "Pooling";
    pool.name = "testPool";

    LayerParams unpool;
    unpool.set("pool_k_w", 2);
    unpool.set("pool_k_h", 2);
    unpool.set("pool_stride_w", 2);
    unpool.set("pool_stride_h", 2);
    unpool.set("pool_pad_w", 0);
    unpool.set("pool_pad_h", 0);
    unpool.type = "MaxUnpool";
    unpool.name = "testUnpool";

    Net net;
    int poolId = net.addLayer(pool.name, pool.type, pool);
    net.connect(0, 0, poolId, 0);

    int unpoolId = net.addLayer(unpool.name, unpool.type, unpool);
    net.connect(poolId, 0, unpoolId, 0);
    net.connect(poolId, 1, unpoolId, 1);

    int sz[] = {1, 1, 4, 4};
    Mat input(4, &sz[0], CV_32F);
    test(input, net, backend, target);
}

////////////////////////////////////////////////////////////////////////////////
// AvePooling + in-place layers
////////////////////////////////////////////////////////////////////////////////
static const int kNumChannels = 3;

void testInPlaceActivation(LayerParams& lp, int backendId, int targetId)
{
    EXPECT_FALSE(lp.name.empty());

    LayerParams pool;
    pool.set("pool", "ave");
    pool.set("kernel_w", 2);
    pool.set("kernel_h", 2);
    pool.set("stride_w", 2);
    pool.set("stride_h", 2);
    pool.type = "Pooling";

    Net net;
    int poolId = net.addLayer(pool.name, pool.type, pool);
    net.connect(0, 0, poolId, 0);
    net.addLayerToPrev(lp.name, lp.type, lp);

    int sz[] = {1, kNumChannels, 10, 10};
    Mat input(4, &sz[0], CV_32F);
    test(input, net, backendId, targetId);
}

typedef TestWithParam BatchNorm;
TEST_P(BatchNorm, Accuracy)
{
    bool hasWeights = get(GetParam());
    bool hasBias = get(GetParam());
    float epsilon = get(GetParam());
    int backendId = get(get(GetParam()));
    int targetId = get(get(GetParam()));

    LayerParams lp;
    lp.set("has_weight", hasWeights);
    lp.set("has_bias", hasBias);
    lp.set("eps", epsilon);
    lp.type = "BatchNorm";
    lp.name = "testLayer";

    lp.blobs.reserve(4);
    for (int i = 0; i < 3; ++i)
        lp.blobs.push_back(Mat(1, kNumChannels, CV_32F));
    if (hasBias || hasWeights)
        lp.blobs.push_back(Mat(1, kNumChannels, CV_32F));

    for (int i = 0; i < lp.blobs.size(); ++i)
        randu(lp.blobs[i], 0.0f, 1.0f);

    testInPlaceActivation(lp, backendId, targetId);
}

INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, BatchNorm, Combine(
/*has weights*/ Bool(),
/*has bias*/    Bool(),
/*epsilon*/     Values(1e-3f, 1e-5f),
                dnnBackendsAndTargetsWithHalide()
));

typedef TestWithParam ReLU;
TEST_P(ReLU, Accuracy)
{
    float negativeSlope = get(GetParam());
    int backendId = get(get(GetParam()));
    int targetId = get(get(GetParam()));

    LayerParams lp;
    lp.set("negative_slope", negativeSlope);
    lp.type = "ReLU";
    lp.name = "testLayer";
    testInPlaceActivation(lp, backendId, targetId);
}

INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, ReLU, Combine(
/*negative slope*/ Values(2.0f, 0.3f, -0.1f, 0.0f),
                   dnnBackendsAndTargetsWithHalide()
));

typedef TestWithParam NoParamActivation;
TEST_P(NoParamActivation, Accuracy)
{
    int backendId = get(get(GetParam()));
    int targetId = get(get(GetParam()));

    LayerParams lp;
    lp.type = get(GetParam());
    lp.name = "testLayer";
    testInPlaceActivation(lp, backendId, targetId);
}
INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, NoParamActivation, Combine(
/*type*/ Values("TanH", "Sigmoid", "AbsVal", "BNLL"),
         dnnBackendsAndTargetsWithHalide()
));

typedef TestWithParam Power;
TEST_P(Power, Accuracy)
{
    float power = get(GetParam())[0];
    float scale = get(GetParam())[1];
    float shift = get(GetParam())[2];
    int backendId = get(get(GetParam()));
    int targetId = get(get(GetParam()));

    LayerParams lp;
    lp.set("power", power);
    lp.set("scale", scale);
    lp.set("shift", shift);
    lp.type = "Power";
    lp.name = "testLayer";
    testInPlaceActivation(lp, backendId, targetId);
}

INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, Power, Combine(
/*power, scale, shift*/ Values(Vec3f(0.9f, 1.0f, 1.1f), Vec3f(0.9f, 1.1f, 1.0f),
                               Vec3f(1.0f, 0.9f, 1.1f), Vec3f(1.0f, 1.1f, 0.9f),
                               Vec3f(1.1f, 0.9f, 1.0f), Vec3f(1.1f, 1.0f, 0.9f)),
                        dnnBackendsAndTargetsWithHalide()
));

TEST_P(Test_Halide_layers, ChannelsPReLU)
{
    LayerParams lp;
    lp.type = "ChannelsPReLU";
    lp.name = "testLayer";
    lp.blobs.push_back(Mat(1, kNumChannels, CV_32F));
    randu(lp.blobs[0], -1.0f, 1.0f);

    testInPlaceActivation(lp, backend, target);
}

typedef TestWithParam Scale;
TEST_P(Scale, Accuracy)
{
    bool hasBias = get(GetParam());
    int backendId = get(get(GetParam()));
    int targetId = get(get(GetParam()));

    LayerParams lp;
    lp.set("bias_term", hasBias);
    lp.type = "Scale";
    lp.name = "testLayer";
    lp.blobs.push_back(Mat(1, kNumChannels, CV_32F));
    randu(lp.blobs[0], -1.0f, 1.0f);
    if (hasBias)
    {
        lp.blobs.push_back(Mat(1, kNumChannels, CV_32F));
        randu(lp.blobs[1], -1.0f, 1.0f);
    }
    testInPlaceActivation(lp, backendId, targetId);
}

INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, Scale, Combine(
    Bool(),
    dnnBackendsAndTargetsWithHalide()
));

////////////////////////////////////////////////////////////////////////////////
// Concat layer
////////////////////////////////////////////////////////////////////////////////
//
// input --- conv --- concat --- output
//      `--- conv ----^ ^ ^
//      `---- ... ------' '
//      `-----------------'
typedef TestWithParam Concat;
TEST_P(Concat, Accuracy)
{
    Vec3i inSize = get(GetParam());
    Vec3i numChannels = get(GetParam());
    int backendId = get(get(GetParam()));
    int targetId = get(get(GetParam()));

    Net net;

    std::vector convLayerIds;
    convLayerIds.reserve(numChannels.channels);
    for (int i = 0, n = numChannels.channels; i < n; ++i)
    {
        if (!numChannels[i])
            break;

        int sz[] = {numChannels[i], inSize[0], 1, 1};
        Mat weights(4, &sz[0], CV_32F);
        randu(weights, -1.0f, 1.0f);

        LayerParams convParam;
        convParam.set("kernel_w", 1);
        convParam.set("kernel_h", 1);
        convParam.set("num_output", numChannels[i]);
        convParam.set("bias_term", false);
        convParam.type = "Convolution";
        std::ostringstream ss;
        ss 

Web Proxy Viewer  |  New URL  |  Original Page