mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
slope fix
This commit is contained in:
@@ -1123,6 +1123,8 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
{
|
||||
public:
|
||||
static Ptr<Layer> create(const LayerParams& params);
|
||||
// Set the per-channel slope when it arrives as a second input, not a blob.
|
||||
virtual void setSlope(const Mat& /*slope*/) {}
|
||||
};
|
||||
|
||||
class CV_EXPORTS ELULayer : public ActivationLayer
|
||||
|
||||
@@ -68,6 +68,7 @@ struct ConstArgs
|
||||
Conv2Layer* conv = dynamic_cast<Conv2Layer*>(layer_ptr);
|
||||
ConvTranspose2Layer* deconv = dynamic_cast<ConvTranspose2Layer*>(layer_ptr);
|
||||
BatchNorm2Layer* bn = dynamic_cast<BatchNorm2Layer*>(layer_ptr);
|
||||
ChannelsPReLULayer* prelu = dynamic_cast<ChannelsPReLULayer*>(layer_ptr);
|
||||
//ActivationLayer* activ = dynamic_cast<ActivationLayer*>(layer_ptr);
|
||||
|
||||
if (tail_const) {
|
||||
@@ -88,6 +89,10 @@ struct ConstArgs
|
||||
} else if (bn && bn->freezeScaleBias()) {
|
||||
// batch norm with constant parameters
|
||||
unuse_tail = true;
|
||||
} else if (prelu && ninputs == 2) {
|
||||
prelu->setSlope(netimpl->__tensors__[inputs[1].idx]);
|
||||
prelu->inputs.resize(1);
|
||||
unuse_tail = true;
|
||||
}/* else if (activ && dynamic_cast<ReLU6Layer>(activ)) {
|
||||
// [TODO] ...
|
||||
unuse_tail = true;
|
||||
|
||||
@@ -3742,6 +3742,14 @@ class ChannelsPReLUImpl CV_FINAL : public ElementWiseLayer<ChannelsPReLUFunctor>
|
||||
public:
|
||||
using ElementWiseLayer<ChannelsPReLUFunctor>::ElementWiseLayer;
|
||||
|
||||
void setSlope(const Mat& slope) CV_OVERRIDE
|
||||
{
|
||||
slope.reshape(1, (int)slope.total()).convertTo(func.scale, CV_32F);
|
||||
#ifdef HAVE_OPENCL
|
||||
func.scale_umat.release();
|
||||
#endif
|
||||
}
|
||||
|
||||
void forward(InputArrayOfArrays inputs_arr,
|
||||
OutputArrayOfArrays outputs_arr,
|
||||
OutputArrayOfArrays internals_arr) CV_OVERRIDE
|
||||
@@ -3849,6 +3857,13 @@ private:
|
||||
|
||||
Ptr<Layer> ChannelsPReLULayer::create(const LayerParams& params)
|
||||
{
|
||||
if (params.blobs.empty())
|
||||
{
|
||||
// Slope comes as a second input; constArgs() fills the scale in later.
|
||||
Ptr<ChannelsPReLUImpl> l(new ChannelsPReLUImpl(ChannelsPReLUFunctor()));
|
||||
l->setParamsFrom(params);
|
||||
return l;
|
||||
}
|
||||
CV_Assert(params.blobs.size() == 1);
|
||||
Mat scale = params.blobs[0];
|
||||
float slope = *scale.ptr<float>();
|
||||
|
||||
@@ -1458,9 +1458,17 @@ void ONNXImporter2::parsePRelu(LayerParams& layerParams, const opencv_onnx::Node
|
||||
{
|
||||
layerParams.type = "PReLU";
|
||||
CV_Assert(node_inputs.size() == 2);
|
||||
CV_Assert(net.isConstArg(node_inputs[1]));
|
||||
layerParams.blobs.push_back(net.argTensor(node_inputs[1]));
|
||||
addLayer(layerParams, node_proto, 1);
|
||||
if (net.isConstArg(node_inputs[1]))
|
||||
{
|
||||
layerParams.blobs.push_back(net.argTensor(node_inputs[1]));
|
||||
addLayer(layerParams, node_proto, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Slope produced by a foldable subgraph (e.g. Reshape of an initializer):
|
||||
// keep it as a second input for constFold()/constArgs() to resolve.
|
||||
addLayer(layerParams, node_proto);
|
||||
}
|
||||
}
|
||||
|
||||
void ONNXImporter2::parseLpNormalization(LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto)
|
||||
|
||||
Reference in New Issue
Block a user