summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'debian/ti-timl/usr/share/ti/examples/timl/app/cnn/interop/caffe/appCNNInteropCaffeConvLayerConvert.cpp')
-rw-r--r--debian/ti-timl/usr/share/ti/examples/timl/app/cnn/interop/caffe/appCNNInteropCaffeConvLayerConvert.cpp111
1 files changed, 111 insertions, 0 deletions
diff --git a/debian/ti-timl/usr/share/ti/examples/timl/app/cnn/interop/caffe/appCNNInteropCaffeConvLayerConvert.cpp b/debian/ti-timl/usr/share/ti/examples/timl/app/cnn/interop/caffe/appCNNInteropCaffeConvLayerConvert.cpp
new file mode 100644
index 0000000..e9c8449
--- /dev/null
+++ b/debian/ti-timl/usr/share/ti/examples/timl/app/cnn/interop/caffe/appCNNInteropCaffeConvLayerConvert.cpp
@@ -0,0 +1,111 @@
1/******************************************************************************/
2/*!
3 * \file appCNNInteropCaffeConvLayerConvert.cpp
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 "appCNNInteropCaffe.hpp"
45
46
47/******************************************************************************/
48/*!
49 * \ingroup appCNNInteropCaffe
50 * \brief Convert Caffe conv layer
51 * \param[in] cnn CNN
52 * \param[in] layerStructure Layer structure
53 * \param[in] layerParam Layer params
54 * \return Error code
55 */
56/******************************************************************************/
57
58int appCNNInteropCaffeConvLayerConvert(timlConvNeuralNetwork *cnn, LayerParameter layerStructure, LayerParameter layerParam)
59{
60 float *kernel;
61 int pad;
62 int stride;
63 int kernelSize;
64 int channel;
65 int group;
66 int size;
67 timlCNNLayer *layer;
68 timlCNNConvParams params;
69
70 pad = layerStructure.convolution_param().pad();
71 stride = layerStructure.convolution_param().stride();
72 kernelSize = layerStructure.convolution_param().kernel_size();
73 channel = layerStructure.convolution_param().num_output();
74 group = layerStructure.convolution_param().group();
75
76 params = timlCNNConvParamsDefault();
77 params.padUp = pad;
78 params.padDown = pad;
79 params.padLeft = pad;
80 params.padRight = pad;
81 params.type = Util_Corr2D;
82
83 // add conv layer
84 timlCNNAddConvLayer(cnn, kernelSize, kernelSize, stride, stride, channel, params);
85 layer = cnn->tail;
86 timlCNNConvInitialize(layer);
87
88 // read kernel
89 size = layerParam.blobs(0).data_size();
90 kernel = (float*)malloc(sizeof(float)*size);
91 for (int i = 0; i < size; i++) {
92 kernel[i] = layerParam.blobs(0).data(i);
93 }
94
95 // convert grouped kernel
96 appCNNInteropCaffeFillBlockDiagonalMatrix(layer->convParams.kernel, layer->convParams.outputFeatureMapChannel, layer->convParams.inputFeatureMapChannel*layer->convParams.kernelRow*layer->convParams.kernelCol, group, kernel);
97 free(kernel);
98
99// // flip all the kernels
100// if (layer->convParams.type == Util_Conv2D) {
101// appCNNInteropCaffeFlipKernelMatrix(layer->convParams.kernel, kernelSize, kernelSize, layer->convParams.inputFeatureMapChannel, layer->convParams.outputFeatureMapChannel);
102// }
103
104 // read bias
105 size = layerParam.blobs(1).data_size();
106 for (int i = 0; i < size; i++) {
107 layer->convParams.bias[i] = layerParam.blobs(1).data(i);
108 }
109
110 return 0;
111}