TIML
 All Data Structures Files Functions Variables Enumerations Enumerator Groups Pages
timl.h
Go to the documentation of this file.
1 #ifndef TIML_H_
2 #define TIML_H_
3 
4 
5 /******************************************************************************/
10 /* Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  *
16  * Redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer.
18  *
19  * Redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the
22  * distribution.
23  *
24  * Neither the name of Texas Instruments Incorporated nor the names of
25  * its contributors may be used to endorse or promote products derived
26  * from this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  ******************************************************************************/
41 
42 
43 /*******************************************************************************
44  *
45  * INCLUDES
46  *
47  ******************************************************************************/
48 
49 #include "timlUtil.h"
50 #include "timlCNN.h"
51 
52 
53 /*******************************************************************************
54  *
55  * DEFINITIONS
56  *
57  ******************************************************************************/
58 
59 #define TIML_CPU
60 #ifndef TIML_CPU
61 #define TIML_ALT
62 #endif
63 
64 
65 /*******************************************************************************
66  *
67  * CNN PUBLIC FUNCTION PROTOTYPES
68  *
69  ******************************************************************************/
70 
72 
73 
74 
75 /*******************************************************************************
76  *
77  * DEFAULT PARAMS FUNCTIONS
78  *
79  ******************************************************************************/
80 
82 
84 
86 
88 
90 
92 
94 
95 
96 /*******************************************************************************
97  *
98  * CNN SETUP FUNCTIONS
99  *
100  ******************************************************************************/
101 
103 
104 int timlCNNAddInputLayer(timlConvNeuralNetwork *cnn, int featureMapRow, int featureMapCol, int featureMapChannel, timlCNNInputParams params);
105 
106 int timlCNNAddPoolingLayer(timlConvNeuralNetwork *cnn, int scaleRow, int scaleCol, int strideX, int strideY, timlCNNPoolingType type, timlCNNPoolingParams params);
107 
109 
110 int timlCNNAddConvLayer(timlConvNeuralNetwork *cnn, int kernelRow, int kernelCol, int strideX, int strideY, int featureMapChannel, timlCNNConvParams params);
111 
112 int timlCNNAddNonlinearLayer(timlConvNeuralNetwork *cnn, timlUtilActivationType type);
113 
115 
116 int timlCNNAddDropoutLayer(timlConvNeuralNetwork *cnn, float prob);
117 
119 
121 
123 
124 
125 /*******************************************************************************
126  *
127  * CNN TRAINING AND TESTING FUNCTIONS
128  *
129  ******************************************************************************/
130 
131 int timlCNNSupervisedTrainingWithLabelBatchMode(timlConvNeuralNetwork *cnn, float *data, int *label, int dim, int num);
132 
133 int timlCNNClassifyTopNBatchMode(timlConvNeuralNetwork *cnn, float *data, int dim, int num, int *label, float *percent, int topN);
134 
135 int timlCNNClassifyTop1SingleMode(timlConvNeuralNetwork *cnn, float *data, int dim);
136 
137 int timlCNNSetMode(timlConvNeuralNetwork *cnn, timlUtilPhase phase);
138 
139 
140 /*******************************************************************************
141  *
142  * CNN AUX FUNCTIONS
143  *
144  ******************************************************************************/
145 
147 
149 
151 
153 
154 int timlCNNWriteToFile(const char * fileName, timlConvNeuralNetwork *cnn, timlUtilParamsLevel paramsLevel, const char* name, const char *floatFormat, const char *intFormat);
155 
156 timlConvNeuralNetwork* timlCNNReadFromFile(const char * fileName, int deviceId);
157 
159 
160 int timlCNNProfile(timlConvNeuralNetwork *cnn, float *data, int dim, int num, int *label, int iter);
161 
162 int timlCNNResize(timlConvNeuralNetwork *cnn, int row, int col, int channel);
163 
165 
166 int timlCNNResize(timlConvNeuralNetwork *cnn, int row, int col, int channel);
167 
169 #endif
timlCNNPoolingParams timlCNNPoolingParamsDefault()
Return the default parameters for the pooling layer.
Definition: timlCNNPoolingParamsDefault.c:55
int timlCNNInitialize(timlConvNeuralNetwork *cnn)
Allocate the memory required by the cnn.
Definition: timlCNNInitialize.c:56
int timlCNNSetMode(timlConvNeuralNetwork *cnn, timlUtilPhase phase)
Set the phase (train/test) of the cnn.
Definition: timlCNNSetMode.c:56
timlCNNTrainingParams timlCNNTrainingParamsDefault()
Return the default training parameters.
Definition: timlCNNTrainingParamsDefault.c:55
timlConvNeuralNetwork * timlCNNCreateConvNeuralNetwork(timlCNNTrainingParams params, int deviceId)
Create a cnn structure.
Definition: timlCNNCreateConvNeuralNetwork.c:57
timlCNNNonlinearParams timlCNNNonlinearParamsDefault()
Return the default parameters for the nonlinear layer.
Definition: timlCNNNonlinearParamsDefault.c:55
timlUtilParamsLevel
Definition: timlUtil.h:132
int timlCNNClassifyTopNBatchMode(timlConvNeuralNetwork *cnn, float *data, int dim, int num, int *label, float *percent, int topN)
Batch classification.
Definition: timlCNNClassifyTopNBatchMode.c:62
Definition: timlCNN.h:193
Definition: timlCNN.h:257
Definition: timlCNN.h:132
timlConvNeuralNetwork * timlCNNShareParams(timlConvNeuralNetwork *cnn, int deviceId)
Create a new CNN that shares the parameters with the input CNN.
Definition: timlCNNShareParams.c:59
int timlCNNSupervisedTrainingWithLabelBatchMode(timlConvNeuralNetwork *cnn, float *data, int *label, int dim, int num)
Supervised training with label.
Definition: timlCNNSupervisedTrainingWithLabelBatchMode.c:60
int timlCNNAddConvLayer(timlConvNeuralNetwork *cnn, int kernelRow, int kernelCol, int strideX, int strideY, int featureMapChannel, timlCNNConvParams params)
Add conv layer.
Definition: timlCNNAddConvLayer.c:62
timlConvNeuralNetwork * timlCNNClone(timlConvNeuralNetwork *cnn, int deviceId)
Clone a cnn.
Definition: timlCNNClone.c:57
timlCNNNormParams timlCNNNormParamsDefault()
Return the default parameters for the norm layer.
Definition: timlCNNNormParamsDefault.c:55
Definition: timlCNN.h:244
int timlCNNGetLayerNum(timlConvNeuralNetwork *cnn)
Return the number of layers of the cnn.
Definition: timlCNNGetLayerNum.c:56
int timlCNNProfile(timlConvNeuralNetwork *cnn, float *data, int dim, int num, int *label, int iter)
Profile the CNN with both timing and memory allocation.
Definition: timlCNNProfile.c:61
Definition: timlCNN.h:158
int timlCNNAddPoolingLayer(timlConvNeuralNetwork *cnn, int scaleRow, int scaleCol, int strideX, int strideY, timlCNNPoolingType type, timlCNNPoolingParams params)
Add pooling layer.
Definition: timlCNNAddPoolingLayer.c:62
timlCNNConvParams timlCNNConvParamsDefault()
Return the default parameters for the convolutional layer.
Definition: timlCNNConvParamsDefault.c:55
timlConvNeuralNetwork * timlCNNReadFromFile(const char *fileName, int deviceId)
Read CNN from file(s)
Definition: timlCNNReadFromFile.c:57
int timlCNNAddLinearLayer(timlConvNeuralNetwork *cnn, int dim, timlCNNLinearParams params)
Add linear layer.
Definition: timlCNNAddLinearLayer.c:58
long timlCNNGetParamsNum(timlConvNeuralNetwork *cnn)
Get the number of parameters of the cnn.
Definition: timlCNNGetParamsNum.c:55
int timlCNNAddInputLayer(timlConvNeuralNetwork *cnn, int featureMapRow, int featureMapCol, int featureMapChannel, timlCNNInputParams params)
Add input layer.
Definition: timlCNNAddInputLayer.c:60
int timlCNNDelete(timlConvNeuralNetwork *cnn)
Free a cnn structure.
Definition: timlCNNDelete.c:56
int timlCNNAddNormLayer(timlConvNeuralNetwork *cnn, timlCNNNormParams params)
Add normalization layer.
Definition: timlCNNAddNormLayer.c:57
Definition: timlCNN.h:119
Definition: timlCNN.h:188
int timlCNNPrint(timlConvNeuralNetwork *cnn)
Print out the information of the cnn.
Definition: timlCNNPrint.c:56
int timlCNNResize(timlConvNeuralNetwork *cnn, int row, int col, int channel)
Resize the feature map sizes to accommodate new input feature map dimensions.
Definition: timlCNNResize.c:60
timlCNNLinearParams timlCNNLinearParamsDefault()
Return the default parameters for the linear layer.
Definition: timlCNNLinearParamsDefault.c:54
timlCNNInputParams timlCNNInputParamsDefault()
Return the default parameters for the input layer.
Definition: timlCNNInputParamsDefault.c:55
Definition: timlCNN.h:201
int timlCNNAddDropoutLayer(timlConvNeuralNetwork *cnn, float prob)
Add dropout layer.
Definition: timlCNNAddDropoutLayer.c:57
int timlCNNClassifyTop1SingleMode(timlConvNeuralNetwork *cnn, float *data, int dim)
Classify the data.
Definition: timlCNNClassifyTop1SingleMode.c:58
int timlCNNWriteToFile(const char *fileName, timlConvNeuralNetwork *cnn, timlUtilParamsLevel paramsLevel, const char *name, const char *floatFormat, const char *intFormat)
Write the cnn to file(s)
Definition: timlCNNWriteToFile.c:61
int timlCNNReset(timlConvNeuralNetwork *cnn)
Reset the parameters of the CNN.
Definition: timlCNNReset.c:56
long timlCNNMemory(timlConvNeuralNetwork *cnn)
Return the memory in bytes required by the cnn.
Definition: timlCNNMemory.c:56
int timlCNNAddNonlinearLayer(timlConvNeuralNetwork *cnn, timlUtilActivationType type)
Add nonlinear layer.
Definition: timlCNNAddNonlinearLayer.c:57