1#ifndef dcnnelements_hpp_
2#define dcnnelements_hpp_
13 template<
typename ... TL>
18 struct permutation_policy_tag {};
19 struct permutation_policy_back_tag {};
21 template<
typename PP>
22 concept is_policy = std::derived_from<PP, permutation_policy_tag>
23 && (!std::derived_from<PP, permutation_policy_back_tag>);
25 template<
typename BPP>
26 concept is_policy_back = std::derived_from<BPP, permutation_policy_back_tag>;
31 using dcnnasgn::is_policy;
33 template<
typename SP, is_policy PP>
36 template<
typename CSP, is_policy PP>
39 template<
typename KSP,
typename CSPI,
typename CSPO, is_policy PP>
42 template<
typename CSPI,
typename CSPO, is_policy PP>
43 class feature_weights;
45 template<
typename CSP, is_policy PP>
46 class feature_multiplier;
48 template<
typename CSP, is_policy PP>
51 template<
typename CSPI,
typename CSPO,
typename KSP, is_policy PP>
52 class complete_cnn_model;
54 template<
typename SPI,
typename SPO, is_policy PP>
55 struct complete_cnn_internal;
57 template<
typename SPI,
typename SPO,
typename KSP, is_policy PP>
58 struct complete_cnn_layer;
70 struct input_selector : tagged::tag_base {};
71 struct input_tag : tagged::r_tag<input_selector, tagged::rp_dense> {};
72 using input_range = tagged::range_class< input_tag>;
73 using input_index = tagged::index_class< input_tag>;
80 struct batch_tag : tagged::r_tag<batch_selector, tagged::rp_odd> {};
109 template< std::
size_t H>
110 struct height_stag : tagged::srr_tag<height_selector, 0, H, tagged::rp_odd> {};
112 template< std::
size_t W>
113 struct width_stag : tagged::srr_tag<width_selector, 0, W, tagged::rp_odd> {};
127 template< std::
size_t H, std::
size_t W>
160 template< std::
size_t C>
161 struct channel_stag : tagged::srr_tag<channel_selector, 0, C, tagged::rp_odd> {};
188 template<
typename ISP,
typename CP>
189 struct input_data_policy : ISP, CP {
190 using typename ISP::height_tag;
191 using typename ISP::width_tag;
192 using typename CP::channel_tag;
198 using image_carrier = float;
204 template<
typename ISP,
typename CP,
typename SPO, is_policy PP>
205 struct batch_initializer {
207 using policy = input_data_policy< ISP, CP>;
209 using height_tag =
typename policy::height_tag;
210 using width_tag =
typename policy::width_tag;
211 using channel_tag =
typename policy::channel_tag;
213 using output_data = dcnnsol::image_data<SPO, PP>;
215 static void init(
const typename policy::images_t& ind,
const batch_mapping& bmap, output_data& outd)
217 static constexpr auto hr = policy::hr;
218 static constexpr auto wr = policy::wr;
219 auto cr = policy::cr;
221 auto&& images = outd.values;
223 assert(ind.range().template get<height_tag>() == hr);
224 assert(ind.range().template get<width_tag>() == wr);
225 assert(ind.range().template get<channel_tag>() == cr);
227 assert(images.range().template get<height_tag>() == hr);
228 assert(images.range().template get<width_tag>() == wr);
229 assert(images.range().template get<channel_tag>() == cr);
231 assert(images.range().template get<batch_tag>() == bmap.range().get<batch_tag>());
233 for (
auto b : bmap.range())
242 images[b & h & w & c] = ind[i & h & w & c];
250 struct gold_labels_policy {
251 using label_carrier = std::uint32_t;
253 using labels_t = tagged::tensor_class< label_carrier, input_tag>;
254 using batch_t = tagged::tensor_class< label_carrier, batch_tag>;
259 using policy = gold_labels_policy;
260 gold_labels(
const input_range& inr) : labels(inr) {}
261 policy::labels_t labels;
266 using policy = gold_labels_policy;
267 gold_data(
const batch_range& nr) : labels(nr) {}
268 policy::batch_t labels;
269 void init(
const policy::labels_t& ind,
const input_range& inr)
271 assert(labels.range().get<batch_tag>().size() == inr.size());
273 auto inrb = (*inr.begin()).value();
276 tagged::index_class<batch_tag> b(i.value() - inrb);
280 void init(
const policy::labels_t& ind,
const batch_mapping& bmap)
282 assert(labels.range().get<batch_tag>().size() == bmap.range().size());
284 for (
auto b : bmap.range())
303 template< std::
size_t C>
321 template<
typename ISP,
typename CSP>
338 template<
typename SP, is_policy PP>
343 using typename SP::height_tag;
347 using typename SP::width_tag;
351 using typename SP::channel_tag;
356 inline static constexpr auto hr = SP::hr;
360 inline static constexpr auto wr = SP::wr;
364 inline static constexpr auto cr = SP::cr;
387 template<
typename CSP, is_policy PP>
389 using typename CSP::channel_tag;
394 inline static constexpr auto cr = CSP::cr;
425 data_stats(
float e,
float v)
433 auto&& rng = val.
range();
442 float c = (float)rng.
size();
452 template<
typename SP, is_policy PP>
453 inline data_stats value_stats(
const dcnnsol::image_data<SP, PP>& dt)
458 template<
typename CSP, is_policy PP>
459 inline data_stats value_stats(
const dcnnsol::feature_data<CSP, PP>& dt)
461 return data_stats(dt.values);
500 template< tagged::tag T1, tagged::tag T2>
501 struct delta_functor {
502 delta_functor(std::ptrdiff_t delta)
506 std::ptrdiff_t delta()
const
513 auto dox = ko.value();
517 std::ptrdiff_t delta_;
525 template< tagged::tag T1, tagged::tag T2>
526 struct neg_delta_functor {
527 neg_delta_functor(std::ptrdiff_t delta)
531 std::ptrdiff_t delta()
const
538 auto dox = ko.value();
542 std::ptrdiff_t delta_;
551 template< tagged::tag T1, tagged::tag T2, std::ptrdiff_t MUL>
552 struct mul_delta_functor {
553 mul_delta_functor(std::ptrdiff_t delta)
557 std::ptrdiff_t delta()
const
562 inline static constexpr std::ptrdiff_t multiplier = MUL;
566 auto dox = ko.value();
570 std::ptrdiff_t delta_;
580 template< std::
size_t KH>
581 struct kernel_height_stag : tagged::srr_tag<kernel_height_selector, 0, KH, tagged::rp_odd> {};
583 template< std::
size_t KW>
584 struct kernel_width_stag : tagged::srr_tag<kernel_width_selector, 0, KW, tagged::rp_odd> {};
600 template< std::
size_t KH, std::
size_t KW>
631 template<
typename KSP,
typename CSPI,
typename CSPO>
638 using typename KSP::kernel_height_tag;
639 using typename KSP::kernel_width_tag;
653 inline static constexpr auto cir = CSPI::cr;
654 inline static constexpr auto cor = CSPO::cr;
667 template<
typename CSPI,
typename CSPO>
684 inline static constexpr auto cir = CSPI::cr;
685 inline static constexpr auto cor = CSPO::cr;
697 template<
typename KSP,
typename CSPI,
typename CSPO, is_policy PP>
702 using typename base_::kernel_height_tag;
703 using typename base_::kernel_width_tag;
735 template<
typename CSPI,
typename CSPO, is_policy PP>
771 template<std::
size_t KD, std::
size_t S>
773 static_assert(KD / 2 >= S - 1);
774 inline static constexpr std::size_t LPAD = (KD - 1) / 2;
775 inline static constexpr std::size_t SHIFT = (KD - 1) / 2;
776 inline static constexpr std::size_t RPAD = KD / 2 + 1 - S;
789 template< tagged::tag TK, tagged::tag TO, std::
size_t DI, std::
size_t KD, std::
size_t S>
791 using traits = conv_traits<KD, S>;
792 static_assert(DI > traits::LPAD);
793 static_assert(DI > traits::RPAD);
796 auto dox = o.value() * S;
800 constexpr std::size_t multiplier()
const
805 constexpr std::size_t lpad()
const
810 constexpr std::size_t rpad()
const
823 template< tagged::tag TI, tagged::tag TK, tagged::tag TO, std::
size_t KD, std::
size_t S>
825 using traits = conv_traits<KD, S>;
829 auto dox = o.value() * S;
830 return df(dox - traits::SHIFT);
833 constexpr std::size_t multiplier()
const
838 constexpr std::ptrdiff_t delta()
const
840 return -traits::SHIFT;
851 template< tagged::tag TI, tagged::tag TK, std::
size_t DI, std::
size_t KD, std::
size_t S>
853 using traits = conv_traits<KD, S>;
854 static_assert(DI > traits::LPAD);
855 static_assert(DI > traits::RPAD);
858 static_assert(S == 1,
"The kernel range is not contiguous for stride > 1");
859 auto dix = i.value();
871 template< tagged::tag TI, tagged::tag TK, tagged::tag TO, std::
size_t KD, std::
size_t S>
873 using traits = conv_traits<KD, S>;
877 static_assert(S == 1,
"The kernel range is not contiguous for stride > 1");
878 auto dix = i.value();
879 return df(dix + traits::SHIFT);
890 template< tagged::tag TK, tagged::tag TO, std::
size_t DI, std::
size_t KD, std::
size_t S>
892 using traits = conv_traits<KD, S>;
893 static_assert(DI > traits::LPAD);
894 static_assert(DI > traits::RPAD);
897 auto dkx = k.value();
909 template< tagged::tag TK, tagged::tag TO, tagged::tag TI, std::
size_t KD, std::
size_t S>
911 using traits = conv_traits<KD, S>;
915 auto dkx = k.value();
916 return df(dkx - traits::SHIFT);
933 template<
typename SPI,
typename SPO,
typename KSP, is_policy PP>
937 using CSPI =
typename SPI::channel_policy;
938 using CSPO =
typename SPO::channel_policy;
950 using weights = dcnnsol::conv_weights<KSP, CSPI, CSPO, PP>;
973 static_assert(tagged::same_tag<height_in_tag, height_out_tag>);
974 static_assert(tagged::same_tag<width_in_tag, width_out_tag>);
982 inline static constexpr auto hir = SPI::hr;
983 inline static constexpr auto wir = SPI::wr;
984 inline static constexpr auto cir = SPI::cr;
985 inline static constexpr auto khr = KSP::khr;
986 inline static constexpr auto kwr = KSP::kwr;
987 inline static constexpr auto hor = SPO::hr;
988 inline static constexpr auto wor = SPO::wr;
989 inline static constexpr auto cor = SPO::cr;
993 inline static constexpr std::size_t
fanin =
khr.size() *
kwr.size() *
cir.size();
1053 auto&& inv = ind.values;
1054 auto&& wtv = wtd.weights;
1055 auto&& outv = outd.values;
1057 auto&& inr = inv.range();
1058 auto&& wtr = wtv.range();
1059 auto&& outr = outv.range();
1061 auto&& br = inr.template get<batch_tag>();
1063 static_assert(inr.template get<height_in_tag>() ==
hir);
1064 static_assert(inr.template get<width_in_tag>() ==
wir);
1065 static_assert(inr.template get<channel_in_tag>() ==
cir);
1067 static_assert(wtr.template get<kernel_height_tag>() ==
khr);
1068 static_assert(wtr.template get<kernel_width_tag>() ==
kwr);
1069 static_assert(wtr.template get< tagged::co<channel_in_tag>>() ==
~cir);
1070 static_assert(wtr.template get<channel_out_tag>() ==
cor);
1072 static_assert(outr.template get<height_out_tag>() ==
hor);
1073 static_assert(outr.template get<width_out_tag>() ==
wor);
1074 static_assert(outr.template get<channel_out_tag>() ==
cor);
1076 assert(outr.template get<batch_tag>() == br);
1081 static std::size_t forward_complexity(
const batch_range & br)
1097 template<
typename SPI,
typename SPO,
typename KSP, is_policy PP>
1101 using CSPI =
typename SPI::channel_policy;
1102 using CSPO =
typename SPO::channel_policy;
1114 using weights = dcnnsol::conv_weights<KSP, CSPI, CSPO, PP>;
1143 inline static constexpr auto hir = SPI::hr;
1144 inline static constexpr auto wir = SPI::wr;
1145 inline static constexpr auto cir = SPI::cr;
1146 inline static constexpr auto khr = KSP::khr;
1147 inline static constexpr auto kwr = KSP::kwr;
1148 inline static constexpr auto hor = SPO::hr;
1149 inline static constexpr auto wor = SPO::wr;
1150 inline static constexpr auto cor = SPO::cr;
1156 static_assert(
hir.size() %
hor.size() == 0);
1157 static_assert(
wir.size() %
wor.size() == 0);
1164 inline static constexpr std::size_t HSTRIDE =
hir.size() /
hor.size();
1165 inline static constexpr std::size_t WSTRIDE =
wir.size() /
wor.size();
1227 auto&& inv = ind.values;
1228 auto&& wtv = wtd.weights;
1229 auto&& outv = outd.values;
1231 auto&& inr = inv.range();
1232 auto&& wtr = wtv.range();
1233 auto&& outr = outv.range();
1235 auto&& br = inr.template get<batch_tag>();
1237 static_assert(inr.template get<height_in_tag>() ==
hir);
1238 static_assert(inr.template get<width_in_tag>() ==
wir);
1239 static_assert(inr.template get<channel_in_tag>() ==
cir);
1241 static_assert(wtr.template get<kernel_height_tag>() ==
khr);
1242 static_assert(wtr.template get<kernel_width_tag>() ==
kwr);
1243 static_assert(wtr.template get< tagged::co<channel_in_tag>>() ==
~cir);
1244 static_assert(wtr.template get<channel_out_tag>() ==
cor);
1246 static_assert(outr.template get<height_out_tag>() ==
hor);
1247 static_assert(outr.template get<width_out_tag>() ==
wor);
1248 static_assert(outr.template get<channel_out_tag>() ==
cor);
1250 assert(outr.template get<batch_tag>() == br);
1255 static std::size_t forward_complexity(
const batch_range& br)
1271 template<
typename CSP>
1272 struct image_transformed_relu_internal_policy : CSP {
1273 using typename CSP::channel_tag;
1277 using stat_t = tagged::tensor_class< float, channel_tag>;
1278 using multiplier_t = tagged::tensor_class< float, channel_tag>;
1279 using co_multiplier_t = tagged::tensor_class< float, tagged::co<channel_tag>>;
1280 using bias_t = tagged::tensor_class< float, channel_tag>;
1281 using co_bias_t = tagged::tensor_class< float, tagged::co<channel_tag>>;
1292 template<
typename CSP>
1293 class image_transformed_relu_model {
1295 using policy = image_transformed_relu_internal_policy< CSP>;
1296 image_transformed_relu_model() : scales(policy::cr), betas(policy::cr) {}
1297 policy::stat_t scales;
1298 policy::bias_t betas;
1313 template<
typename SP, is_policy PP>
1316 using CSP =
typename SP::channel_policy;
1344 inline static constexpr auto hr = SP::hr;
1345 inline static constexpr auto wr = SP::wr;
1346 inline static constexpr auto cr = SP::cr;
1350 auto&& inv = ind.values;
1351 auto&& scalev = nd.scales;
1352 auto&& betav = nd.betas;
1353 auto&& outv = outd.values;
1355 auto&& inr = inv.range();
1356 auto&& scaler = scalev.range();
1357 auto&& betar = betav.range();
1358 auto&& outr = outv.range();
1360 auto&& br = inr.template get<batch_tag>();
1362 static_assert(inr.template get<height_tag>() ==
hr);
1363 static_assert(inr.template get<width_tag>() ==
wr);
1364 static_assert(inr.template get<channel_tag>() ==
cr);
1366 static_assert(scaler.template get<channel_tag>() ==
cr);
1367 static_assert(betar.template get<channel_tag>() ==
cr);
1369 static_assert(outr.template get<height_tag>() ==
hr);
1370 static_assert(outr.template get<width_tag>() ==
wr);
1371 static_assert(outr.template get<channel_tag>() ==
cr);
1373 assert(outr.template get<batch_tag>() == br);
1379 static std::size_t forward_complexity(
const batch_range & br)
1381 return 5 * (br &
hr &
wr &
cr).size();
1391 template<
typename CSP, is_policy PP>
1393 using typename CSP::channel_tag;
1411 template< std::
size_t KH>
1414 template< std::
size_t KW>
1423 template< tagged::tag TK, tagged::tag TO, tagged::tag TI, std::
size_t KD>
1428 auto dkx = k.value();
1439 template<
typename SPI,
typename SPO, is_policy PP>
1442 static_assert(SPI::hr.size() % SPO::hr.size() == 0);
1443 static_assert(SPI::wr.size() % SPO::wr.size() == 0);
1444 static_assert(SPI::cr == SPO::cr);
1446 static constexpr std::size_t KH = SPI::hr.size() / SPO::hr.size();
1447 static constexpr std::size_t KW = SPI::wr.size() / SPO::wr.size();
1449 using input_data = dcnnsol::image_data<SPI, PP>;
1450 using output_data = dcnnsol::image_data<SPO, PP>;
1452 using height_in_tag =
typename SPI::height_tag;
1453 using width_in_tag =
typename SPI::width_tag;
1454 using channel_tag =
typename SPI::channel_tag;
1456 using height_out_tag =
typename SPO::height_tag;
1457 using width_out_tag =
typename SPO::width_tag;
1459 static_assert(tagged::same_tag<channel_tag, typename SPO::channel_tag>);
1461 inline static constexpr auto hir = SPI::hr;
1462 inline static constexpr auto wir = SPI::wr;
1463 inline static constexpr auto cr = SPI::cr;
1471 inline static constexpr auto hor = SPO::hr;
1472 inline static constexpr auto wor = SPO::wr;
1479 auto&& inv = ind.values;
1480 auto&& outv = outd.values;
1482 auto&& inr = inv.range();
1483 auto&& outr = outv.range();
1485 auto&& br = inr.template get<batch_tag>();
1487 static_assert(inr.template get<height_in_tag>() == hir);
1488 static_assert(inr.template get<width_in_tag>() == wir);
1489 static_assert(inr.template get<channel_tag>() == cr);
1491 static_assert(outr.template get<height_out_tag>() == hor);
1492 static_assert(outr.template get<width_out_tag>() == wor);
1493 static_assert(outr.template get<channel_tag>() == cr);
1495 assert(outr.template get<batch_tag>() == br);
1501 static std::size_t forward_complexity(
const batch_range & br)
1503 return (br & khr & kwr & hor & wor & cr).
size();
1508 template<
typename SPI,
typename CSPO, is_policy PP>
1512 using CSPI =
typename SPI::channel_policy;
1514 static_assert(CSPI::cr == CSPO::cr);
1545 inline static constexpr auto hir = SPI::hr;
1546 inline static constexpr auto wir = SPI::wr;
1547 inline static constexpr auto cr = SPI::cr;
1565 auto&& inv = ind.values;
1566 auto&& outv = outd.values;
1568 auto&& inr = inv.range();
1569 auto&& outr = outv.range();
1571 auto&& br = inr.template get<batch_tag>();
1573 static_assert(inr.template get<height_in_tag>() ==
hir);
1574 static_assert(inr.template get<width_in_tag>() ==
wir);
1575 static_assert(inr.template get<channel_tag>() ==
cr);
1577 static_assert(outr.template get<channel_tag>() ==
cr);
1579 assert(outr.template get<batch_tag>() == br);
1585 static std::size_t forward_complexity(
const batch_range& br)
1604 template<
typename CSP>
1607 using kernel_height_tag = tagged::retag< dcnnasgn::kernel_height_selector, typename CSP::height_tag>;
1608 using kernel_width_tag = tagged::retag< dcnnasgn::kernel_width_selector, typename CSP::width_tag>;
1610 inline static constexpr auto khr = CSP::hr.template retag< kernel_height_tag>();
1611 inline static constexpr auto kwr = CSP::wr.template retag< kernel_width_tag>();
1625 template< tagged::tag TI, tagged::tag TK>
1629 return i.template retag<TK>();
1645 template<
typename CSPI,
typename CSPO, is_policy PP>
1659 using weights = dcnnsol::feature_weights< CSPI, CSPO, PP>;
1682 inline static constexpr auto cir = CSPI::cr;
1683 inline static constexpr auto cor = CSPO::cr;
1687 inline static constexpr std::size_t
fanin =
cir.size();
1701 auto&& inv = ind.values;
1702 auto&& wtv = wtd.weights;
1703 auto&& outv = outd.values;
1705 auto&& inr = inv.range();
1706 auto&& wtr = wtv.range();
1707 auto&& outr = outv.range();
1709 auto&& br = inr.template get<batch_tag>();
1711 static_assert(inr.template get<channel_in_tag>() ==
cir);
1713 static_assert(wtr.template get< tagged::co<channel_in_tag>>() ==
~cir);
1714 static_assert(wtr.template get<channel_out_tag>() ==
cor);
1716 static_assert(outr.template get<channel_out_tag>() ==
cor);
1718 assert(outr.template get<batch_tag>() == br);
1724 static std::size_t forward_complexity(
const batch_range& br)
1731 template<
typename CSP, is_policy PP>
1733 using input_data = dcnnsol::feature_data<CSP, PP>;
1734 using bias_data = dcnnsol::feature_bias<CSP, PP>;
1735 using output_data = dcnnsol::feature_data<CSP, PP>;
1737 using typename CSP::channel_tag;
1743 auto&& inv = ind.values;
1744 auto&& betav = cd.betas;
1745 auto&& outv = outd.values;
1747 auto&& inr = inv.range();
1748 auto&& betar = betav.range();
1749 auto&& outr = outv.range();
1751 auto&& br = inr.template get<batch_tag>();
1753 static_assert(inr.template get<channel_tag>() == cr);
1755 static_assert(betar.template get<channel_tag>() == cr);
1757 static_assert(outr.template get<channel_tag>() == cr);
1759 assert(outr.template get<batch_tag>() == br);
1765 static std::size_t forward_complexity(
const batch_range & br)
1767 return (br & cr).
size();
1772 template<
typename CSP, is_policy PP>
1775 using input_data = dcnnsol::feature_data<CSP, PP>;
1778 using channel_tag =
typename CSP::channel_tag;
1780 inline static constexpr auto cr = CSP::cr;
1784 auto&& inv = ind.values;
1785 auto&& labelv = gd.labels;
1786 auto&& outv = outd.loss;
1788 auto&& inr = inv.
range();
1789 auto&& labelr = labelv.range();
1790 auto&& outr = outv.range();
1792 auto&& br = inr.template get<batch_tag>();
1794 static_assert(inr.template get<channel_tag>() == cr);
1796 assert(labelr.template get<batch_tag>() == br); sink(labelr);
1798 assert(outr.template get<batch_tag>() == br); sink(outr);
1804 static std::size_t forward_complexity(
const batch_range & br)
1806 return (br & cr).
size();
1818 template<
typename CSP, is_policy PP>
1825 using typename base_::input_data;
1826 using typename base_::output_data;
1830 using base_::forward_check;
1838 static void forward(
const input_data& ind,
const gold_data& gd, output_data& outd)
1840 auto br = forward_check(ind, gd, outd);
1842 auto&& inv = ind.values;
1843 auto&& labelv = gd.labels;
1844 auto&& outv = outd.loss;
1848 auto label = labelv[b];
1849 float maxv = std::numeric_limits<float>::lowest();
1853 auto v = inv[b & c];
1860 auto loss = maxc.value() == label ? 1.0f : 0.0f;
Loss data class.
Definition dcnnelements.hpp:471
A list of tagged indexes (a position in an N-dimensional space)
Definition tagged.hpp:784
A list of tagged ranges (an N-dimensional box)
Definition tagged.hpp:933
std::size_t size() const
Size (volume) of the range.
Definition tagged.hpp:951
A tensor - a multi-dimensional tagged generalization of vector/matrix.
Definition tagged.hpp:1617
const range_class< TL ... > & range() const
The range corresponding to this tensor.
Definition tagged.hpp:1710
Any tag used to specify a dimension.
Definition tagged.hpp:28
tagged::range_class< batch_tag > batch_range
The range of images within a minibatch.
Definition dcnnelements.hpp:91
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:1911
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:1857
Functor to cast input to kernel indexes (without any change in value).
Definition dcnnelements.hpp:1626
Retag input dimension policy as kernel dimension policy.
Definition dcnnelements.hpp:1606
Tag: Images within a minibatch.
Definition dcnnelements.hpp:79
Definition dcnnelements.hpp:80
Tag: Channel dimension.
Definition dcnnelements.hpp:157
Channel size policy.
Definition dcnnelements.hpp:304
static constexpr tagged::range_class< channel_tag > cr
Channel index range, statically sized.
Definition dcnnelements.hpp:313
channel_stag< C > channel_tag
Tag: The channel dimension, statically sized.
Definition dcnnelements.hpp:308
Functor: Input index to kernel index range.
Definition dcnnelements.hpp:852
Functor: Input index to neg_delta_functor.
Definition dcnnelements.hpp:872
Policy class: Convolution kernel dimensions.
Definition dcnnelements.hpp:601
static constexpr tagged::range_class< kernel_height_tag > khr
Kernel (convolution) height range.
Definition dcnnelements.hpp:617
static constexpr tagged::range_class< kernel_width_tag > kwr
Kernel (convolution) width range.
Definition dcnnelements.hpp:618
kernel_width_stag< KW > kernel_width_tag
Kernel (convolution) width.
Definition dcnnelements.hpp:608
kernel_height_stag< KH > kernel_height_tag
Kernel (convolution) height.
Definition dcnnelements.hpp:607
Functor: Kernel index to output index range.
Definition dcnnelements.hpp:891
Functor: Kernel index to delta_functor.
Definition dcnnelements.hpp:910
Functor: Output index to kernel index range.
Definition dcnnelements.hpp:790
Functor: Output index to delta_functor.
Definition dcnnelements.hpp:824
Policy class: Model weight data types for convolutional layers.
Definition dcnnelements.hpp:698
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:723
typename CSPO::channel_tag channel_out_tag
Output channel tag.
Definition dcnnelements.hpp:642
Policy class: Model weight dimensions for convolutional layers.
Definition dcnnelements.hpp:632
typename CSPO::channel_tag channel_out_tag
Output channel tag.
Definition dcnnelements.hpp:642
static constexpr auto cir
Input channel range.
Definition dcnnelements.hpp:653
typename CSPI::channel_tag channel_in_tag
Input channel tag.
Definition dcnnelements.hpp:641
static constexpr auto cor
Output channel range.
Definition dcnnelements.hpp:654
Definition dcnnelements.hpp:424
Functor to add a fixed value.
Definition dcnnelements.hpp:501
Definition dcnnelements.hpp:1392
Utility base class for the fully connected layer.
Definition dcnnelements.hpp:1647
dcnnsol::feature_weights< CSPI, CSPO, PP > weights
Model weights.
Definition dcnnelements.hpp:1659
static constexpr std::size_t fanin
Number of inputs for each output element.
Definition dcnnelements.hpp:1687
typename CSPO::channel_tag channel_out_tag
Output feature channel.
Definition dcnnelements.hpp:1672
static constexpr auto cor
Output feature channel range.
Definition dcnnelements.hpp:1683
dcnnsol::feature_data< CSPI, PP > input_data
Input activations.
Definition dcnnelements.hpp:1655
static constexpr auto cir
Input feature channel range.
Definition dcnnelements.hpp:1682
typename CSPI::channel_tag channel_in_tag
Input feature channel.
Definition dcnnelements.hpp:1670
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:1699
dcnnsol::feature_data< CSPO, PP > output_data
Output activations.
Definition dcnnelements.hpp:1663
Final layer activation data policy.
Definition dcnnelements.hpp:388
static constexpr auto cr
Channel index range, statically sized.
Definition dcnnelements.hpp:394
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:409
tagged::permute_tensor_class< typename PP::feature_data, float, channel_tag, batch_tag > values_t
2-dimensional tensor type carrying activations
Definition dcnnelements.hpp:401
Definition dcnnelements.hpp:1732
Policy class: Model weight data types for fully connected layers.
Definition dcnnelements.hpp:736
typename CSPO::channel_tag channel_out_tag
Output channel tag.
Definition dcnnelements.hpp:675
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:759
Policy class: Model weight dimensions for fully connected layers.
Definition dcnnelements.hpp:668
typename CSPO::channel_tag channel_out_tag
Output channel tag.
Definition dcnnelements.hpp:675
static constexpr auto cor
Output channel range.
Definition dcnnelements.hpp:685
static constexpr auto cir
Input channel range.
Definition dcnnelements.hpp:684
typename CSPI::channel_tag channel_in_tag
Input channel tag.
Definition dcnnelements.hpp:674
Definition dcnnelements.hpp:1510
static constexpr auto cr
Input image channel range.
Definition dcnnelements.hpp:1547
dcnnsol::feature_data< CSPO, PP > output_data
Output activations.
Definition dcnnelements.hpp:1526
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:1563
typename SPI::width_tag width_in_tag
Input image width.
Definition dcnnelements.hpp:1534
typename SPI::height_tag height_in_tag
Input image height.
Definition dcnnelements.hpp:1533
static constexpr auto hir
Input image height range.
Definition dcnnelements.hpp:1545
typename SPI::channel_tag channel_tag
Input image channel.
Definition dcnnelements.hpp:1535
static constexpr auto wir
Input image width range.
Definition dcnnelements.hpp:1546
static constexpr std::size_t fanin
Number of inputs for each output element.
Definition dcnnelements.hpp:1551
dcnnsol::image_data< SPI, PP > input_data
Input activations.
Definition dcnnelements.hpp:1522
Tag: Height dimension of an image.
Definition dcnnelements.hpp:102
Internal layer activation data policy.
Definition dcnnelements.hpp:339
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:371
static constexpr auto cr
Channel index range, statically sized.
Definition dcnnelements.hpp:364
static constexpr auto hr
Image height range, statically sized.
Definition dcnnelements.hpp:356
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:379
static constexpr auto wr
Image width range, statically sized.
Definition dcnnelements.hpp:360
Combined image and channel size policy.
Definition dcnnelements.hpp:322
CSP channel_policy
Channel size policy.
Definition dcnnelements.hpp:330
ISP image_policy
Image size policy.
Definition dcnnelements.hpp:326
Definition dcnnelements.hpp:1440
Image size policy.
Definition dcnnelements.hpp:128
height_stag< H > height_tag
Tag: Height dimension of an image, statically sized.
Definition dcnnelements.hpp:132
width_stag< W > width_tag
Tag: Width dimension of an image, statically sized.
Definition dcnnelements.hpp:136
static constexpr tagged::range_class< height_tag > hr
Height range of an image, statically sized.
Definition dcnnelements.hpp:141
static constexpr tagged::range_class< width_tag > wr
Width range of an image, statically sized.
Definition dcnnelements.hpp:145
Tag: Kernel height dimension.
Definition dcnnelements.hpp:170
Tag: Kernel width dimension.
Definition dcnnelements.hpp:177
Loss data policy.
Definition dcnnelements.hpp:415
tagged::tensor_class< float, batch_tag > loss_t
1-dimensional tensor type carrying loss values for images in a minibatch
Definition dcnnelements.hpp:419
Definition dcnnelements.hpp:1774
The loss layer.
Definition dcnnelements.hpp:1821
static void forward(const input_data &ind, const gold_data &gd, output_data &outd)
The forward-propagation function of the loss layer.
Definition dcnnelements.hpp:1838
Definition dcnnelements.hpp:1408
Definition dcnnelements.hpp:1412
Definition dcnnelements.hpp:1424
Definition dcnnelements.hpp:1409
Definition dcnnelements.hpp:1415
Functor to multiply by a constant and add a fixed value.
Definition dcnnelements.hpp:552
Functor to subtract from a fixed value.
Definition dcnnelements.hpp:526
Utility base class for the convolutional layer.
Definition dcnnelements.hpp:935
typename KSP::kernel_width_tag kernel_width_tag
Kernel width.
Definition dcnnelements.hpp:965
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:1030
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:1024
dcnnsol::image_data< SPI, PP > input_data
Input activations.
Definition dcnnelements.hpp:946
static constexpr auto cor
Output image channel range.
Definition dcnnelements.hpp:989
static constexpr auto hir
Input image height range.
Definition dcnnelements.hpp:982
static constexpr auto wir
Input image width range.
Definition dcnnelements.hpp:983
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:1037
typename SPI::height_tag height_in_tag
Input image height.
Definition dcnnelements.hpp:960
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:1035
typename SPI::width_tag width_in_tag
Input image width.
Definition dcnnelements.hpp:961
static constexpr auto cir
Input image channel range.
Definition dcnnelements.hpp:984
typename SPO::height_tag height_out_tag
Output image height.
Definition dcnnelements.hpp:967
static constexpr auto khr
Kernel height range.
Definition dcnnelements.hpp:985
dcnnsol::image_data< SPO, PP > output_data
Output activations.
Definition dcnnelements.hpp:954
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:1051
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:1034
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:1027
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:1031
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:1036
typename SPO::width_tag width_out_tag
Output image width.
Definition dcnnelements.hpp:968
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:1025
static constexpr auto kwr
Kernel width range.
Definition dcnnelements.hpp:986
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:1032
static constexpr std::size_t fanin
Number of inputs for each output element.
Definition dcnnelements.hpp:993
typename SPI::channel_tag channel_in_tag
Input image channel.
Definition dcnnelements.hpp:962
typename KSP::kernel_height_tag kernel_height_tag
Kernel height.
Definition dcnnelements.hpp:964
typename SPO::channel_tag channel_out_tag
Output image channel.
Definition dcnnelements.hpp:969
dcnnsol::conv_weights< KSP, CSPI, CSPO, PP > weights
Model weights.
Definition dcnnelements.hpp:950
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:1026
static constexpr auto hor
Output image height range.
Definition dcnnelements.hpp:987
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:1029
static constexpr auto wor
Output image width range.
Definition dcnnelements.hpp:988
Utility base class for the convolutional layer.
Definition dcnnelements.hpp:1099
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:1206
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:1225
typename SPI::height_tag height_in_tag
Input image height.
Definition dcnnelements.hpp:1124
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:1199
dcnnsol::image_data< SPI, PP > input_data
Input activations.
Definition dcnnelements.hpp:1110
static constexpr auto wor
Output image width range.
Definition dcnnelements.hpp:1149
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:1201
typename SPI::width_tag width_in_tag
Input image width.
Definition dcnnelements.hpp:1125
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:1209
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:1210
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:1203
typename KSP::kernel_height_tag kernel_height_tag
Kernel height.
Definition dcnnelements.hpp:1128
typename SPO::channel_tag channel_out_tag
Output image channel.
Definition dcnnelements.hpp:1133
static constexpr auto hor
Output image height range.
Definition dcnnelements.hpp:1148
dcnnsol::image_data< SPO, PP > output_data
Output activations.
Definition dcnnelements.hpp:1118
static constexpr auto wir
Input image width range.
Definition dcnnelements.hpp:1144
static constexpr auto hir
Input image height range.
Definition dcnnelements.hpp:1143
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:1208
typename SPO::width_tag width_out_tag
Output image width.
Definition dcnnelements.hpp:1132
static constexpr auto kwr
Kernel width range.
Definition dcnnelements.hpp:1147
static constexpr auto khr
Kernel height range.
Definition dcnnelements.hpp:1146
static constexpr auto cor
Output image channel range.
Definition dcnnelements.hpp:1150
typename SPI::channel_tag channel_in_tag
Input image channel.
Definition dcnnelements.hpp:1126
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:1211
typename KSP::kernel_width_tag kernel_width_tag
Kernel width.
Definition dcnnelements.hpp:1129
static constexpr auto cir
Input image channel range.
Definition dcnnelements.hpp:1145
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:1205
typename SPO::height_tag height_out_tag
Output image height.
Definition dcnnelements.hpp:1131
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:1198
dcnnsol::conv_weights< KSP, CSPI, CSPO, PP > weights
Model weights.
Definition dcnnelements.hpp:1114
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:1204
static constexpr std::size_t fanin
Number of inputs for each output element.
Definition dcnnelements.hpp:1154
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:1200
Tag: Width dimension of an image.
Definition dcnnelements.hpp:106
A wrapped list of tags.
Definition tagged.hpp:228