Path: blob/master/modules/dnn/src/darknet/darknet_io.hpp
16349 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11// (3-clause BSD License)12//13// Copyright (C) 2017, Intel Corporation, all rights reserved.14// Third party copyrights are property of their respective owners.15//16// Redistribution and use in source and binary forms, with or without modification,17// are permitted provided that the following conditions are met:18//19// * Redistributions of source code must retain the above copyright notice,20// this list of conditions and the following disclaimer.21//22// * Redistributions in binary form must reproduce the above copyright notice,23// this list of conditions and the following disclaimer in the documentation24// and/or other materials provided with the distribution.25//26// * Neither the names of the copyright holders nor the names of the contributors27// may be used to endorse or promote products derived from this software28// without specific prior written permission.29//30// This software is provided by the copyright holders and contributors "as is" and31// any express or implied warranties, including, but not limited to, the implied32// warranties of merchantability and fitness for a particular purpose are disclaimed.33// In no event shall copyright holders or contributors be liable for any direct,34// indirect, incidental, special, exemplary, or consequential damages35// (including, but not limited to, procurement of substitute goods or services;36// loss of use, data, or profits; or business interruption) however caused37// and on any theory of liability, whether in contract, strict liability,38// or tort (including negligence or otherwise) arising in any way out of39// the use of this software, even if advised of the possibility of such damage.40//41//M*/4243/*M///////////////////////////////////////////////////////////////////////////////////////44//MIT License45//46//Copyright (c) 2017 Joseph Redmon47//48//Permission is hereby granted, free of charge, to any person obtaining a copy49//of this software and associated documentation files (the "Software"), to deal50//in the Software without restriction, including without limitation the rights51//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell52//copies of the Software, and to permit persons to whom the Software is53//furnished to do so, subject to the following conditions:54//55//The above copyright notice and this permission notice shall be included in all56//copies or substantial portions of the Software.57//58//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR59//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,60//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE61//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER62//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,63//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE64//SOFTWARE.65//66//M*/6768#ifndef __OPENCV_DNN_DARKNET_IO_HPP__69#define __OPENCV_DNN_DARKNET_IO_HPP__7071#include <opencv2/dnn/dnn.hpp>7273namespace cv {74namespace dnn {75namespace darknet {7677class LayerParameter {78std::string layer_name, layer_type;79std::vector<std::string> bottom_indexes;80cv::dnn::LayerParams layerParams;81public:82friend class setLayersParams;83cv::dnn::LayerParams getLayerParams() const { return layerParams; }84std::string name() const { return layer_name; }85std::string type() const { return layer_type; }86int bottom_size() const { return bottom_indexes.size(); }87std::string bottom(const int index) const { return bottom_indexes.at(index); }88int top_size() const { return 1; }89std::string top(const int index) const { return layer_name; }90};9192class NetParameter {93public:94int width, height, channels;95std::vector<LayerParameter> layers;96std::vector<int> out_channels_vec;9798std::map<int, std::map<std::string, std::string> > layers_cfg;99std::map<std::string, std::string> net_cfg;100101NetParameter() : width(0), height(0), channels(0) {}102103int layer_size() const { return layers.size(); }104105int input_size() const { return 1; }106std::string input(const int index) const { return "data"; }107LayerParameter layer(const int index) const { return layers.at(index); }108};109}110111// Read parameters from a stream into a NetParameter message.112void ReadNetParamsFromCfgStreamOrDie(std::istream &ifile, darknet::NetParameter *net);113void ReadNetParamsFromBinaryStreamOrDie(std::istream &ifile, darknet::NetParameter *net);114}115}116#endif117118119