]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ti-machine-learning/ti-machine-learning.git/blob - src/common/cnn/timlCNNNonlinearReadFromTextFile.c
Remove deleted files
[ti-machine-learning/ti-machine-learning.git] / src / common / cnn / timlCNNNonlinearReadFromTextFile.c
1 /******************************************************************************/\r
2 /*!\r
3  * \file timlCNNNonlinearReadFromTextFile.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 \r
45 #include "../api/timl.h"\r
46 \r
47 /******************************************************************************/\r
48 /*!\r
49  * \ingroup       cnn\r
50  * \brief         Read the nonlinear layer from a text file\r
51  * \param[in]     fp1 FILE ptr to the level 1 text file\r
52  * \param[in,out] cnn CNN\r
53  * \return        Error code\r
54  */\r
55 /******************************************************************************/\r
56 \r
57 int timlCNNNonlinearReadFromTextFile(FILE *fp1, timlConvNeuralNetwork *cnn)\r
58 {\r
59    int                    err;\r
60    int                    intBuffer;\r
61    int                    read;\r
62    char                   str[TIML_UTIL_MAX_STR];\r
63    int                    row;\r
64    int                    col;\r
65    int                    channel;\r
66    timlUtilActivationType activationType;\r
67 \r
68    read = fscanf(fp1, "%[^.].layer(%d).row = %d;\n", (char*)&str, &intBuffer, &row);\r
69    if (read != 3) {\r
70       timlCNNDelete(cnn);\r
71       return ERROR_CNN_READ_FILE;\r
72    }\r
73    read = fscanf(fp1, "%[^.].layer(%d).col = %d;\n", (char*)&str, &intBuffer, &col);\r
74    if (read != 3) {\r
75       timlCNNDelete(cnn);\r
76       return ERROR_CNN_READ_FILE;\r
77    }\r
78    read = fscanf(fp1, "%[^.].layer(%d).channel = %d;\n", (char*)&str, &intBuffer, &channel);\r
79    if (read != 3) {\r
80       timlCNNDelete(cnn);\r
81       return ERROR_CNN_READ_FILE;\r
82    }\r
83    read = fscanf(fp1, "%[^.].layer(%d).nonlinearParams.type = %d;\n", (char*)&str, &intBuffer, (int*)&activationType);\r
84    if (read != 3) {\r
85       timlCNNDelete(cnn);\r
86       return ERROR_CNN_READ_FILE;\r
87    }\r
88 \r
89    err = timlCNNAddNonlinearLayer(cnn, activationType);\r
90    if (err) {\r
91       timlCNNDelete(cnn);\r
92       return err;\r
93    }\r
94 \r
95    return 0;\r
96 }\r