libeblearngui
|
00001 /*************************************************************************** 00002 * Copyright (C) 2009 by Pierre Sermanet * 00003 * pierre.sermanet@gmail.com * 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Redistribution under a license not approved by the Open Source 00014 * Initiative (http://www.opensource.org) must display the 00015 * following acknowledgement in all advertising material: 00016 * This product includes software developed at the Courant 00017 * Institute of Mathematical Sciences (http://cims.nyu.edu). 00018 * * The names of the authors may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00023 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY 00025 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00026 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00027 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00028 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00029 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 ***************************************************************************/ 00032 00033 #ifndef ELB_LAYERS_GUI_HPP_ 00034 #define ELB_LAYERS_GUI_HPP_ 00035 00036 using namespace std; 00037 00038 #define MAXWIDTH 1000 00039 00040 namespace ebl { 00041 00043 // full_layer 00044 00045 #define FULL_LAYER_GUI(dname, T, op, state) \ 00046 template <typename T, class Tstate> \ 00047 void full_layer_gui::dname(full_layer<T,Tstate> &nn, \ 00048 Tstate &in, Tstate &out, \ 00049 unsigned int &h0, unsigned int &w0, \ 00050 double zoom, T vmin, T vmax, \ 00051 bool show_out) { \ 00052 /* run it */ \ 00053 nn.op(in, out); \ 00054 unsigned int h = h0, w = w0; \ 00055 /* display text */ \ 00056 gui << gui_only() << at(h, w) << nn.name() << " in:" << in.T; \ 00057 w += 150; \ 00058 zoom *= 3; \ 00059 /* display inputs */ \ 00060 idx_bloop1(m, in.T, T) { \ 00061 if (w - w0 < MAXWIDTH) { \ 00062 draw_matrix(m, h, w, zoom, zoom, vmin, vmax); \ 00063 w += (uint) (m.dim(1) * zoom + 1); \ 00064 } \ 00065 } \ 00066 h0 += (uint) (std::max((uint) 10, (uint) (m.dim(0) * zoom + 1))); \ 00067 } 00068 00069 FULL_LAYER_GUI(display_fprop, x, fprop, fstate_idx) 00070 FULL_LAYER_GUI(display_bprop, dx, bprop, bstate_idx) 00071 FULL_LAYER_GUI(display_bbprop, ddx, bbprop, bbstate_idx) 00072 00074 // convolution_layer 00075 00076 #define CONVOLUTION_LAYER_GUI(dname, T, op, state) \ 00077 template <typename T, class Tstate> \ 00078 void convolution_layer_gui::dname(convolution_layer<T,Tstate> &nn, \ 00079 Tstate &in, Tstate &out, \ 00080 unsigned int &h0, \ 00081 unsigned int &w0, \ 00082 double zoom, T vmin, T vmax, \ 00083 bool show_out, bool run) { \ 00084 /* run it */ \ 00085 if (run) \ 00086 nn.op(in, out); \ 00087 unsigned int h = h0, w = w0; \ 00088 /* display text */ \ 00089 gui << gui_only() << at(h, w) << nn.name() << " in:" << in.T \ 00090 << at(h + 15, w) << "min:" << idx_min(in.T) \ 00091 << at(h + 30, w) << "max:" << idx_max(in.T); \ 00092 w += 150; \ 00093 /* display inputs */ \ 00094 idx_bloop1(m, in.T, T) { \ 00095 if (w - w0 < MAXWIDTH) { \ 00096 draw_matrix(m, h, w, zoom, zoom, vmin, vmax); \ 00097 w += (uint) (m.dim(1) * zoom + 1); \ 00098 } \ 00099 } \ 00100 h0 += (uint) (m.dim(0) * zoom + 1); \ 00101 w = w0; \ 00102 h = h0; \ 00103 /* display kernels text */ \ 00104 gui << gui_only()<< at(h, w) << "kernels:" << nn.convol.kernel.T; \ 00105 w += 150; \ 00106 /* display kernels */ \ 00107 /* zoom *= 4; */ \ 00108 idx_bloop1(mk, nn.convol.kernel.T, T) { \ 00109 if (w - w0 < MAXWIDTH) { \ 00110 draw_matrix(mk, h, w, zoom, zoom, vmin, vmax); \ 00111 w += (uint) (mk.dim(1) * zoom + 1); \ 00112 } \ 00113 } \ 00114 h0 += (uint) (std::max((uint) 10, (uint) (mk.dim(0) * zoom + 1))); \ 00115 } 00116 00117 CONVOLUTION_LAYER_GUI(display_fprop, x, fprop, fstate_idx) 00118 CONVOLUTION_LAYER_GUI(display_bprop, dx, bprop, bstate_idx) 00119 CONVOLUTION_LAYER_GUI(display_bbprop, ddx, bbprop, bbstate_idx) 00120 00122 // convabsnorm_layer 00123 00124 #define CONVABSNORM_LAYER_GUI(dname, T, op, state) \ 00125 template <typename T, class Tstate> \ 00126 void convabsnorm_layer_gui::dname(convabsnorm_layer<T,Tstate> &layer, \ 00127 Tstate &in, Tstate &out, \ 00128 unsigned int &h0, \ 00129 unsigned int &w0, \ 00130 double zoom, T vmin, T vmax, \ 00131 bool show_out) { \ 00132 convolution_layer_gui::dname(layer.lconv, in, out, h0, w0, \ 00133 zoom, vmin, vmax, show_out, false); \ 00134 /* run it */ \ 00135 layer.op(in, out); \ 00136 unsigned int h = h0, w = w0; \ 00137 /* display text */ \ 00138 gui << gui_only() << at(h, w) << layer.name() << " out:" << layer.tmp->T \ 00139 << at(h + 15, w) << "min:" << idx_min(layer.tmp->T) \ 00140 << at(h + 30, w) << "max:" << idx_max(layer.tmp->T); \ 00141 w += 150; \ 00142 /* display output of convolution */ \ 00143 idx_bloop1(m, layer.tmp->T, T) { \ 00144 if (w - w0 < MAXWIDTH) { \ 00145 draw_matrix(m, h, w, zoom, zoom, vmin, vmax); \ 00146 w += (uint) (m.dim(1) * zoom + 1); \ 00147 } \ 00148 } \ 00149 h0 += (uint) (m.dim(0) * zoom + 1); \ 00150 w = w0; \ 00151 h = h0; \ 00152 /* display text */ \ 00153 gui << gui_only() << at(h, w) << "abs out:" << layer.tmp2->T \ 00154 << at(h + 15, w) << "min:" << idx_min(layer.tmp2->T) \ 00155 << at(h + 30, w) << "max:" << idx_max(layer.tmp2->T); \ 00156 w += 150; \ 00157 /* display output of abs */ \ 00158 idx_bloop1(m2, layer.tmp2->T, T) { \ 00159 if (w - w0 < MAXWIDTH) { \ 00160 draw_matrix(m2, h, w, zoom, zoom, vmin, vmax); \ 00161 w += (uint) (m2.dim(1) * zoom + 1); \ 00162 } \ 00163 } \ 00164 h0 += (uint) (m2.dim(0) * zoom + 1); \ 00165 w = w0; \ 00166 h = h0; \ 00167 /* display normalization internals */ \ 00168 contrast_norm_module_gui::dname(layer.norm, in, out, h0, w0, \ 00169 zoom, vmin, vmax, show_out, false); \ 00170 } 00171 00172 CONVABSNORM_LAYER_GUI(display_fprop, x, fprop, fstate_idx) 00173 CONVABSNORM_LAYER_GUI(display_bprop, dx, bprop, bstate_idx) 00174 CONVABSNORM_LAYER_GUI(display_bbprop, ddx, bbprop, bbstate_idx) 00175 00177 // subsampling_layer 00178 00179 #define SUBSAMPLING_LAYER_GUI(dname, T, op, state) \ 00180 template <typename T, class Tstate> \ 00181 void subsampling_layer_gui::dname(subsampling_layer<T,Tstate> &nn, \ 00182 Tstate &in, Tstate &out, \ 00183 unsigned int &h0, \ 00184 unsigned int &w0, \ 00185 double zoom, T vmin, T vmax, \ 00186 bool show_out) { \ 00187 /* run it */ \ 00188 nn.op(in, out); \ 00189 unsigned int h = h0, w = w0; \ 00190 /* display input text */ \ 00191 gui << gui_only() << at(h, w) << nn.name() << " in:" << in.T; \ 00192 w += 150; \ 00193 /* display inputs */ \ 00194 idx_bloop1(m, in.T, T) { \ 00195 if (w - w0 < MAXWIDTH) { \ 00196 draw_matrix(m, h, w, zoom, zoom, vmin, vmax); \ 00197 w += (uint) (m.dim(1) * zoom + 1); \ 00198 } \ 00199 } \ 00200 h0 += (uint) (m.dim(0) * zoom + 1); \ 00201 w = w0; \ 00202 h = h0; \ 00203 /* display kernels text */ \ 00204 gui << gui_only()<< at(h, w) << "kernels:" << nn.subsampler.sub.T.dim(0); \ 00205 gui << "x" << in.T.dim(1) / nn.subsampler.sub.T.dim(1); \ 00206 gui << "x" << in.T.dim(2) / nn.subsampler.sub.T.dim(2); \ 00207 w += 150; \ 00208 h0 += 10; \ 00209 } 00210 00211 SUBSAMPLING_LAYER_GUI(display_fprop, x, fprop, fstate_idx) 00212 SUBSAMPLING_LAYER_GUI(display_bprop, dx, bprop, bstate_idx) 00213 SUBSAMPLING_LAYER_GUI(display_bbprop, ddx, bbprop, bbstate_idx) 00214 00215 } 00216 00217 #endif /* ELB_LAYERS_GUI_HPP_ */