Merge pull request #20999 from alalek:dnn_replace_deprecated_calls

dnn(protobuf): replace deprecated calls

* dnn: replace deprecated ByteSize() => ByteSizeLong()

* dnn: replace deprecated calls, use GetRepeatedFieldRef
pull/21013/head^2
Alexander Alekhin 3 years ago committed by GitHub
parent 85fd8729ce
commit d484939c02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      modules/dnn/src/caffe/caffe_importer.cpp
  2. 20
      modules/dnn/src/tensorflow/tf_importer.cpp

@ -49,6 +49,7 @@
#include <google/protobuf/message.h>
#include <google/protobuf/text_format.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/reflection.h>
#include "caffe_io.hpp"
#endif
@ -57,8 +58,7 @@ namespace dnn {
CV__DNN_EXPERIMENTAL_NS_BEGIN
#ifdef HAVE_PROTOBUF
using ::google::protobuf::RepeatedField;
using ::google::protobuf::RepeatedPtrField;
using ::google::protobuf::RepeatedFieldRef;
using ::google::protobuf::Message;
using ::google::protobuf::Descriptor;
using ::google::protobuf::FieldDescriptor;
@ -136,7 +136,7 @@ public:
#define SET_UP_FILED(getter, arrayConstr, gtype) \
if (isRepeated) { \
const RepeatedField<gtype> &v = refl->GetRepeatedField<gtype>(msg, field); \
const RepeatedFieldRef<gtype> v = refl->GetRepeatedFieldRef<gtype>(msg, field); \
params.set(name, DictValue::arrayConstr(v.begin(), (int)v.size())); \
} \
else { \
@ -168,7 +168,7 @@ public:
break;
case FieldDescriptor::CPPTYPE_STRING:
if (isRepeated) {
const RepeatedPtrField<std::string> &v = refl->GetRepeatedPtrField<std::string>(msg, field);
const RepeatedFieldRef<std::string> v = refl->GetRepeatedFieldRef<std::string>(msg, field);
params.set(name, DictValue::arrayString(v.begin(), (int)v.size()));
}
else {

@ -2739,14 +2739,21 @@ DataLayout TFImporter::predictOutputDataLayout(const tensorflow::NodeDef& layer)
void TFImporter::populateNet()
{
CV_Assert(netBin.ByteSize() || netTxt.ByteSize());
#if GOOGLE_PROTOBUF_VERSION < 3005000
size_t netBinSize = saturate_cast<size_t>(netBin.ByteSize());
size_t netTxtSize = saturate_cast<size_t>(netTxt.ByteSize());
#else
size_t netBinSize = netBin.ByteSizeLong();
size_t netTxtSize = netTxt.ByteSizeLong();
#endif
CV_Assert(netBinSize || netTxtSize);
CV_LOG_INFO(NULL, "DNN/TF: parsing model"
<< (netBin.has_versions() ? cv::format(" produced by TF v%d (min_consumer=%d)", (int)netBin.versions().producer(), (int)netBin.versions().min_consumer()) : cv::String(" (N/A version info)"))
<< ". Number of nodes = " << netBin.node_size()
);
if (netTxt.ByteSize())
if (netTxtSize)
{
CV_LOG_INFO(NULL, "DNN/TF: parsing config"
<< (netTxt.has_versions() ? cv::format(" produced by TF v%d (min_consumer=%d)", (int)netTxt.versions().producer(), (int)netTxt.versions().min_consumer()) : cv::String(" (N/A version info)"))
@ -2775,7 +2782,7 @@ void TFImporter::populateNet()
CV_LOG_DEBUG(NULL, "DNN/TF: sortByExecutionOrder(model) => " << netBin.node_size() << " nodes");
}
tensorflow::GraphDef& net = netTxt.ByteSize() != 0 ? netTxt : netBin;
tensorflow::GraphDef& net = netTxtSize != 0 ? netTxt : netBin;
int layersSize = net.node_size();
@ -2873,7 +2880,12 @@ void TFImporter::addPermuteLayer(const int* order, const std::string& permName,
void TFImporter::parseNode(const tensorflow::NodeDef& layer)
{
tensorflow::GraphDef& net = netTxt.ByteSize() != 0 ? netTxt : netBin;
#if GOOGLE_PROTOBUF_VERSION < 3005000
size_t netTxtSize = saturate_cast<size_t>(netTxt.ByteSize());
#else
size_t netTxtSize = netTxt.ByteSizeLong();
#endif
tensorflow::GraphDef& net = netTxtSize != 0 ? netTxt : netBin;
const std::string& name = layer.name();
const std::string& type = layer.op();

Loading…
Cancel
Save