]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - tidl/tidl-api.git/blob - tidl_api/inc/configuration.h
Fix unique_ptr that holds an allocated array
[tidl/tidl-api.git] / tidl_api / inc / configuration.h
1 /******************************************************************************
2  * Copyright (c) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *      * Redistributions of source code must retain the above copyright
8  *        notice, this list of conditions and the following disclaimer.
9  *      * Redistributions in binary form must reproduce the above copyright
10  *        notice, this list of conditions and the following disclaimer in the
11  *        documentation and/or other materials provided with the distribution.
12  *      * Neither the name of Texas Instruments Incorporated nor the
13  *        names of its contributors may be used to endorse or promote products
14  *        derived from this software without specific prior written permission.
15  *
16  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26  *  THE POSSIBILITY OF SUCH DAMAGE.
27  *****************************************************************************/
29 #pragma once
31 //! @file configuration.h
33 #include <string>
34 #include <map>
35 #include <iostream>
37 namespace tidl {
39 /*! @class Configuration
40     @brief Specifies the configuration required for a network
42     The Configuration object is used to specify various parameters required
43     for network execution. Applications can directly initialize fields in an
44     instance of Configuration or use the ReadFromFile method to read the
45     configuration from a file.
46 */
48 class Configuration
49 {
50   public:
52     //! Number of frames of input data (can be 0 if data is not read from file)
53     int     numFrames;
55     //! Height of the input image. Used by the API, must be specified.
56     int     inHeight;
58     //! Width of the input image. Used by the API, must be specified.
59     int     inWidth;
61     //! Number of channels in the input frame (e.g. 3 for BGR)
62     //! Used by the API, must be specified.
63     int     inNumChannels;
65     //! @private
66     int     noZeroCoeffsPercentage;
68     //! Pre-processing type applied to the input frame
69     //! Specific to each network, can take values from 0 to 4, default is 0
70     //! 0 -> Caffe-Jacinto models
71     //! 1 -> Caffe models (SqueezeNet)
72     //! 2 -> TensorFlow (Inception, MobileNet)
73     //! 3 -> CIFAR 10
74     //! 4 -> JdetNet
75     int     preProcType;
77     //! Force to run all layers, regardless of layersGroupId partitioning
78     bool    runFullNet;
80     //! @brief Size of the device side network heap
81     //! This heap is used for allocating memory required to
82     //! run the network on the device. One per Execution Object.
83     size_t NETWORK_HEAP_SIZE;
85     //! @brief Size of the device side heap used for parameter data.
86     //! The size depends on the size of the parameter binary file. The
87     //! constructor for ``Configuration`` sets PARAM_HEAP_SIZE to 9MB.
88     //! There is one parameter heap for each instance of ``Executor`` .
89     size_t PARAM_HEAP_SIZE;
91     //! @brief Path to the input image file.
92     //! This field is not used by the TIDL API itself. It can be used by
93     //! applications to load an input image into a buffer. Can be empty if
94     //! the application uses frameworks such as OpenCV to read images. Refer
95     //! examples/test/main.cpp for usage.
96     std::string inData;
98     //! @brief Path to the output image file.
99     //! This field is not used by the TIDL API itself. It can be used by
100     //! applications to specify a name for the output file. Can be empty
101     //! if the application uses frameworks such as OpenCV to read images.
102     //! Refer examples/test/main.cpp for usage.
103     std::string outData;
105     //! Path to the TIDL network binary file.
106     //! Used by the API, must be specified.
107     std::string netBinFile;
109     //! Path to the TIDL parameter binary file
110     //! Used by the API, must be specified.
111     std::string paramsBinFile;
113     //! Map of layer index to layer group id. Used to override layer group
114     //! assigment for layers. Any layer not specified in this map will
115     //! retain its existing mapping.
116     std::map<int, int> layerIndex2LayerGroupId;
118     //! Enable tracing of output buffers associated with each layer
119     bool enableOutputTrace;
121     //! Debug - Generates a trace of host and device function calls
122     bool enableApiTrace;
124     //! Debug - Shows total size of PARAM and NETWORK heaps. Also shows bytes
125     //! available after all allocations. Can be used to adjust the heap
126     //! size.
127     bool showHeapStats;
129     //! Weight in percentage applied to previously processed input frame during
130     //! application startup (first 10 frames of input).
131     //!
132     //! TIDL maintains range statistics for previously processed frames.
133     //! It quantizes the current inference activations using these range
134     //! statistics from previous inputs (weighted average range). Therefore,
135     //! the results observed when the input is processed on the device will
136     //! not be identical to that observed during the import stage.
137     //! Parameters to control quantization:
138     //! @see quantHistoryParam1, quantHistoryParam2, quantMargin
139     int quantHistoryParam1;
141     //! Weight in percentage applied to previously processed input frames
142     //! after the first 10 input frames.
143     int quantHistoryParam2;
145     //! Margin added to the average in percentage.
146     int quantMargin;
148     //! Default constructor.
149     Configuration();
151     //! Validate the fields in the configuration object
152     bool Validate() const;
154     //! Debug - Print the configuration.
155     void Print(std::ostream& os = std::cout) const;
157     //! Read a configuration from the specified file and validate
158     bool ReadFromFile(const std::string& file_name);
160 };