diff options
Diffstat (limited to 'debian/ti-timl/usr/src/timl/src/common/cnn/timlCNNPoolingReadFromTextFile.c')
-rw-r--r-- | debian/ti-timl/usr/src/timl/src/common/cnn/timlCNNPoolingReadFromTextFile.c | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/debian/ti-timl/usr/src/timl/src/common/cnn/timlCNNPoolingReadFromTextFile.c b/debian/ti-timl/usr/src/timl/src/common/cnn/timlCNNPoolingReadFromTextFile.c new file mode 100644 index 0000000..d457acb --- /dev/null +++ b/debian/ti-timl/usr/src/timl/src/common/cnn/timlCNNPoolingReadFromTextFile.c | |||
@@ -0,0 +1,139 @@ | |||
1 | /******************************************************************************/ | ||
2 | /*! | ||
3 | * \file timlCNNPoolingReadFromTextFile.c | ||
4 | */ | ||
5 | /* Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/ | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * | ||
11 | * Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * | ||
14 | * Redistributions in binary form must reproduce the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer in the | ||
16 | * documentation and/or other materials provided with the | ||
17 | * distribution. | ||
18 | * | ||
19 | * Neither the name of Texas Instruments Incorporated nor the names of | ||
20 | * its contributors may be used to endorse or promote products derived | ||
21 | * from this software without specific prior written permission. | ||
22 | * | ||
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
26 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
27 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
28 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
29 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
34 | * | ||
35 | ******************************************************************************/ | ||
36 | |||
37 | |||
38 | /******************************************************************************* | ||
39 | * | ||
40 | * INCLUDES | ||
41 | * | ||
42 | ******************************************************************************/ | ||
43 | |||
44 | #include "../api/timl.h" | ||
45 | |||
46 | |||
47 | /******************************************************************************/ | ||
48 | /*! | ||
49 | * \ingroup cnn | ||
50 | * \brief Read the pooling layer from a text file | ||
51 | * \param[in] fp1 FILE ptr to the level 1 text file | ||
52 | * \param[in,out] cnn CNN | ||
53 | * \return Error code | ||
54 | */ | ||
55 | /******************************************************************************/ | ||
56 | |||
57 | int timlCNNPoolingReadFromTextFile(FILE *fp1, timlConvNeuralNetwork *cnn) | ||
58 | { | ||
59 | int err; | ||
60 | int intBuffer; | ||
61 | timlCNNPoolingParams params; | ||
62 | int read; | ||
63 | int row; | ||
64 | int col; | ||
65 | int channel; | ||
66 | char str[TIML_UTIL_MAX_STR]; | ||
67 | |||
68 | err = 0; | ||
69 | params = timlCNNPoolingParamsDefault(); | ||
70 | |||
71 | read = fscanf(fp1, "%[^.].layer(%d).row = %d;\n", (char*)&str, &intBuffer, &row); | ||
72 | if (read != 3) { | ||
73 | timlCNNDelete(cnn); | ||
74 | return ERROR_CNN_READ_FILE; | ||
75 | } | ||
76 | read = fscanf(fp1, "%[^.].layer(%d).col = %d;\n", (char*)&str, &intBuffer, &col); | ||
77 | if (read != 3) { | ||
78 | timlCNNDelete(cnn); | ||
79 | return ERROR_CNN_READ_FILE; | ||
80 | } | ||
81 | read = fscanf(fp1, "%[^.].layer(%d).channel = %d;\n", (char*)&str, &intBuffer, &channel); | ||
82 | if (read != 3) { | ||
83 | timlCNNDelete(cnn); | ||
84 | return ERROR_CNN_READ_FILE; | ||
85 | } | ||
86 | read = fscanf(fp1, "%[^.].layer(%d).poolingParams.type = %d;\n", (char*)&str, &intBuffer, (int*)¶ms.type); | ||
87 | if (read != 3) { | ||
88 | timlCNNDelete(cnn); | ||
89 | return ERROR_CNN_READ_FILE; | ||
90 | } | ||
91 | read = fscanf(fp1, "%[^.].layer(%d).poolingParams.scaleRow = %d;\n", (char*)&str, &intBuffer, ¶ms.scaleRow); | ||
92 | if (read != 3) { | ||
93 | timlCNNDelete(cnn); | ||
94 | return ERROR_CNN_READ_FILE; | ||
95 | } | ||
96 | read = fscanf(fp1, "%[^.].layer(%d).poolingParams.scaleCol = %d;\n", (char*)&str, &intBuffer, ¶ms.scaleCol); | ||
97 | if (read != 3) { | ||
98 | timlCNNDelete(cnn); | ||
99 | return ERROR_CNN_READ_FILE; | ||
100 | } | ||
101 | read = fscanf(fp1, "%[^.].layer(%d).poolingParams.padUp = %d;\n", (char*)&str, &intBuffer, ¶ms.padUp); | ||
102 | if (read != 3) { | ||
103 | timlCNNDelete(cnn); | ||
104 | return ERROR_CNN_READ_FILE; | ||
105 | } | ||
106 | read = fscanf(fp1, "%[^.].layer(%d).poolingParams.padDown = %d;\n", (char*)&str, &intBuffer, ¶ms.padDown); | ||
107 | if (read != 3) { | ||
108 | timlCNNDelete(cnn); | ||
109 | return ERROR_CNN_READ_FILE; | ||
110 | } | ||
111 | read = fscanf(fp1, "%[^.].layer(%d).poolingParams.padLeft = %d;\n", (char*)&str, &intBuffer, ¶ms.padLeft); | ||
112 | if (read != 3) { | ||
113 | timlCNNDelete(cnn); | ||
114 | return ERROR_CNN_READ_FILE; | ||
115 | } | ||
116 | read = fscanf(fp1, "%[^.].layer(%d).poolingParams.padRight = %d;\n", (char*)&str, &intBuffer, ¶ms.padRight); | ||
117 | if (read != 3) { | ||
118 | timlCNNDelete(cnn); | ||
119 | return ERROR_CNN_READ_FILE; | ||
120 | } | ||
121 | read = fscanf(fp1, "%[^.].layer(%d).poolingParams.strideX = %d;\n", (char*)&str, &intBuffer, ¶ms.strideX); | ||
122 | if (read != 3) { | ||
123 | timlCNNDelete(cnn); | ||
124 | return ERROR_CNN_READ_FILE; | ||
125 | } | ||
126 | read = fscanf(fp1, "%[^.].layer(%d).poolingParams.strideY = %d;\n", (char*)&str, &intBuffer, ¶ms.strideY); | ||
127 | if (read != 3) { | ||
128 | timlCNNDelete(cnn); | ||
129 | return ERROR_CNN_READ_FILE; | ||
130 | } | ||
131 | |||
132 | err = timlCNNAddPoolingLayer(cnn, params.scaleRow, params.scaleCol, params.strideX, params.strideY, params.type, params); | ||
133 | if (err) { | ||
134 | timlCNNDelete(cnn); | ||
135 | return err; | ||
136 | } | ||
137 | |||
138 | return 0; | ||
139 | } | ||