summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'debian/ti-timl/usr/src/timl/src/test/cnn/testCNNSimpleResize.c')
-rw-r--r--debian/ti-timl/usr/src/timl/src/test/cnn/testCNNSimpleResize.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/debian/ti-timl/usr/src/timl/src/test/cnn/testCNNSimpleResize.c b/debian/ti-timl/usr/src/timl/src/test/cnn/testCNNSimpleResize.c
new file mode 100644
index 0000000..e0c52de
--- /dev/null
+++ b/debian/ti-timl/usr/src/timl/src/test/cnn/testCNNSimpleResize.c
@@ -0,0 +1,107 @@
1/******************************************************************************/
2/*!
3 * \file testCNNSimpleResize.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 "testCNN.h"
45
46
47/*******************************************************************************
48 *
49 * DEFINES
50 *
51 ******************************************************************************/
52
53#define MODEL_PATH "../../database/test/cnn/databaseTestCNNSimpleResize1.m"
54#define RESIZED_MODEL_PATH "../../database/test/cnn/databaseTestCNNSimpleResize2.m"
55#define IMAGE_ROW 28
56#define IMAGE_COL 28
57#define IMAGE_CHANNEL 1
58#define IMAGE_RESIZE_ROW 56
59#define IMAGE_RESIZE_COL 56
60#define IMAGE_RESIZE_CHANNEL 1
61#define INT_FORMAT "%10d"
62#define FLOAT_FORMAT "%12.4f"
63#define CNN_NAME "cnn"
64#define PARAMS_LEVEL Util_ParamsLevel2
65
66
67/******************************************************************************/
68/*!
69 * \ingroup testCNN
70 * \brief Simple resize function test
71 * \return Error code
72 */
73/******************************************************************************/
74
75int testCNNSimpleResize()
76{
77 timlConvNeuralNetwork *cnn;
78
79 printf("[Test] CNN simple resize\n");
80 // build up the CNN
81 printf("1. Build up CNN\n");
82 cnn = timlCNNCreateConvNeuralNetwork(timlCNNTrainingParamsDefault(), 0);
83 timlCNNAddInputLayer(cnn, IMAGE_ROW, IMAGE_COL, IMAGE_CHANNEL, timlCNNInputParamsDefault()); // input layer
84 timlCNNAddConvLayer(cnn, 5, 5, 1, 1, 6, timlCNNConvParamsDefault()); // conv layer
85 timlCNNAddNonlinearLayer(cnn, Util_Sigmoid); // sigmoid layer
86 timlCNNAddPoolingLayer(cnn, 4, 4, 4, 4, CNN_MaxPooling, timlCNNPoolingParamsDefault()); // max pooling layer
87 timlCNNAddDropoutLayer(cnn, 0.2); // dropout layer
88 timlCNNAddLinearLayer(cnn, 10, timlCNNLinearParamsDefault()); // linear layer
89 timlCNNAddNonlinearLayer(cnn, Util_Softmax); // softmax layer
90 timlCNNInitialize(cnn);
91 timlCNNReset(cnn);
92
93 // write model
94 printf("2. Write model\n");
95 timlCNNWriteToFile(MODEL_PATH, cnn, PARAMS_LEVEL, CNN_NAME, FLOAT_FORMAT, INT_FORMAT);
96
97 timlCNNResize(cnn, IMAGE_RESIZE_ROW, IMAGE_RESIZE_COL, IMAGE_RESIZE_CHANNEL);
98
99 // write resized model
100 printf("3. Write resized model\n");
101 timlCNNWriteToFile(RESIZED_MODEL_PATH, cnn, PARAMS_LEVEL, CNN_NAME, FLOAT_FORMAT, INT_FORMAT);
102
103 // free CNN
104 timlCNNDelete(cnn);
105
106 return 0;
107}