Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/dnn/src/tensorflow/tf_io.cpp
16345 views
1
// This file is part of OpenCV project.
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
// of this distribution and at http://opencv.org/license.html.
4
5
// Copyright (C) 2016, Intel Corporation, all rights reserved.
6
// Third party copyrights are property of their respective owners.
7
8
/*
9
Implementation of various functions which are related to Tensorflow models reading.
10
*/
11
12
#include "../precomp.hpp"
13
14
#ifdef HAVE_PROTOBUF
15
#include <google/protobuf/io/coded_stream.h>
16
#include <google/protobuf/io/zero_copy_stream_impl.h>
17
#include <google/protobuf/text_format.h>
18
19
#include <opencv2/core.hpp>
20
21
#include <map>
22
#include <string>
23
#include <fstream>
24
#include <vector>
25
26
#include "tf_io.hpp"
27
28
#include "../caffe/caffe_io.hpp"
29
#include "../caffe/glog_emulator.hpp"
30
31
namespace cv {
32
namespace dnn {
33
34
using std::string;
35
using std::map;
36
using namespace tensorflow;
37
using namespace ::google::protobuf;
38
using namespace ::google::protobuf::io;
39
40
const int kProtoReadBytesLimit = INT_MAX; // Max size of 2 GB minus 1 byte.
41
42
void ReadTFNetParamsFromBinaryFileOrDie(const char* param_file,
43
tensorflow::GraphDef* param) {
44
CHECK(ReadProtoFromBinaryFile(param_file, param))
45
<< "Failed to parse GraphDef file: " << param_file;
46
}
47
48
void ReadTFNetParamsFromBinaryBufferOrDie(const char* data, size_t len,
49
tensorflow::GraphDef* param) {
50
CHECK(ReadProtoFromBinaryBuffer(data, len, param))
51
<< "Failed to parse GraphDef buffer";
52
}
53
54
void ReadTFNetParamsFromTextFileOrDie(const char* param_file,
55
tensorflow::GraphDef* param) {
56
CHECK(ReadProtoFromTextFile(param_file, param))
57
<< "Failed to parse GraphDef file: " << param_file;
58
}
59
60
void ReadTFNetParamsFromTextBufferOrDie(const char* data, size_t len,
61
tensorflow::GraphDef* param) {
62
CHECK(ReadProtoFromTextBuffer(data, len, param))
63
<< "Failed to parse GraphDef buffer";
64
}
65
66
}
67
}
68
#endif
69
70