本文整理汇总了C++中LayerParams类的典型用法代码示例。如果您正苦于以下问题:C++ LayerParams类的具体用法?C++ LayerParams怎么用?C++ LayerParams使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LayerParams类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
Ptr<Layer> createLayerFromCaffe<EltwiseLayer>(LayerParams& params)
{
EltwiseLayer::EltwiseOp op = EltwiseLayer::SUM;
if (params.has("operation"))
{
String operation = params.get<String>("operation").toLowerCase();
if (operation == "prod")
op = EltwiseLayer::PROD;
else if (operation == "sum")
op = EltwiseLayer::SUM;
else if (operation == "max")
op = EltwiseLayer::MAX;
else
CV_Error(cv::Error::StsBadArg, "Unknown operaticon type \"" + operation + "\"");
}
std::vector<int> coeffs;
if (params.has("coeff"))
{
DictValue paramCoeff = params.get("coeff");
coeffs.resize(paramCoeff.size(), 1);
for (int i = 0; i < paramCoeff.size(); i++)
{
coeffs[i] = paramCoeff.get<int>(i);
}
}
return Ptr<Layer>(EltwiseLayer::create(op, coeffs));
}
示例2: testInPlaceActivation
void testInPlaceActivation(LayerParams& lp)
{
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);
Mat input({1, kNumChannels, 10, 10}, CV_32F);
randu(input, -1.0f, 1.0f);
net.setInput(input);
Mat outputDefault = net.forward(lp.name).clone();
net.setInput(input);
net.setPreferableBackend(DNN_BACKEND_HALIDE);
Mat outputHalide = net.forward(lp.name).clone();
normAssert(outputDefault, outputHalide);
}
示例3: TEST_P
TEST_P(ReLU, Accuracy)
{
float negativeSlope = get<0>(GetParam());
LayerParams lp;
lp.set("negative_slope", negativeSlope);
lp.type = "ReLU";
lp.name = "testLayer";
testInPlaceActivation(lp);
}
示例4: ResizeNearestNeighborLayerImpl
ResizeNearestNeighborLayerImpl(const LayerParams& params)
{
setParamsFrom(params);
CV_Assert(params.has("width"), params.has("height"));
outWidth = params.get<float>("width");
outHeight = params.get<float>("height");
alignCorners = params.get<bool>("align_corners", false);
if (alignCorners)
CV_Error(Error::StsNotImplemented, "Nearest neighborhood resize with align_corners=true is not implemented");
}
示例5: isCeilMode
bool ONNXImporter::isCeilMode(const LayerParams& layerParams) {
if (!layerParams.has("pad_mode")) {
if (layerParams.has("pad_h")) {
return layerParams.get<int>("pad_h") != layerParams.get<int>("pad_b") ||
layerParams.get<int>("pad_w") != layerParams.get<int>("pad_r");
}
else
return false; // all pads == 0
}
return true;
}
示例6: getParameterDict
bool getParameterDict(const LayerParams ¶ms,
const std::string ¶meterName,
DictValue& result)
{
if (!params.has(parameterName))
{
return false;
}
result = params.get(parameterName);
return true;
}
示例7: Layer
ConvolutionLayer::ConvolutionLayer(LayerParams ¶ms) : Layer(params)
{
getKernelParams(params, kerH, kerW, padH, padW, strideH, strideW);
numOutput = params.get<int>("num_output");
bias = params.get<bool>("bias_term", true);
group = params.get<int>("group", 1);
CV_Assert(numOutput % group == 0);
CV_Assert(!bias || blobs.size() == 2);
CV_Assert( bias || blobs.size() == 1);
const Blob &wgtBlob = blobs[0];
CV_Assert(wgtBlob.dims() == 4 && wgtBlob.cols() == kerW && wgtBlob.rows() == kerH);
if (bias)
{
Blob &biasBlob = blobs[1];
CV_Assert(biasBlob.total() == (size_t)numOutput);
}
//TBD
useOpenCL = params.has("use_opencl");
#if HAVE_CBLAS
{
if (getBlasThreads() != cv::getThreadNum())
{
setBlasThreads(cv::getThreadNum());
}
}
#endif
}
示例8: sliceIndices
Ptr<Layer> createLayerFromCaffe<SliceLayer>(LayerParams& params)
{
int axis = params.get<int>("axis", 1);
if (!params.has("slice_point"))
{
return Ptr<Layer>(SliceLayer::create(axis));
}
else
{
const DictValue &indicesValue = params.get("slice_point");
std::vector<int> sliceIndices(indicesValue.size());
for (int i = 0; i < indicesValue.size(); i++)
sliceIndices[i] = indicesValue.get<int>(i);
return Ptr<Layer>(SliceLayer::create(axis, sliceIndices));
}
}
示例9: ReshapeLayerImpl
ReshapeLayerImpl(const LayerParams& params)
{
setParamsFrom(params);
int axis = params.get<int>("axis", 0);
int numAxes = params.get<int>("num_axes", -1);
CV_Assert(numAxes >= -1);
newShapeRange = (numAxes == -1) ? Range(axis, INT_MAX) : Range(axis, axis + numAxes);
newShapeDesc.clear();
if (params.has("dim"))
{
const DictValue ¶mShape = params.get("dim");
int i, dims = paramShape.size();
newShapeDesc.resize(dims);
for (i = 0; i < dims; i++)
newShapeDesc[i] = paramShape.get<int>(i);
}
}
示例10: TEST
////////////////////////////////////////////////////////////////////////////////
// Padding
////////////////////////////////////////////////////////////////////////////////
TEST(Padding_Halide, Accuracy)
{
static const int kNumRuns = 10;
std::vector<int> paddings(8);
for (int t = 0; t < kNumRuns; ++t)
{
for (int i = 0; i < paddings.size(); ++i)
paddings[i] = rand() % 5;
LayerParams lp;
lp.set("paddings", DictValue::arrayInt<int*>(&paddings[0], paddings.size()));
lp.type = "Padding";
lp.name = "testLayer";
Mat input({1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10, 1 + rand() % 10}, CV_32F);
test(lp, input);
}
}
示例11: PaddingLayerImpl
PaddingLayerImpl(const LayerParams ¶ms)
{
setParamsFrom(params);
paddingValue = params.get<float>("value", 0);
inputDims = params.get<int>("input_dims", -1);
paddingType = params.get<String>("type", "constant");
CV_Assert(params.has("paddings"));
const DictValue& paddingsParam = params.get("paddings");
CV_Assert((paddingsParam.size() & 1) == 0);
paddings.resize(paddingsParam.size() / 2);
for (int i = 0; i < paddings.size(); ++i)
{
paddings[i].first = paddingsParam.get<int>(i * 2); // Pad before.
paddings[i].second = paddingsParam.get<int>(i * 2 + 1); // Pad after.
CV_Assert(paddings[i].first >= 0, paddings[i].second >= 0);
}
}
示例12: CropLayerImpl
CropLayerImpl(const LayerParams& params)
{
setParamsFrom(params);
startAxis = params.get<int>("axis", 2);
const DictValue *paramOffset = params.ptr("offset");
if (paramOffset)
{
for (int i = 0; i < paramOffset->size(); i++)
offset.push_back(paramOffset->get<int>(i));
}
}
示例13: Range
Ptr<Layer> createLayerFromCaffe<ReshapeLayer>(LayerParams ¶ms)
{
int axis = params.get<int>("axis", 0);
int numAxes = params.get<int>("num_axes", -1);
bool enableReordering = params.get<bool>("reorder_dims", false);
CV_Assert(numAxes >= -1);
Range applyingRange = (numAxes == -1) ? Range(axis, INT_MAX) : Range(axis, axis + numAxes);
Shape newShape;
if (params.has("dim"))
{
const DictValue ¶mShape = params.get("dim");
newShape = Shape::all(paramShape.size());
for (int i = 0; i < paramShape.size(); i++)
newShape[i] = paramShape.get<int>(i);
}
else
newShape = Shape::all(0);
return Ptr<Layer>(ReshapeLayer::create(newShape, applyingRange, enableReordering));
}
示例14: SplitLayerImpl
SplitLayerImpl(const LayerParams ¶ms)
{
setParamsFrom(params);
//TODO: maybe "top_count" param is useless because it can be determined by output connections number
if (params.has("top_count"))
{
outputsCount = params.get<int>("top_count");
CV_Assert(outputsCount >= 0);
}
else
{
outputsCount = -1;
}
}
示例15:
Ptr<Layer> createLayerFromCaffe<CropLayer>(LayerParams& params)
{
int start_axis = params.get<int>("axis", 2);
DictValue *paramOffset = params.ptr("offset");
std::vector<int> offset;
if (paramOffset)
{
for (int i = 0; i < paramOffset->size(); i++)
offset.push_back(paramOffset->get<int>(i));
}
return Ptr<Layer>(CropLayer::create(start_axis, offset));
}