asgn
 
Loading...
Searching...
No Matches
dcnnelements.hpp
1#ifndef dcnnelements_hpp_
2#define dcnnelements_hpp_
3
4#include "tagged.hpp"
5
6#include <cassert>
7#include <random>
8#include <cmath>
9
11namespace dcnnasgn {
12 struct permutation_policy_tag {};
13 struct permutation_policy_back_tag {};
14
15 template< typename PP>
16 concept is_policy = std::derived_from<PP, permutation_policy_tag>
17 && (!std::derived_from<PP, permutation_policy_back_tag>);
18
19 template< typename BPP>
20 concept is_policy_back = std::derived_from<BPP, permutation_policy_back_tag>;
21}
22
23namespace dcnnsol {
24
25 using dcnnasgn::is_policy;
26
27 template< typename SP, is_policy PP>
28 class image_data;
29
30 template< typename CSP, is_policy PP>
31 class feature_data;
32
33 template< typename KSP, typename CSPI, typename CSPO, is_policy PP>
34 class conv_weights;
35
36 template< typename CSPI, typename CSPO, is_policy PP>
37 class feature_weights;
38
39 template< typename CSP, is_policy PP>
40 class feature_multiplier;
41
42 template< typename CSP, is_policy PP>
43 class feature_bias;
44
45 template< typename CSPI, typename CSPO, typename KSP, is_policy PP>
46 class complete_cnn_model;
47
48 template< typename SPI, typename SPO, is_policy PP>
49 struct complete_cnn_internal;
50
51 template< typename SPI, typename SPO, typename KSP, is_policy PP>
52 struct complete_cnn_layer;
53
54}
56
57namespace dcnnasgn {
58
62
64 struct input_tag : tagged::tag_base {};
65 using input_range = tagged::range_class< input_tag>;
66 using input_index = tagged::index_class< input_tag>;
68
72 struct batch_tag : tagged::tag_base {};
73
75
79
84
86
90
94 struct height_selector : tagged::tag_base {};
98 struct width_selector : tagged::tag_base {};
99
101 template< std::size_t H>
102 struct height_stag : tagged::sr_tag<height_selector, 0, H> {};
103
104 template< std::size_t W>
105 struct width_stag : tagged::sr_tag<width_selector, 0, W> {};
107
109
113
119 template< std::size_t H, std::size_t W>
124 using height_tag = height_stag<H>;
128 using width_tag = width_stag<W>;
129
133 inline static constexpr tagged::range_class< height_tag> hr{ H };
137 inline static constexpr tagged::range_class< width_tag> wr{ W };
138 };
139
141
145
149 struct channel_selector : tagged::tag_base {};
150
152 template< std::size_t C>
153 struct channel_stag : tagged::sr_tag<channel_selector, 0, C> {};
155
162 struct kernel_height_selector : tagged::tag_base {};
169 struct kernel_width_selector : tagged::tag_base {};
170
172
176
179
180 template< typename ISP, typename CP>
181 struct input_data_policy : ISP, CP {
182 using typename ISP::height_tag;
183 using typename ISP::width_tag;
184 using typename CP::channel_tag;
185
186 using ISP::hr;
187 using ISP::wr;
188 using CP::cr;
189
190 using image_carrier = float;
191
194 };
195
196 template< typename ISP, typename CP>
197 class input_data {
198 public:
199 using policy = input_data_policy< ISP, CP>;
200 input_data(const input_range& inr) : images(inr& policy::hr& policy::wr& policy::cr) {}
201 policy::images_t images;
202 };
203
204 template< typename ISP, typename CP>
205 class batch_data {
206 public:
207 using policy = input_data_policy< ISP, CP>;
208
209 using height_tag = typename policy::height_tag;
210 using width_tag = typename policy::width_tag;
211 using channel_tag = typename policy::channel_tag;
212
213 batch_data(const batch_range& nr) : images(nr& policy::hr& policy::wr& policy::cr) {}
214 typename policy::batch_t images;
215 void init(const typename policy::images_t& ind, const input_range& inr)
216 {
217 auto hr = policy::hr;
218 auto wr = policy::wr;
219 auto cr = policy::cr;
220
221 static_assert(ind.range().template get<height_tag>() == hr);
222 static_assert(ind.range().template get<width_tag>() == wr);
223 static_assert(ind.range().template get<channel_tag>() == cr);
224
225 static_assert(images.range().template get<height_tag>() == hr);
226 static_assert(images.range().template get<width_tag>() == wr);
227 static_assert(images.range().template get<channel_tag>() == cr);
228
229 assert(images.range().template get<batch_tag>().size() == inr.size());
230
231 auto inrb = (*inr.begin()).value();
232 for (auto i : inr)
233 {
234 tagged::index_class<batch_tag> b(i.value() - inrb);
235 for (auto h : hr)
236 {
237 for (auto w : wr)
238 {
239 for (auto c : cr)
240 {
241 images[b & h & w & c] = ind[i & h & w & c];
242 }
243 }
244 }
245 }
246 }
247 void init(const typename policy::images_t& ind, const batch_mapping& bmap)
248 {
249 static constexpr auto hr = policy::hr;
250 static constexpr auto wr = policy::wr;
251 auto cr = policy::cr;
252
253 assert(ind.range().template get<height_tag>() == hr);
254 assert(ind.range().template get<width_tag>() == wr);
255 assert(ind.range().template get<channel_tag>() == cr);
256
257 assert(images.range().template get<height_tag>() == hr);
258 assert(images.range().template get<width_tag>() == wr);
259 assert(images.range().template get<channel_tag>() == cr);
260
261 assert(images.range().template get<batch_tag>() == bmap.range().get<batch_tag>());
262
263 for (auto b : bmap.range())
264 {
265 auto i = bmap[b];
266 for (auto h : hr)
267 {
268 for (auto w : wr)
269 {
270 for (auto c : cr)
271 {
272 images[b & h & w & c] = ind[i & h & w & c];
273 }
274 }
275 }
276 }
277 }
278 };
279
280 struct gold_labels_policy {
281 using label_carrier = std::uint32_t;
282
283 using labels_t = tagged::tensor_class< label_carrier, input_tag>;
284 using batch_t = tagged::tensor_class< label_carrier, batch_tag>;
285 };
286
287 class gold_labels {
288 public:
289 using policy = gold_labels_policy;
290 gold_labels(const input_range& inr) : labels(inr) {}
291 policy::labels_t labels;
292 };
293
294 class gold_data {
295 public:
296 using policy = gold_labels_policy;
297 gold_data(const batch_range& nr) : labels(nr) {}
298 policy::batch_t labels;
299 void init(const policy::labels_t& ind, const input_range& inr)
300 {
301 assert(labels.range().get<batch_tag>().size() == inr.size());
302
303 auto inrb = (*inr.begin()).value();
304 for (auto i : inr)
305 {
306 tagged::index_class<batch_tag> b(i.value() - inrb);
307 labels[b] = ind[i];
308 }
309 }
310 void init(const policy::labels_t& ind, const batch_mapping& bmap)
311 {
312 assert(labels.range().get<batch_tag>().size() == bmap.range().size());
313
314 for (auto b : bmap.range())
315 {
316 auto i = bmap[b];
317 labels[b] = ind[i];
318 }
319 }
320 };
322
324
328
333 template< std::size_t C>
338 using channel_tag = channel_stag<C>;
339
343 inline static constexpr tagged::range_class< channel_tag> cr{ C };
344 };
345
351 template< typename ISP, typename CSP>
352 struct image_data_size_policy : ISP, CSP {
356 using image_policy = ISP;
360 using channel_policy = CSP;
361 };
362
368 template< typename SP, is_policy PP>
369 struct image_data_policy : SP {
373 using typename SP::height_tag;
377 using typename SP::width_tag;
381 using typename SP::channel_tag;
382
386 inline static constexpr auto hr = SP::hr;
390 inline static constexpr auto wr = SP::wr;
394 inline static constexpr auto cr = SP::cr;
395
410 };
411
417 template< typename CSP, is_policy PP>
441
451
453
457
461 class loss_data {
462 public:
463 using policy = loss_data_policy;
464 loss_data(const batch_range& nr) : loss(nr) {}
465 policy::loss_t loss;
466 };
467
469
473
475
479
485 template< tagged::tag T1, tagged::tag T2>
486 struct delta_functor {
487 delta_functor(std::ptrdiff_t delta)
488 : delta_(delta)
489 {}
490
491 std::ptrdiff_t delta() const
492 {
493 return delta_;
494 }
495
496 tagged::index_class<T2> operator()(const tagged::index_class<T1>& ko) const
497 {
498 auto dox = ko.value();
499 return tagged::index_class<T2>(dox + delta_);
500 }
501 private:
502 std::ptrdiff_t delta_;
503 };
504
510 template< tagged::tag T1, tagged::tag T2>
511 struct neg_delta_functor {
512 neg_delta_functor(std::ptrdiff_t delta)
513 : delta_(delta)
514 {}
515
516 std::ptrdiff_t delta() const
517 {
518 return delta_;
519 }
520
521 tagged::index_class<T2> operator()(const tagged::index_class<T1>& ko) const
522 {
523 auto dox = ko.value();
524 return tagged::index_class<T2>(delta_ - dox);
525 }
526 private:
527 std::ptrdiff_t delta_;
528 };
529
536 template< tagged::tag T1, tagged::tag T2, std::ptrdiff_t MUL>
537 struct mul_delta_functor {
538 mul_delta_functor(std::ptrdiff_t delta)
539 : delta_(delta)
540 {}
541
542 std::ptrdiff_t delta() const
543 {
544 return delta_;
545 }
546
547 inline static constexpr std::ptrdiff_t multiplier = MUL;
548
549 tagged::index_class<T2> operator()(const tagged::index_class<T1>& ko) const
550 {
551 auto dox = ko.value();
552 return tagged::index_class<T2>(delta_ + multiplier * dox);
553 }
554 private:
555 std::ptrdiff_t delta_;
556 };
557
559
563
565 class first_stat {
566 public:
567 first_stat() : sumx(0), sumx2(0), E(0.0f), var(0.0f), scale(0.0f) {}
568 float sumx;
569 float sumx2;
570 float E;
571 float var;
572 float scale;
573 };
575
577
581
587 template< typename SP, is_policy PP>
589 private:
590 using ISP = typename SP::image_policy;
591 using CSP = typename SP::channel_policy;
592 public:
596 using input_data = batch_data<ISP, CSP>;
600 using stat_data = first_stat;
604 using output_data = dcnnsol::image_data< SP, PP>;
605
609 using height_tag = typename SP::height_tag;
613 using width_tag = typename SP::width_tag;
619 using channel_tag = typename SP::channel_tag;
620
621 inline static constexpr auto hr = SP::hr;
622 inline static constexpr auto wr = SP::wr;
623 inline static constexpr auto cr = SP::cr;
624
627 {
628 auto&& inv = ind.images;
629 auto&& sumx = cd.sumx;
630 auto&& sumx2 = cd.sumx2;
631 auto&& E = cd.E;
632 auto&& var = cd.var;
633 auto&& scale = cd.scale;
634 auto&& outv = outd.values;
635
636 auto&& inr = inv.range();
637 auto&& outr = outv.range();
638
639 auto&& br = inr.template get<batch_tag>();
640
641 static_assert(inr.template get<height_tag>() == hr);
642 static_assert(inr.template get<width_tag>() == wr);
643
644 static_assert(outr.template get<height_tag>() == hr);
645 static_assert(outr.template get<width_tag>() == wr);
646 static_assert(outr.template get<channel_tag>() == cr);
647
648 assert(outr.template get<batch_tag>() == br);
649
650 return br;
651 }
652
654 static std::size_t forward_complexity( const batch_range & br)
655 {
656 return (br & hr & wr & cr).size();
657 }
659 };
660
662
666
668 template< std::size_t KH>
669 struct kernel_height_stag : tagged::sr_tag<kernel_height_selector, 0, KH> {};
670
671 template< std::size_t KW>
672 struct kernel_width_stag : tagged::sr_tag<kernel_width_selector, 0, KW> {};
674
676
680
688 template< std::size_t KH, std::size_t KW>
694
695 using kernel_height_tag = kernel_height_stag<KH>;
696 using kernel_width_tag = kernel_width_stag<KW>;
697
699
704
705 inline static constexpr tagged::range_class< kernel_height_tag> khr{ KH };
706 inline static constexpr tagged::range_class< kernel_width_tag> kwr{ KW };
707
709 };
710
719 template< typename KSP, typename CSPI, typename CSPO>
725
726 using typename KSP::kernel_height_tag;
727 using typename KSP::kernel_width_tag;
728
729 using channel_in_tag = typename CSPI::channel_tag;
730 using channel_out_tag = typename CSPO::channel_tag;
731
733
738
739 using KSP::khr;
740 using KSP::kwr;
741 inline static constexpr auto cir = CSPI::cr;
742 inline static constexpr auto cor = CSPO::cr;
743
745 };
746
755 template< typename CSPI, typename CSPO>
761
762 using channel_in_tag = typename CSPI::channel_tag;
763 using channel_out_tag = typename CSPO::channel_tag;
764
766
771
772 inline static constexpr auto cir = CSPI::cr;
773 inline static constexpr auto cor = CSPO::cr;
774
776 };
777
785 template< typename KSP, typename CSPI, typename CSPO, is_policy PP>
786 struct conv_weight_policy : conv_weight_size_policy< KSP, CSPI, CSPO> {
787 private:
789 public:
790 using typename base_::kernel_height_tag;
791 using typename base_::kernel_width_tag;
792 using typename base_::channel_in_tag;
793 using typename base_::channel_out_tag;
794
802
812
814 };
815
823 template< typename CSPI, typename CSPO, is_policy PP>
851
853
857
859 template<std::size_t KD, std::size_t S>
860 struct conv_traits {
861 static_assert(KD / 2 >= S - 1);
862 inline static constexpr std::size_t LPAD = (KD - 1) / 2;
863 inline static constexpr std::size_t SHIFT = (KD - 1) / 2;
864 inline static constexpr std::size_t RPAD = KD / 2 + 1 - S;
865 // KD == LPAD + 1 + RPAD
866 };
868
877 template< tagged::tag TK, tagged::tag TO, std::size_t DI, std::size_t KD, std::size_t S>
879 using traits = conv_traits<KD, S>;
880 static_assert(DI > traits::LPAD);
881 static_assert(DI > traits::RPAD);
883 {
884 auto dox = o.value() * S;
885 return tagged::range_class< tagged::selector<TK>>(traits::LPAD - std::min(dox, traits::LPAD), (KD + DI - traits::RPAD - 1) - std::max(dox, DI - traits::RPAD - 1));
886 }
887 };
888
896 template< tagged::tag TI, tagged::tag TK, tagged::tag TO, std::size_t KD, std::size_t S>
898 using traits = conv_traits<KD, S>;
899 using df = delta_functor<TK, TI>;
900 df operator()(const tagged::index_class<TO>& o) const
901 {
902 auto dox = o.value() * S;
903 return df(dox - traits::SHIFT);
904 }
905 };
906
914 template< tagged::tag TI, tagged::tag TK, std::size_t DI, std::size_t KD, std::size_t S>
916 using traits = conv_traits<KD, S>;
917 static_assert(DI > traits::LPAD);
918 static_assert(DI > traits::RPAD);
920 {
921 static_assert(S == 1, "The kernel range is not contiguous for stride > 1");
922 auto dix = i.value();
923 return tagged::range_class< tagged::selector<TK>>(std::max(dix, DI - traits::LPAD - 1) - (DI - traits::LPAD - 1), (KD - traits::RPAD) + std::min(dix, traits::RPAD));
924 }
925 };
926
934 template< tagged::tag TI, tagged::tag TK, tagged::tag TO, std::size_t KD, std::size_t S>
936 using traits = conv_traits<KD, S>;
937 using df = neg_delta_functor<TK, TO>;
938 df operator()(const tagged::index_class<TI>& i) const
939 {
940 static_assert(S == 1, "The kernel range is not contiguous for stride > 1");
941 auto dix = i.value();
942 return df(dix + traits::SHIFT);
943 }
944 };
945
953 template< tagged::tag TK, tagged::tag TO, std::size_t DI, std::size_t KD, std::size_t S>
955 using traits = conv_traits<KD, S>;
956 static_assert(DI > traits::LPAD);
957 static_assert(DI > traits::RPAD);
959 {
960 auto dkx = k.value();
961 return tagged::range_class< tagged::selector<TO>>(((traits::LPAD + S - 1) - std::min(dkx, traits::LPAD)) / S, ((DI + KD - traits::RPAD - 1) - std::max(dkx, KD - traits::RPAD - 1)) / S);
962 }
963 };
964
972 template< tagged::tag TK, tagged::tag TO, tagged::tag TI, std::size_t KD, std::size_t S>
974 using traits = conv_traits<KD, S>;
975 using df = std::conditional_t< S == 1, delta_functor<TO, TI>, mul_delta_functor<TO, TI, S>>;
976 df operator()(const tagged::index_class<TK>& k) const
977 {
978 auto dkx = k.value();
979 return df(dkx - traits::SHIFT);
980 }
981 };
982
984
988
996 template< typename SPI, typename SPO, typename KSP, is_policy PP>
998 {
999 public:
1000 using CSPI = typename SPI::channel_policy;
1001 using CSPO = typename SPO::channel_policy;
1002
1005
1009 using input_data = dcnnsol::image_data<SPI, PP>;
1013 using weights = dcnnsol::conv_weights<KSP, CSPI, CSPO, PP>;
1017 using output_data = dcnnsol::image_data<SPO, PP>;
1019
1022
1023 using height_in_tag = typename SPI::height_tag;
1024 using width_in_tag = typename SPI::width_tag;
1025 using channel_in_tag = typename SPI::channel_tag;
1026
1027 using kernel_height_tag = typename KSP::kernel_height_tag;
1028 using kernel_width_tag = typename KSP::kernel_width_tag;
1029
1030 using height_out_tag = typename SPO::height_tag;
1031 using width_out_tag = typename SPO::width_tag;
1032 using channel_out_tag = typename SPO::channel_tag;
1033
1035
1036 static_assert(tagged::same_tag<height_in_tag, height_out_tag>);
1037 static_assert(tagged::same_tag<width_in_tag, width_out_tag>);
1038
1044
1045 inline static constexpr auto hir = SPI::hr;
1046 inline static constexpr auto wir = SPI::wr;
1047 inline static constexpr auto cir = SPI::cr;
1048 inline static constexpr auto khr = KSP::khr;
1049 inline static constexpr auto kwr = KSP::kwr;
1050 inline static constexpr auto hor = SPO::hr;
1051 inline static constexpr auto wor = SPO::wr;
1052 inline static constexpr auto cor = SPO::cr;
1053
1055
1056 inline static constexpr std::size_t fanin = khr.size() * kwr.size() * cir.size();
1057
1086
1091
1096
1101
1103
1106
1115 {
1116 auto&& inv = ind.values;
1117 auto&& wtv = wtd.weights;
1118 auto&& outv = outd.values;
1119
1120 auto&& inr = inv.range();
1121 auto&& wtr = wtv.range();
1122 auto&& outr = outv.range();
1123
1124 auto&& br = inr.template get<batch_tag>();
1125
1126 static_assert(inr.template get<height_in_tag>() == hir);
1127 static_assert(inr.template get<width_in_tag>() == wir);
1128 static_assert(inr.template get<channel_in_tag>() == cir);
1129
1130 static_assert(wtr.template get<kernel_height_tag>() == khr);
1131 static_assert(wtr.template get<kernel_width_tag>() == kwr);
1132 static_assert(wtr.template get< tagged::co<channel_in_tag>>() == ~cir);
1133 static_assert(wtr.template get<channel_out_tag>() == cor);
1134
1135 static_assert(outr.template get<height_out_tag>() == hor);
1136 static_assert(outr.template get<width_out_tag>() == wor);
1137 static_assert(outr.template get<channel_out_tag>() == cor);
1138
1139 assert(outr.template get<batch_tag>() == br);
1140
1141 return br;
1142 }
1143
1144 static std::size_t forward_complexity( const batch_range & br)
1145 {
1146 return (br & khr & kwr & hor & wor & ~cir & cor).size();
1147 }
1149
1151 };
1152
1160 template< typename SPI, typename SPO, typename KSP, is_policy PP>
1162 {
1163 public:
1164 using CSPI = typename SPI::channel_policy;
1165 using CSPO = typename SPO::channel_policy;
1166
1169
1173 using input_data = dcnnsol::image_data<SPI, PP>;
1177 using weights = dcnnsol::conv_weights<KSP, CSPI, CSPO, PP>;
1181 using output_data = dcnnsol::image_data<SPO, PP>;
1183
1186
1187 using height_in_tag = typename SPI::height_tag;
1188 using width_in_tag = typename SPI::width_tag;
1189 using channel_in_tag = typename SPI::channel_tag;
1190
1191 using kernel_height_tag = typename KSP::kernel_height_tag;
1192 using kernel_width_tag = typename KSP::kernel_width_tag;
1193
1194 using height_out_tag = typename SPO::height_tag;
1195 using width_out_tag = typename SPO::width_tag;
1196 using channel_out_tag = typename SPO::channel_tag;
1197
1199
1205
1206 inline static constexpr auto hir = SPI::hr;
1207 inline static constexpr auto wir = SPI::wr;
1208 inline static constexpr auto cir = SPI::cr;
1209 inline static constexpr auto khr = KSP::khr;
1210 inline static constexpr auto kwr = KSP::kwr;
1211 inline static constexpr auto hor = SPO::hr;
1212 inline static constexpr auto wor = SPO::wr;
1213 inline static constexpr auto cor = SPO::cr;
1214
1216
1217 inline static constexpr std::size_t fanin = khr.size() * kwr.size() * cir.size();
1218
1219 static_assert(hir.size() % hor.size() == 0);
1220 static_assert(wir.size() % wor.size() == 0);
1221
1226
1227 inline static constexpr std::size_t HSTRIDE = hir.size() / hor.size();
1228 inline static constexpr std::size_t WSTRIDE = wir.size() / wor.size();
1229
1231
1260
1265
1270
1275
1277
1280
1289 {
1290 auto&& inv = ind.values;
1291 auto&& wtv = wtd.weights;
1292 auto&& outv = outd.values;
1293
1294 auto&& inr = inv.range();
1295 auto&& wtr = wtv.range();
1296 auto&& outr = outv.range();
1297
1298 auto&& br = inr.template get<batch_tag>();
1299
1300 static_assert(inr.template get<height_in_tag>() == hir);
1301 static_assert(inr.template get<width_in_tag>() == wir);
1302 static_assert(inr.template get<channel_in_tag>() == cir);
1303
1304 static_assert(wtr.template get<kernel_height_tag>() == khr);
1305 static_assert(wtr.template get<kernel_width_tag>() == kwr);
1306 static_assert(wtr.template get< tagged::co<channel_in_tag>>() == ~cir);
1307 static_assert(wtr.template get<channel_out_tag>() == cor);
1308
1309 static_assert(outr.template get<height_out_tag>() == hor);
1310 static_assert(outr.template get<width_out_tag>() == wor);
1311 static_assert(outr.template get<channel_out_tag>() == cor);
1312
1313 assert(outr.template get<batch_tag>() == br);
1314
1315 return br;
1316 }
1317
1318 static std::size_t forward_complexity(const batch_range& br)
1319 {
1320 return (br & khr & kwr & hor & wor & ~cir & cor).size();
1321 }
1323
1325 };
1326
1328
1332
1334 template< typename CSP>
1335 struct image_normalize_internal_policy : CSP {
1336 using typename CSP::channel_tag;
1337
1338 using CSP::cr;
1339
1340 using stat_t = tagged::tensor_class< float, channel_tag>;
1341 };
1343
1345
1349
1351 template< typename CSP>
1352 class image_normalize_model {
1353 public:
1354 using policy = image_normalize_internal_policy< CSP>;
1355 image_normalize_model() : Es(policy::cr), scales(policy::cr) {}
1356 policy::stat_t Es;
1357 policy::stat_t scales;
1358 };
1360
1362
1366
1372 template< typename SP, is_policy PP>
1374 public:
1375 using CSP = typename SP::channel_policy;
1376
1380 using input_data = dcnnsol::image_data<SP, PP>;
1384 using norm_data = image_normalize_model<CSP>;
1388 using output_data = dcnnsol::image_data<SP, PP>;
1389
1393 using height_tag = typename SP::height_tag;
1397 using width_tag = typename SP::width_tag;
1401 using channel_tag = typename SP::channel_tag;
1402
1403 inline static constexpr auto hr = SP::hr;
1404 inline static constexpr auto wr = SP::wr;
1405 inline static constexpr auto cr = SP::cr;
1406
1407 static tagged::range_class<batch_tag> forward_check(const input_data& ind, const norm_data& nd, output_data& outd)
1408 {
1409 auto&& inv = ind.values;
1410 auto&& Ev = nd.Es;
1411 auto&& scalev = nd.scales;
1412 auto&& outv = outd.values;
1413
1414 auto&& inr = inv.range();
1415 auto&& Er = Ev.range();
1416 auto&& scaler = scalev.range();
1417 auto&& outr = outv.range();
1418
1419 auto&& br = inr.template get<batch_tag>();
1420
1421 static_assert(inr.template get<height_tag>() == hr);
1422 static_assert(inr.template get<width_tag>() == wr);
1423 static_assert(inr.template get<channel_tag>() == cr);
1424
1425 static_assert(Er.template get<channel_tag>() == cr);
1426
1427 static_assert(scaler.template get<channel_tag>() == cr);
1428
1429 static_assert(outr.template get<height_tag>() == hr);
1430 static_assert(outr.template get<width_tag>() == wr);
1431 static_assert(outr.template get<channel_tag>() == cr);
1432
1433 assert(outr.template get<batch_tag>() == br);
1434
1435 return br;
1436 }
1437
1439 static std::size_t forward_complexity( const batch_range & br)
1440 {
1441 return (br & hr & wr & cr).size();
1442 }
1444 };
1445
1447
1451
1452 template< typename CSP, is_policy PP>
1454 using typename CSP::channel_tag;
1455
1456 using CSP::cr;
1457
1458 using multiplier_t = tagged::tensor_class< float, channel_tag>;
1460 };
1461
1463
1467
1473 template< typename SP, is_policy PP>
1475 public:
1476 using CSP = typename SP::channel_policy;
1479
1483 using input_data = dcnnsol::image_data<SP, PP>;
1487 using multiplier_data = dcnnsol::feature_multiplier<CSP, PP>;
1491 using output_data = dcnnsol::image_data<SP, PP>;
1493
1496
1497 using height_tag = typename SP::height_tag;
1498 using width_tag = typename SP::width_tag;
1499 using channel_tag = typename SP::channel_tag;
1501
1507
1508 inline static constexpr auto hr = SP::hr;
1509 inline static constexpr auto wr = SP::wr;
1510 inline static constexpr auto cr = SP::cr;
1511
1513
1516
1525 {
1526 auto&& inv = ind.values;
1527 auto&& multiplierv = cd.multipliers;
1528 auto&& outv = outd.values;
1529
1530 auto&& inr = inv.range();
1531 auto&& multiplierr = multiplierv.range();
1532 auto&& outr = outv.range();
1533
1534 auto&& br = inr.template get<batch_tag>();
1535
1536 static_assert(inr.template get<height_tag>() == hr);
1537 static_assert(inr.template get<width_tag>() == wr);
1538 static_assert(inr.template get<channel_tag>() == cr);
1539
1540 static_assert(multiplierr.template get<channel_tag>() == cr);
1541
1542 static_assert(outr.template get<height_tag>() == hr);
1543 static_assert(outr.template get<width_tag>() == wr);
1544 static_assert(outr.template get<channel_tag>() == cr);
1545
1546 assert(outr.template get<batch_tag>() == br);
1547
1548 return br;
1549 }
1550
1552 static std::size_t forward_complexity( const batch_range & br)
1553 {
1554 return (br & hr & wr & cr).size();
1555 }
1557 };
1558
1560
1564
1565 template< typename CSP, is_policy PP>
1566 struct feature_bias_policy : CSP {
1567 using typename CSP::channel_tag;
1568
1569 using CSP::cr;
1570
1573 };
1574
1576
1580
1586 template< typename SP, is_policy PP>
1588 public:
1589 using CSP = typename SP::channel_policy;
1590
1593
1597 using input_data = dcnnsol::image_data<SP, PP>;
1601 using bias_data = dcnnsol::feature_bias<CSP, PP>;
1605 using output_data = dcnnsol::image_data<SP, PP>;
1607
1610
1611 using height_tag = typename SP::height_tag;
1612 using width_tag = typename SP::width_tag;
1613 using channel_tag = typename SP::channel_tag;
1615
1621
1622 inline static constexpr auto hr = SP::hr;
1623 inline static constexpr auto wr = SP::wr;
1624 inline static constexpr auto cr = SP::cr;
1625
1627
1630
1639 {
1640 auto&& inv = ind.values;
1641 auto&& betav = cd.betas;
1642 auto&& outv = outd.values;
1643
1644 auto&& inr = inv.range();
1645 auto&& betar = betav.range();
1646 auto&& outr = outv.range();
1647
1648 auto&& br = inr.template get<batch_tag>();
1649
1650 static_assert(inr.template get<height_tag>() == hr);
1651 static_assert(inr.template get<width_tag>() == wr);
1652 static_assert(inr.template get<channel_tag>() == cr);
1653
1654 static_assert(betar.template get<channel_tag>() == cr);
1655
1656 static_assert(outr.template get<height_tag>() == hr);
1657 static_assert(outr.template get<width_tag>() == wr);
1658 static_assert(outr.template get<channel_tag>() == cr);
1659
1660 assert(outr.template get<batch_tag>() == br);
1661
1662 return br;
1663 }
1664
1666 static std::size_t forward_complexity(const batch_range& br)
1667 {
1668 return (br & hr & wr & cr).size();
1669 }
1671 };
1672
1673 template< typename SP, is_policy PP>
1675 using input_data = dcnnsol::image_data<SP, PP>;
1676 using output_data = dcnnsol::image_data<SP, PP>;
1677
1678 using height_tag = typename SP::height_tag;
1679 using width_tag = typename SP::width_tag;
1680 using channel_tag = typename SP::channel_tag;
1681
1682 inline static constexpr auto hr = SP::hr;
1683 inline static constexpr auto wr = SP::wr;
1684 inline static constexpr auto cr = SP::cr;
1685
1686 static tagged::range_class<batch_tag> forward_check(const input_data& ind, output_data& outd)
1687 {
1688 auto&& inv = ind.values;
1689 auto&& outv = outd.values;
1690
1691 auto&& inr = inv.range();
1692 auto&& outr = outv.range();
1693
1694 auto&& br = inr.template get<batch_tag>();
1695
1696 static_assert(inr.template get<height_tag>() == hr);
1697 static_assert(inr.template get<width_tag>() == wr);
1698 static_assert(inr.template get<channel_tag>() == cr);
1699
1700 static_assert(outr.template get<height_tag>() == hr);
1701 static_assert(outr.template get<width_tag>() == wr);
1702 static_assert(outr.template get<channel_tag>() == cr);
1703
1704 assert(outr.template get<batch_tag>() == br);
1705
1706 return br;
1707 }
1708
1710 static std::size_t forward_complexity( const batch_range & br)
1711 {
1712 return (br & hr & wr & cr).size();
1713 }
1715 };
1716
1718
1722
1723 struct maxpool_height_selector : tagged::tag_base {};
1724 struct maxpool_width_selector : tagged::tag_base {};
1725
1726 template< std::size_t KH>
1727 struct maxpool_height_stag : tagged::sr_tag<maxpool_height_selector, 0, KH> {};
1728
1729 template< std::size_t KW>
1730 struct maxpool_width_stag : tagged::sr_tag<maxpool_width_selector, 0, KW> {};
1731
1733
1737
1738 template< tagged::tag TK, tagged::tag TO, tagged::tag TI, std::size_t KD>
1741 df operator()(const tagged::index_class<TK>& k) const
1742 {
1743 auto dkx = k.value();
1744 return df(dkx);
1745 }
1746 };
1747
1749
1753
1754 template< typename SPI, typename SPO, is_policy PP>
1756
1757 static_assert(SPI::hr.size() % SPO::hr.size() == 0);
1758 static_assert(SPI::wr.size() % SPO::wr.size() == 0);
1759 static_assert(SPI::cr == SPO::cr);
1760
1761 static constexpr std::size_t KH = SPI::hr.size() / SPO::hr.size();
1762 static constexpr std::size_t KW = SPI::wr.size() / SPO::wr.size();
1763
1764 using input_data = dcnnsol::image_data<SPI, PP>;
1765 using output_data = dcnnsol::image_data<SPO, PP>;
1766
1767 using height_in_tag = typename SPI::height_tag;
1768 using width_in_tag = typename SPI::width_tag;
1769 using channel_tag = typename SPI::channel_tag;
1770
1771 using height_out_tag = typename SPO::height_tag;
1772 using width_out_tag = typename SPO::width_tag;
1773
1774 static_assert(tagged::same_tag<channel_tag, typename SPO::channel_tag>);
1775
1776 inline static constexpr auto hir = SPI::hr;
1777 inline static constexpr auto wir = SPI::wr;
1778 inline static constexpr auto cr = SPI::cr;
1779
1780 using maxpool_height_tag = maxpool_height_stag< KH>;
1781 using maxpool_width_tag = maxpool_width_stag< KW>;
1782
1783 inline static constexpr tagged::range_class< maxpool_height_tag> khr{ KH };
1784 inline static constexpr tagged::range_class< maxpool_width_tag> kwr{ KW };
1785
1786 inline static constexpr auto hor = SPO::hr;
1787 inline static constexpr auto wor = SPO::wr;
1788
1791
1792 static tagged::range_class<batch_tag> forward_check(const input_data& ind, output_data& outd)
1793 {
1794 auto&& inv = ind.values;
1795 auto&& outv = outd.values;
1796
1797 auto&& inr = inv.range();
1798 auto&& outr = outv.range();
1799
1800 auto&& br = inr.template get<batch_tag>();
1801
1802 static_assert(inr.template get<height_in_tag>() == hir);
1803 static_assert(inr.template get<width_in_tag>() == wir);
1804 static_assert(inr.template get<channel_tag>() == cr);
1805
1806 static_assert(outr.template get<height_out_tag>() == hor);
1807 static_assert(outr.template get<width_out_tag>() == wor);
1808 static_assert(outr.template get<channel_tag>() == cr);
1809
1810 assert(outr.template get<batch_tag>() == br);
1811
1812 return br;
1813 }
1814
1816 static std::size_t forward_complexity( const batch_range & br)
1817 {
1818 return (br & khr & kwr & hor & wor & cr).size();
1819 }
1821 };
1822
1823 template< typename SPI, typename CSPO, is_policy PP>
1825 {
1826 private:
1827 using CSPI = typename SPI::channel_policy;
1828
1829 static_assert(CSPI::cr == CSPO::cr);
1830 public:
1833
1837 using input_data = dcnnsol::image_data<SPI, PP>;
1841 using output_data = dcnnsol::feature_data<CSPO, PP>;
1842
1844
1847
1848 using height_in_tag = typename SPI::height_tag;
1849 using width_in_tag = typename SPI::width_tag;
1850 using channel_tag = typename SPI::channel_tag;
1851
1853
1859
1860 inline static constexpr auto hir = SPI::hr;
1861 inline static constexpr auto wir = SPI::wr;
1862 inline static constexpr auto cr = SPI::cr;
1863
1865
1866 inline static constexpr std::size_t fanin = hir.size() * wir.size();
1867
1870
1879 {
1880 auto&& inv = ind.values;
1881 auto&& outv = outd.values;
1882
1883 auto&& inr = inv.range();
1884 auto&& outr = outv.range();
1885
1886 auto&& br = inr.template get<batch_tag>();
1887
1888 static_assert(inr.template get<height_in_tag>() == hir);
1889 static_assert(inr.template get<width_in_tag>() == wir);
1890 static_assert(inr.template get<channel_tag>() == cr);
1891
1892 static_assert(outr.template get<channel_tag>() == cr);
1893
1894 assert(outr.template get<batch_tag>() == br);
1895
1896 return br;
1897 }
1898
1900 static std::size_t forward_complexity(const batch_range& br)
1901 {
1902 return (br & hir & wir & cr).size();
1903 }
1905 };
1906
1908
1912
1919 template< typename CSP>
1921 {
1922 using kernel_height_tag = tagged::retag< dcnnasgn::kernel_height_selector, typename CSP::height_tag>;
1923 using kernel_width_tag = tagged::retag< dcnnasgn::kernel_width_selector, typename CSP::width_tag>;
1924
1925 inline static constexpr auto khr = CSP::hr.template retag< kernel_height_tag>();
1926 inline static constexpr auto kwr = CSP::wr.template retag< kernel_width_tag>();
1927 };
1928
1930
1934
1940 template< tagged::tag TI, tagged::tag TK>
1942 tagged::index_class<TK> operator()(const tagged::index_class<TI>& i) const
1943 {
1944 return i.template retag<TK>();
1945 }
1946 };
1947
1949
1953
1960 template< typename CSPI, typename CSPO, is_policy PP>
1962 {
1963 public:
1966
1970 using input_data = dcnnsol::feature_data<CSPI, PP>;
1974 using weights = dcnnsol::feature_weights< CSPI, CSPO, PP>;
1978 using output_data = dcnnsol::feature_data<CSPO, PP>;
1979
1981
1984
1985 using channel_in_tag = typename CSPI::channel_tag;
1986
1987 using channel_out_tag = typename CSPO::channel_tag;
1988
1990
1996
1997 inline static constexpr auto cir = CSPI::cr;
1998 inline static constexpr auto cor = CSPO::cr;
1999
2001
2002 inline static constexpr std::size_t fanin = cir.size();
2003
2006
2015 {
2016 auto&& inv = ind.values;
2017 auto&& wtv = wtd.weights;
2018 auto&& outv = outd.values;
2019
2020 auto&& inr = inv.range();
2021 auto&& wtr = wtv.range();
2022 auto&& outr = outv.range();
2023
2024 auto&& br = inr.template get<batch_tag>();
2025
2026 static_assert(inr.template get<channel_in_tag>() == cir);
2027
2028 static_assert(wtr.template get< tagged::co<channel_in_tag>>() == ~cir);
2029 static_assert(wtr.template get<channel_out_tag>() == cor);
2030
2031 static_assert(outr.template get<channel_out_tag>() == cor);
2032
2033 assert(outr.template get<batch_tag>() == br);
2034
2035 return br;
2036 }
2037
2039 static std::size_t forward_complexity(const batch_range& br)
2040 {
2041 return (br & ~cir & cor).size();
2042 }
2044 };
2045
2046 template< typename CSP, is_policy PP>
2048 using input_data = dcnnsol::feature_data<CSP, PP>;
2049 using bias_data = dcnnsol::feature_bias<CSP, PP>;
2050 using output_data = dcnnsol::feature_data<CSP, PP>;
2051
2052 using typename CSP::channel_tag;
2053
2054 using CSP::cr;
2055
2056 static tagged::range_class<batch_tag> forward_check(const input_data& ind, const bias_data& cd, output_data& outd)
2057 {
2058 auto&& inv = ind.values;
2059 auto&& betav = cd.betas;
2060 auto&& outv = outd.values;
2061
2062 auto&& inr = inv.range();
2063 auto&& betar = betav.range();
2064 auto&& outr = outv.range();
2065
2066 auto&& br = inr.template get<batch_tag>();
2067
2068 static_assert(inr.template get<channel_tag>() == cr);
2069
2070 static_assert(betar.template get<channel_tag>() == cr);
2071
2072 static_assert(outr.template get<channel_tag>() == cr);
2073
2074 assert(outr.template get<batch_tag>() == br);
2075
2076 return br;
2077 }
2078
2080 static std::size_t forward_complexity( const batch_range & br)
2081 {
2082 return (br & cr).size();
2083 }
2085 };
2086
2087 template< typename CSP, is_policy PP>
2089 {
2090 using input_data = dcnnsol::feature_data<CSP, PP>;
2091 using output_data = loss_data;
2092
2093 using channel_tag = typename CSP::channel_tag;
2094
2095 inline static constexpr auto cr = CSP::cr;
2096
2097 static tagged::range_class<batch_tag> forward_check(const input_data& ind, const gold_data& gd, output_data& outd)
2098 {
2099 auto&& inv = ind.values;
2100 auto&& labelv = gd.labels;
2101 auto&& outv = outd.loss;
2102
2103 auto&& inr = inv.range();
2104 auto&& labelr = labelv.range();
2105 auto&& outr = outv.range();
2106
2107 auto&& br = inr.template get<batch_tag>();
2108
2109 static_assert(inr.template get<channel_tag>() == cr);
2110
2111 assert(labelr.template get<batch_tag>() == br);
2112
2113 assert(outr.template get<batch_tag>() == br);
2114
2115 return br;
2116 }
2117
2119 static std::size_t forward_complexity( const batch_range & br)
2120 {
2121 return (br & cr).size();
2122 }
2124 };
2125
2126
2127 using feature_ftl = tagged::tag_list<channel_selector>;
2130}
2131
2132#endif
Loss data class.
Definition dcnnelements.hpp:461
A list of tagged indexes (a position in an N-dimensional space)
Definition tagged.hpp:584
A list of tagged ranges (an N-dimensional box)
Definition tagged.hpp:733
std::size_t size() const
Size (volume) of the range.
Definition tagged.hpp:751
A tensor - a multi-dimensional tagged generalization of vector/matrix.
Definition tagged.hpp:1365
const range_class< TL ... > & range() const
The range corresponding to this tensor.
Definition tagged.hpp:1458
tagged::range_class< batch_tag > batch_range
The range of images within a minibatch.
Definition dcnnelements.hpp:83
typename impl::tag_traits< T >::selector selector
Extract selector tag from any tag.
Definition tagged.hpp:43
retag< typename impl::co_traits< selector< T > >::co, T > co
Provide a co-tag for a given tag.
Definition tagged.hpp:1645
impl::permute_t< P, impl::permutator_tensor_class< E, TL... > > permute_tensor_class
Provide a tensor_class for the selected dimensions with layout specified by a tagged::tag_list.
Definition tagged.hpp:1593
Functor to cast input to kernel indexes (without any change in value).
Definition dcnnelements.hpp:1941
Retag input dimension policy as kernel dimension policy.
Definition dcnnelements.hpp:1921
Tag: Images within a minibatch.
Definition dcnnelements.hpp:72
Tag: Channel dimension.
Definition dcnnelements.hpp:149
Channel size policy.
Definition dcnnelements.hpp:334
static constexpr tagged::range_class< channel_tag > cr
Channel index range, statically sized.
Definition dcnnelements.hpp:343
channel_stag< C > channel_tag
Tag: The channel dimension, statically sized.
Definition dcnnelements.hpp:338
Functor: Input index to kernel index range.
Definition dcnnelements.hpp:915
Functor: Input index to neg_delta_functor.
Definition dcnnelements.hpp:935
Policy class: Convolution kernel dimensions.
Definition dcnnelements.hpp:689
static constexpr tagged::range_class< kernel_height_tag > khr
Kernel (convolution) height range.
Definition dcnnelements.hpp:705
static constexpr tagged::range_class< kernel_width_tag > kwr
Kernel (convolution) width range.
Definition dcnnelements.hpp:706
kernel_width_stag< KW > kernel_width_tag
Kernel (convolution) width.
Definition dcnnelements.hpp:696
kernel_height_stag< KH > kernel_height_tag
Kernel (convolution) height.
Definition dcnnelements.hpp:695
Functor: Kernel index to output index range.
Definition dcnnelements.hpp:954
Functor: Kernel index to delta_functor.
Definition dcnnelements.hpp:973
Functor: Output index to kernel index range.
Definition dcnnelements.hpp:878
Functor: Output index to delta_functor.
Definition dcnnelements.hpp:897
Policy class: Model weight data types for convolutional layers.
Definition dcnnelements.hpp:786
tagged::permute_tensor_class< typename PP::weights, float, kernel_height_tag, kernel_width_tag, tagged::co< channel_in_tag >, channel_out_tag > weights_t
The tensor containing the weights of the convolution.
Definition dcnnelements.hpp:811
typename CSPO::channel_tag channel_out_tag
Output channel tag.
Definition dcnnelements.hpp:730
Policy class: Model weight dimensions for convolutional layers.
Definition dcnnelements.hpp:720
typename CSPO::channel_tag channel_out_tag
Output channel tag.
Definition dcnnelements.hpp:730
static constexpr auto cir
Input channel range.
Definition dcnnelements.hpp:741
typename CSPI::channel_tag channel_in_tag
Input channel tag.
Definition dcnnelements.hpp:729
static constexpr auto cor
Output channel range.
Definition dcnnelements.hpp:742
Functor to add a fixed value.
Definition dcnnelements.hpp:486
Definition dcnnelements.hpp:1566
Utility base class for the fully connected layer.
Definition dcnnelements.hpp:1962
dcnnsol::feature_weights< CSPI, CSPO, PP > weights
Model weights.
Definition dcnnelements.hpp:1974
static constexpr std::size_t fanin
Number of inputs for each output element.
Definition dcnnelements.hpp:2002
typename CSPO::channel_tag channel_out_tag
Output feature channel.
Definition dcnnelements.hpp:1987
static constexpr auto cor
Output feature channel range.
Definition dcnnelements.hpp:1998
dcnnsol::feature_data< CSPI, PP > input_data
Input activations.
Definition dcnnelements.hpp:1970
static constexpr auto cir
Input feature channel range.
Definition dcnnelements.hpp:1997
typename CSPI::channel_tag channel_in_tag
Input feature channel.
Definition dcnnelements.hpp:1985
static tagged::range_class< batch_tag > forward_check(const input_data &ind, const weights &wtd, output_data &outd)
Check argument compatibility for the forward function.
Definition dcnnelements.hpp:2014
dcnnsol::feature_data< CSPO, PP > output_data
Output activations.
Definition dcnnelements.hpp:1978
Final layer activation data policy.
Definition dcnnelements.hpp:418
static constexpr auto cr
Channel index range, statically sized.
Definition dcnnelements.hpp:424
tagged::permute_tensor_class< tagged::co_list< typename PP::feature_data >, float, tagged::co< channel_tag >, tagged::co< batch_tag > > co_values_t
2-dimensional tensor type carrying loss derivatives wrt. activations
Definition dcnnelements.hpp:439
tagged::permute_tensor_class< typename PP::feature_data, float, channel_tag, batch_tag > values_t
2-dimensional tensor type carrying activations
Definition dcnnelements.hpp:431
Definition dcnnelements.hpp:1453
Definition dcnnelements.hpp:2047
Policy class: Model weight data types for fully connected layers.
Definition dcnnelements.hpp:824
typename CSPO::channel_tag channel_out_tag
Output channel tag.
Definition dcnnelements.hpp:763
tagged::permute_tensor_class< typename PP::feature_weights, float, tagged::co< channel_in_tag >, channel_out_tag > weights_t
The tensor containing the weights of the convolution.
Definition dcnnelements.hpp:847
Policy class: Model weight dimensions for fully connected layers.
Definition dcnnelements.hpp:756
typename CSPO::channel_tag channel_out_tag
Output channel tag.
Definition dcnnelements.hpp:763
static constexpr auto cor
Output channel range.
Definition dcnnelements.hpp:773
static constexpr auto cir
Input channel range.
Definition dcnnelements.hpp:772
typename CSPI::channel_tag channel_in_tag
Input channel tag.
Definition dcnnelements.hpp:762
Definition dcnnelements.hpp:1825
static constexpr auto cr
Input image channel range.
Definition dcnnelements.hpp:1862
dcnnsol::feature_data< CSPO, PP > output_data
Output activations.
Definition dcnnelements.hpp:1841
static tagged::range_class< batch_tag > forward_check(const input_data &ind, output_data &outd)
Check argument compatibility for the forward function.
Definition dcnnelements.hpp:1878
typename SPI::width_tag width_in_tag
Input image width.
Definition dcnnelements.hpp:1849
typename SPI::height_tag height_in_tag
Input image height.
Definition dcnnelements.hpp:1848
static constexpr auto hir
Input image height range.
Definition dcnnelements.hpp:1860
typename SPI::channel_tag channel_tag
Input image channel.
Definition dcnnelements.hpp:1850
static constexpr auto wir
Input image width range.
Definition dcnnelements.hpp:1861
static constexpr std::size_t fanin
Number of inputs for each output element.
Definition dcnnelements.hpp:1866
dcnnsol::image_data< SPI, PP > input_data
Input activations.
Definition dcnnelements.hpp:1837
Utility base class for the first normalizing layer.
Definition dcnnelements.hpp:588
static tagged::range_class< batch_tag > forward_check(const input_data &ind, stat_data &cd, output_data &outd)
Argument compatibility check for the forward function.
Definition dcnnelements.hpp:626
typename SP::channel_tag channel_tag
Tag: Channel index.
Definition dcnnelements.hpp:619
static constexpr auto hr
Index range along image height.
Definition dcnnelements.hpp:621
typename SP::height_tag height_tag
Tag: Image height dimension.
Definition dcnnelements.hpp:609
dcnnsol::image_data< SP, PP > output_data
Output activations.
Definition dcnnelements.hpp:604
static constexpr auto cr
Output channel index range [0,1)
Definition dcnnelements.hpp:623
first_stat stat_data
Statistics.
Definition dcnnelements.hpp:600
static constexpr auto wr
Index range along image width.
Definition dcnnelements.hpp:622
batch_data< ISP, CSP > input_data
Input activations.
Definition dcnnelements.hpp:596
typename SP::width_tag width_tag
Tag: Image width dimension.
Definition dcnnelements.hpp:613
Tag: Height dimension of an image.
Definition dcnnelements.hpp:94
Internal layer activation data policy.
Definition dcnnelements.hpp:369
tagged::permute_tensor_class< typename PP::data, float, height_tag, width_tag, channel_tag, batch_tag > values_t
4-dimensional tensor type carrying activations
Definition dcnnelements.hpp:401
static constexpr auto cr
Channel index range, statically sized.
Definition dcnnelements.hpp:394
static constexpr auto hr
Image height range, statically sized.
Definition dcnnelements.hpp:386
tagged::permute_tensor_class< tagged::co_list< typename PP::data >, float, tagged::co< height_tag >, tagged::co< width_tag >, tagged::co< channel_tag >, tagged::co< batch_tag > > co_values_t
4-dimensional tensor type carrying loss derivatives wrt. activations
Definition dcnnelements.hpp:409
static constexpr auto wr
Image width range, statically sized.
Definition dcnnelements.hpp:390
Combined image and channel size policy.
Definition dcnnelements.hpp:352
CSP channel_policy
Channel size policy.
Definition dcnnelements.hpp:360
ISP image_policy
Image size policy.
Definition dcnnelements.hpp:356
Definition dcnnelements.hpp:1755
Utility base class for the image multiply layer.
Definition dcnnelements.hpp:1474
dcnnsol::image_data< SP, PP > output_data
Output activations.
Definition dcnnelements.hpp:1491
static constexpr auto hr
Image height range.
Definition dcnnelements.hpp:1508
typename SP::width_tag width_tag
Image width.
Definition dcnnelements.hpp:1498
typename SP::height_tag height_tag
Image height.
Definition dcnnelements.hpp:1497
static constexpr auto wr
Image width range.
Definition dcnnelements.hpp:1509
dcnnsol::feature_multiplier< CSP, PP > multiplier_data
Model multiplieres.
Definition dcnnelements.hpp:1487
dcnnsol::image_data< SP, PP > input_data
Input activations.
Definition dcnnelements.hpp:1483
typename SP::channel_tag channel_tag
Image channel.
Definition dcnnelements.hpp:1499
static tagged::range_class< batch_tag > forward_check(const input_data &ind, const multiplier_data &cd, output_data &outd)
Check argument compatibility for the forward function.
Definition dcnnelements.hpp:1524
static constexpr auto cr
Image channel range.
Definition dcnnelements.hpp:1510
Utility base class for a normalizing layer.
Definition dcnnelements.hpp:1373
image_normalize_model< CSP > norm_data
Statistics.
Definition dcnnelements.hpp:1384
static constexpr auto cr
Index range along image width.
Definition dcnnelements.hpp:1405
typename SP::height_tag height_tag
Tag: Image height dimension.
Definition dcnnelements.hpp:1393
static constexpr auto hr
Index range along image height.
Definition dcnnelements.hpp:1403
dcnnsol::image_data< SP, PP > output_data
Output activations.
Definition dcnnelements.hpp:1388
typename SP::channel_tag channel_tag
Tag: Channel index.
Definition dcnnelements.hpp:1401
dcnnsol::image_data< SP, PP > input_data
Input activations.
Definition dcnnelements.hpp:1380
typename SP::width_tag width_tag
Tag: Image width dimension.
Definition dcnnelements.hpp:1397
static constexpr auto wr
Index range along image width.
Definition dcnnelements.hpp:1404
Definition dcnnelements.hpp:1674
Utility base class for the image shift layer.
Definition dcnnelements.hpp:1587
static constexpr auto hr
Image height range.
Definition dcnnelements.hpp:1622
dcnnsol::image_data< SP, PP > output_data
Output activations.
Definition dcnnelements.hpp:1605
typename SP::width_tag width_tag
Image width.
Definition dcnnelements.hpp:1612
static constexpr auto cr
Image channel range.
Definition dcnnelements.hpp:1624
static tagged::range_class< batch_tag > forward_check(const input_data &ind, const bias_data &cd, output_data &outd)
Check argument compatibility for the forward function.
Definition dcnnelements.hpp:1638
typename SP::channel_tag channel_tag
Image channel.
Definition dcnnelements.hpp:1613
typename SP::height_tag height_tag
Image height.
Definition dcnnelements.hpp:1611
static constexpr auto wr
Image width range.
Definition dcnnelements.hpp:1623
dcnnsol::feature_bias< CSP, PP > bias_data
Model biases.
Definition dcnnelements.hpp:1601
dcnnsol::image_data< SP, PP > input_data
Input activations.
Definition dcnnelements.hpp:1597
Image size policy.
Definition dcnnelements.hpp:120
height_stag< H > height_tag
Tag: Height dimension of an image, statically sized.
Definition dcnnelements.hpp:124
width_stag< W > width_tag
Tag: Width dimension of an image, statically sized.
Definition dcnnelements.hpp:128
static constexpr tagged::range_class< height_tag > hr
Height range of an image, statically sized.
Definition dcnnelements.hpp:133
static constexpr tagged::range_class< width_tag > wr
Width range of an image, statically sized.
Definition dcnnelements.hpp:137
Tag: Kernel height dimension.
Definition dcnnelements.hpp:162
Tag: Kernel width dimension.
Definition dcnnelements.hpp:169
Loss data policy.
Definition dcnnelements.hpp:445
tagged::tensor_class< float, batch_tag > loss_t
1-dimensional tensor type carrying loss values for images in a minibatch
Definition dcnnelements.hpp:449
Definition dcnnelements.hpp:2089
Definition dcnnelements.hpp:1723
Definition dcnnelements.hpp:1727
Definition dcnnelements.hpp:1739
Definition dcnnelements.hpp:1724
Definition dcnnelements.hpp:1730
Functor to multiply by a constant and add a fixed value.
Definition dcnnelements.hpp:537
Functor to subtract from a fixed value.
Definition dcnnelements.hpp:511
Utility base class for the convolutional layer.
Definition dcnnelements.hpp:998
typename KSP::kernel_width_tag kernel_width_tag
Kernel width.
Definition dcnnelements.hpp:1028
static constexpr conv_iko_map_functor< tagged::selector< height_in_tag >, tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, khr.size(), 1 > hikomf
input-height index to kernel-height index to output-height index
Definition dcnnelements.hpp:1093
static constexpr conv_ok_range_functor< tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, hir.size(), khr.size(), 1 > hokrf
output-height index to kernel-height range
Definition dcnnelements.hpp:1087
dcnnsol::image_data< SPI, PP > input_data
Input activations.
Definition dcnnelements.hpp:1009
static constexpr auto cor
Output image channel range.
Definition dcnnelements.hpp:1052
static constexpr auto hir
Input image height range.
Definition dcnnelements.hpp:1045
static constexpr auto wir
Input image width range.
Definition dcnnelements.hpp:1046
static constexpr conv_koi_map_functor< tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, tagged::selector< width_in_tag >, kwr.size(), 1 > wkoimf
kernel-width index to output-width index to input-width index
Definition dcnnelements.hpp:1100
typename SPI::height_tag height_in_tag
Input image height.
Definition dcnnelements.hpp:1023
static constexpr conv_koi_map_functor< tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, tagged::selector< height_in_tag >, khr.size(), 1 > hkoimf
kernel-height index to output-height index to input-height index
Definition dcnnelements.hpp:1098
typename SPI::width_tag width_in_tag
Input image width.
Definition dcnnelements.hpp:1024
static constexpr auto cir
Input image channel range.
Definition dcnnelements.hpp:1047
typename SPO::height_tag height_out_tag
Output image height.
Definition dcnnelements.hpp:1030
static constexpr auto khr
Kernel height range.
Definition dcnnelements.hpp:1048
dcnnsol::image_data< SPO, PP > output_data
Output activations.
Definition dcnnelements.hpp:1017
static tagged::range_class< batch_tag > forward_check(const input_data &ind, const weights &wtd, output_data &outd)
Check argument compatibility for the forward function.
Definition dcnnelements.hpp:1114
static constexpr conv_ko_range_functor< tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, hir.size(), khr.size(), 1 > hkorf
kernel-height index to output-height range
Definition dcnnelements.hpp:1097
static constexpr conv_oki_map_functor< tagged::selector< width_in_tag >, tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, kwr.size(), 1 > wokimf
output-width index to kernel-width index to input-width index
Definition dcnnelements.hpp:1090
static constexpr conv_ik_range_functor< tagged::selector< width_in_tag >, tagged::selector< kernel_width_tag >, wir.size(), kwr.size(), 1 > wikrf
input-width index to kernel-width range
Definition dcnnelements.hpp:1094
static constexpr conv_ko_range_functor< tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, wir.size(), kwr.size(), 1 > wkorf
kernel-width index to output-width range
Definition dcnnelements.hpp:1099
typename SPO::width_tag width_out_tag
Output image width.
Definition dcnnelements.hpp:1031
static constexpr conv_oki_map_functor< tagged::selector< height_in_tag >, tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, khr.size(), 1 > hokimf
output-height index to kernel-height index to input-height index
Definition dcnnelements.hpp:1088
static constexpr auto kwr
Kernel width range.
Definition dcnnelements.hpp:1049
static constexpr conv_iko_map_functor< tagged::selector< width_in_tag >, tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, kwr.size(), 1 > wikomf
input-width index to kernel-width index to output-width index
Definition dcnnelements.hpp:1095
static constexpr std::size_t fanin
Number of inputs for each output element.
Definition dcnnelements.hpp:1056
typename SPI::channel_tag channel_in_tag
Input image channel.
Definition dcnnelements.hpp:1025
typename KSP::kernel_height_tag kernel_height_tag
Kernel height.
Definition dcnnelements.hpp:1027
typename SPO::channel_tag channel_out_tag
Output image channel.
Definition dcnnelements.hpp:1032
dcnnsol::conv_weights< KSP, CSPI, CSPO, PP > weights
Model weights.
Definition dcnnelements.hpp:1013
static constexpr conv_ok_range_functor< tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, wir.size(), kwr.size(), 1 > wokrf
output-width index to kernel-width range
Definition dcnnelements.hpp:1089
static constexpr auto hor
Output image height range.
Definition dcnnelements.hpp:1050
static constexpr conv_ik_range_functor< tagged::selector< height_in_tag >, tagged::selector< kernel_height_tag >, hir.size(), khr.size(), 1 > hikrf
input-height index to kernel-height range
Definition dcnnelements.hpp:1092
static constexpr auto wor
Output image width range.
Definition dcnnelements.hpp:1051
Utility base class for the convolutional layer.
Definition dcnnelements.hpp:1162
static constexpr conv_iko_map_functor< tagged::selector< width_in_tag >, tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, kwr.size(), WSTRIDE > wikomf
input-width index to kernel-width index to output-width index
Definition dcnnelements.hpp:1269
static tagged::range_class< batch_tag > forward_check(const input_data &ind, const weights &wtd, output_data &outd)
Check argument compatibility for the forward function.
Definition dcnnelements.hpp:1288
typename SPI::height_tag height_in_tag
Input image height.
Definition dcnnelements.hpp:1187
static constexpr conv_oki_map_functor< tagged::selector< height_in_tag >, tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, khr.size(), HSTRIDE > hokimf
output-height index to kernel-height index to input-height index
Definition dcnnelements.hpp:1262
dcnnsol::image_data< SPI, PP > input_data
Input activations.
Definition dcnnelements.hpp:1173
static constexpr auto wor
Output image width range.
Definition dcnnelements.hpp:1212
static constexpr conv_oki_map_functor< tagged::selector< width_in_tag >, tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, kwr.size(), WSTRIDE > wokimf
output-width index to kernel-width index to input-width index
Definition dcnnelements.hpp:1264
typename SPI::width_tag width_in_tag
Input image width.
Definition dcnnelements.hpp:1188
static constexpr conv_koi_map_functor< tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, tagged::selector< height_in_tag >, khr.size(), HSTRIDE > hkoimf
kernel-height index to output-height index to input-height index
Definition dcnnelements.hpp:1272
static constexpr conv_ko_range_functor< tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, wir.size(), kwr.size(), WSTRIDE > wkorf
kernel-width index to output-width range
Definition dcnnelements.hpp:1273
static constexpr conv_ik_range_functor< tagged::selector< height_in_tag >, tagged::selector< kernel_height_tag >, hir.size(), khr.size(), HSTRIDE > hikrf
input-height index to kernel-height range
Definition dcnnelements.hpp:1266
typename KSP::kernel_height_tag kernel_height_tag
Kernel height.
Definition dcnnelements.hpp:1191
typename SPO::channel_tag channel_out_tag
Output image channel.
Definition dcnnelements.hpp:1196
static constexpr auto hor
Output image height range.
Definition dcnnelements.hpp:1211
dcnnsol::image_data< SPO, PP > output_data
Output activations.
Definition dcnnelements.hpp:1181
static constexpr auto wir
Input image width range.
Definition dcnnelements.hpp:1207
static constexpr auto hir
Input image height range.
Definition dcnnelements.hpp:1206
static constexpr conv_ko_range_functor< tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, hir.size(), khr.size(), HSTRIDE > hkorf
kernel-height index to output-height range
Definition dcnnelements.hpp:1271
typename SPO::width_tag width_out_tag
Output image width.
Definition dcnnelements.hpp:1195
static constexpr auto kwr
Kernel width range.
Definition dcnnelements.hpp:1210
static constexpr auto khr
Kernel height range.
Definition dcnnelements.hpp:1209
static constexpr auto cor
Output image channel range.
Definition dcnnelements.hpp:1213
typename SPI::channel_tag channel_in_tag
Input image channel.
Definition dcnnelements.hpp:1189
static constexpr conv_koi_map_functor< tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, tagged::selector< width_in_tag >, kwr.size(), WSTRIDE > wkoimf
kernel-width index to output-width index to input-width index
Definition dcnnelements.hpp:1274
typename KSP::kernel_width_tag kernel_width_tag
Kernel width.
Definition dcnnelements.hpp:1192
static constexpr auto cir
Input image channel range.
Definition dcnnelements.hpp:1208
static constexpr conv_ik_range_functor< tagged::selector< width_in_tag >, tagged::selector< kernel_width_tag >, wir.size(), kwr.size(), WSTRIDE > wikrf
input-width index to kernel-width range
Definition dcnnelements.hpp:1268
typename SPO::height_tag height_out_tag
Output image height.
Definition dcnnelements.hpp:1194
static constexpr conv_ok_range_functor< tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, hir.size(), khr.size(), HSTRIDE > hokrf
output-height index to kernel-height range
Definition dcnnelements.hpp:1261
dcnnsol::conv_weights< KSP, CSPI, CSPO, PP > weights
Model weights.
Definition dcnnelements.hpp:1177
static constexpr conv_iko_map_functor< tagged::selector< height_in_tag >, tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, khr.size(), HSTRIDE > hikomf
input-height index to kernel-height index to output-height index
Definition dcnnelements.hpp:1267
static constexpr std::size_t fanin
Number of inputs for each output element.
Definition dcnnelements.hpp:1217
static constexpr conv_ok_range_functor< tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, wir.size(), kwr.size(), WSTRIDE > wokrf
output-width index to kernel-width range
Definition dcnnelements.hpp:1263
Tag: Width dimension of an image.
Definition dcnnelements.hpp:98
A wrapped list of tags.
Definition tagged.hpp:182