1 /******************************************************************************/\r
2 /*!\r
3 * \file timlCNNFree.c\r
4 */\r
5 /* Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/\r
6 *\r
7 * Redistribution and use in source and binary forms, with or without\r
8 * modification, are permitted provided that the following conditions\r
9 * are met:\r
10 *\r
11 * Redistributions of source code must retain the above copyright\r
12 * notice, this list of conditions and the following disclaimer.\r
13 *\r
14 * Redistributions in binary form must reproduce the above copyright\r
15 * notice, this list of conditions and the following disclaimer in the\r
16 * documentation and/or other materials provided with the\r
17 * distribution.\r
18 *\r
19 * Neither the name of Texas Instruments Incorporated nor the names of\r
20 * its contributors may be used to endorse or promote products derived\r
21 * from this software without specific prior written permission.\r
22 *\r
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
34 *\r
35 ******************************************************************************/\r
36 \r
37 \r
38 /*******************************************************************************\r
39 *\r
40 * INCLUDES\r
41 *\r
42 ******************************************************************************/\r
43 \r
44 #include "../api/timl.h"\r
45 \r
46 \r
47 /******************************************************************************/\r
48 /*!\r
49 * \ingroup cnn\r
50 * \brief Free a cnn structure\r
51 * \param[in] cnn CNN structure\r
52 * \return Error code\r
53 */\r
54 /******************************************************************************/\r
55 \r
56 int timlCNNFree(timlConvNeuralNetwork *cnn)\r
57 {\r
58 int err;\r
59 timlCNNLayer *layer;\r
60 \r
61 err = 0;\r
62 // error checking\r
63 if (cnn == NULL) {\r
64 return ERROR_CNN_NULL_PTR;\r
65 }\r
66 if (cnn->params.allocatorLevel == Util_AllocatorLevel3) {\r
67 timlUtilFreeAcc(cnn->memPool);\r
68 cnn->memPool = NULL;\r
69 }\r
70 \r
71 layer = cnn->head;\r
72 // delete the rest of the layers\r
73 while (layer != NULL) {\r
74 switch (layer->type) {\r
75 case CNN_Input:\r
76 timlCNNFreeInputLayer(layer);\r
77 break;\r
78 case CNN_Conv:\r
79 timlCNNFreeConvLayer(layer);\r
80 break;\r
81 case CNN_Norm:\r
82 timlCNNFreeNormLayer(layer);\r
83 break;\r
84 case CNN_Pooling:\r
85 timlCNNFreePoolingLayer(layer);\r
86 break;\r
87 case CNN_Linear:\r
88 timlCNNFreeLinearLayer(layer);\r
89 break;\r
90 case CNN_Nonlinear:\r
91 timlCNNFreeNonlinearLayer(layer);\r
92 break;\r
93 case CNN_Dropout:\r
94 timlCNNFreeDropoutLayer(layer);\r
95 break;\r
96 case CNN_Softmax:\r
97 timlCNNFreeSoftmaxLayer(layer);\r
98 break;\r
99 case CNN_SoftmaxCost:\r
100 timlCNNFreeSoftmaxCostLayer(layer);\r
101 break;\r
102 case CNN_Accuracy:\r
103 timlCNNFreeAccuracyLayer(layer);\r
104 break;\r
105 default:\r
106 break;\r
107 }\r
108 layer = layer->next;\r
109 }\r
110 \r
111 return err;\r
112 }\r