Repository: opencv/opencv
File: modules/dnn/src/caffe/caffe_importer.cpp (C++)

Code before:
                            (!fd->is_repeated() && !fd->is_required() && msgRefl->HasField(msg, fd)) ||
                            (fd->is_repeated() && msgRefl->FieldSize(msg, fd) > 0) ||
                            !unknownFields.empty();
            if (!hasData)
                continue;

            extractCustomParams(unknownFields, params);
            if (fd->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE)
            {
                if (fd->is_repeated()) //Extract only first item!
                    extractLayerParams(msgRefl->GetRepeatedMessage(msg, fd, 0), params, true);
                else
                    extractLayerParams(msgRefl->GetMessage(msg, fd), params, true);
            }
            else
            {
                addParam(msg, fd, params);
            }
        }
    }

    template<class MSG>
    typename std::enable_if<!std::is_base_of<Message, MSG>::value, void>::type
    extractLayerParams(const MSG &msg, cv::dnn::LayerParams &params, bool isInternal = false)
    {
        // extractBinaryLayerParams will be called anyway.
    }

    void blobShapeFromProto(const caffe::BlobProto &pbBlob, MatShape& shape)
    {
        shape.clear();
        if (pbBlob.has_num() || pbBlob.has_channels() || pbBlob.has_height() || pbBlob.has_width())
        {
            shape.push_back(pbBlob.num());
            shape.push_back(pbBlob.channels());
            shape.push_back(pbBlob.height());
            shape.push_back(pbBlob.width());
        }
        else if (pbBlob.has_shape())
        {
            shape = parseBlobShape(pbBlob.shape());
        }
        else
            shape.resize(1, 1);  // Is a scalar.
    }

    template<class BLOB_PROTO>
    typename std::enable_if<std::is_base_of<Message, BLOB_PROTO>::value, void>::type
    AssertBlobProtoIsFloat(const BLOB_PROTO &pbBlob) {
      CV_DbgAssert(pbBlob.GetDescriptor()->FindFieldByLowercaseName("data")->cpp_type() == FieldDescriptor::CPPTYPE_FLOAT);
    }

Review comment (suggestion):
In case if it's just stub and should not be called, I propose to ad `CV_Error` to highlight issues.

Code after:
                            (!fd->is_repeated() && !fd->is_required() && msgRefl->HasField(msg, fd)) ||
                            (fd->is_repeated() && msgRefl->FieldSize(msg, fd) > 0) ||
                            !unknownFields.empty();
            if (!hasData)
                continue;

            extractCustomParams(unknownFields, params);
            if (fd->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE)
            {
                if (fd->is_repeated()) //Extract only first item!
                    extractLayerParams(msgRefl->GetRepeatedMessage(msg, fd, 0), params, true);
                else
                    extractLayerParams(msgRefl->GetMessage(msg, fd), params, true);
            }
            else
            {
                addParam(msg, fd, params);
            }
        }
    }

    template<class MSG>
    typename std::enable_if<!std::is_base_of<Message, MSG>::value, void>::type
    extractLayerParams(const MSG &msg, cv::dnn::LayerParams &params, bool isInternal = false)
    {
        CV_Error(Error::StsError, "DNN/CAFFE: do not have your message be a MessageLite");
    }

    void blobShapeFromProto(const caffe::BlobProto &pbBlob, MatShape& shape)
    {
        shape.clear();
        if (pbBlob.has_num() || pbBlob.has_channels() || pbBlob.has_height() || pbBlob.has_width())
        {
            shape.push_back(pbBlob.num());
            shape.push_back(pbBlob.channels());
            shape.push_back(pbBlob.height());
            shape.push_back(pbBlob.width());
        }
        else if (pbBlob.has_shape())
        {
            shape = parseBlobShape(pbBlob.shape());
        }
        else
            shape.resize(1, 1);  // Is a scalar.
    }

    template<class BLOB_PROTO>
    typename std::enable_if<std::is_base_of<Message, BLOB_PROTO>::value, void>::type
    AssertBlobProtoIsFloat(const BLOB_PROTO &pbBlob) {
        CV_DbgAssert(pbBlob.GetDescriptor()->FindFieldByLowercaseName("data")->cpp_type() == FieldDescriptor::CPPTYPE_FLOAT);
    }