Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/dnn/src/darknet/darknet_io.hpp
16349 views
1
/*M///////////////////////////////////////////////////////////////////////////////////////
2
//
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
//
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
8
//
9
//
10
// License Agreement
11
// For Open Source Computer Vision Library
12
// (3-clause BSD License)
13
//
14
// Copyright (C) 2017, Intel Corporation, all rights reserved.
15
// Third party copyrights are property of their respective owners.
16
//
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
19
//
20
// * Redistributions of source code must retain the above copyright notice,
21
// this list of conditions and the following disclaimer.
22
//
23
// * Redistributions in binary form must reproduce the above copyright notice,
24
// this list of conditions and the following disclaimer in the documentation
25
// and/or other materials provided with the distribution.
26
//
27
// * Neither the names of the copyright holders nor the names of the contributors
28
// may be used to endorse or promote products derived from this software
29
// without specific prior written permission.
30
//
31
// This software is provided by the copyright holders and contributors "as is" and
32
// any express or implied warranties, including, but not limited to, the implied
33
// warranties of merchantability and fitness for a particular purpose are disclaimed.
34
// In no event shall copyright holders or contributors be liable for any direct,
35
// indirect, incidental, special, exemplary, or consequential damages
36
// (including, but not limited to, procurement of substitute goods or services;
37
// loss of use, data, or profits; or business interruption) however caused
38
// and on any theory of liability, whether in contract, strict liability,
39
// or tort (including negligence or otherwise) arising in any way out of
40
// the use of this software, even if advised of the possibility of such damage.
41
//
42
//M*/
43
44
/*M///////////////////////////////////////////////////////////////////////////////////////
45
//MIT License
46
//
47
//Copyright (c) 2017 Joseph Redmon
48
//
49
//Permission is hereby granted, free of charge, to any person obtaining a copy
50
//of this software and associated documentation files (the "Software"), to deal
51
//in the Software without restriction, including without limitation the rights
52
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
53
//copies of the Software, and to permit persons to whom the Software is
54
//furnished to do so, subject to the following conditions:
55
//
56
//The above copyright notice and this permission notice shall be included in all
57
//copies or substantial portions of the Software.
58
//
59
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
62
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
63
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
64
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
65
//SOFTWARE.
66
//
67
//M*/
68
69
#ifndef __OPENCV_DNN_DARKNET_IO_HPP__
70
#define __OPENCV_DNN_DARKNET_IO_HPP__
71
72
#include <opencv2/dnn/dnn.hpp>
73
74
namespace cv {
75
namespace dnn {
76
namespace darknet {
77
78
class LayerParameter {
79
std::string layer_name, layer_type;
80
std::vector<std::string> bottom_indexes;
81
cv::dnn::LayerParams layerParams;
82
public:
83
friend class setLayersParams;
84
cv::dnn::LayerParams getLayerParams() const { return layerParams; }
85
std::string name() const { return layer_name; }
86
std::string type() const { return layer_type; }
87
int bottom_size() const { return bottom_indexes.size(); }
88
std::string bottom(const int index) const { return bottom_indexes.at(index); }
89
int top_size() const { return 1; }
90
std::string top(const int index) const { return layer_name; }
91
};
92
93
class NetParameter {
94
public:
95
int width, height, channels;
96
std::vector<LayerParameter> layers;
97
std::vector<int> out_channels_vec;
98
99
std::map<int, std::map<std::string, std::string> > layers_cfg;
100
std::map<std::string, std::string> net_cfg;
101
102
NetParameter() : width(0), height(0), channels(0) {}
103
104
int layer_size() const { return layers.size(); }
105
106
int input_size() const { return 1; }
107
std::string input(const int index) const { return "data"; }
108
LayerParameter layer(const int index) const { return layers.at(index); }
109
};
110
}
111
112
// Read parameters from a stream into a NetParameter message.
113
void ReadNetParamsFromCfgStreamOrDie(std::istream &ifile, darknet::NetParameter *net);
114
void ReadNetParamsFromBinaryStreamOrDie(std::istream &ifile, darknet::NetParameter *net);
115
}
116
}
117
#endif
118
119